Skip to content

Commit

Permalink
ci(pipeline): 👷 Update CI system
Browse files Browse the repository at this point in the history
Now using semantic release to automatically publish the package and update all necessary files
  • Loading branch information
AlexTorresDev committed Jul 24, 2023
1 parent ed97354 commit 2c06995
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 83 deletions.
86 changes: 86 additions & 0 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Build & Release

on:
push:
branches:
- main
pull_request:
branches:
- main
types: [opened, synchronize]

workflow_dispatch:

permissions:
contents: write
id-token: write

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
name: 📦 Build
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 7
run_install: false
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: "lts/*"
cache: pnpm
- run: pnpm install --no-frozen-lockfile
- name: Test
run: pnpm test
- name: Build
run: pnpm build
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: build-artifact
path: dist

release:
name: 🚀 Release
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: build
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
persist-credentials: false
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: build-artifact
path: dist
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: "lts/*"
- name: Set correct path
run: sed -i "s/\/dist//g" package.json
- name: Copy files
run: |
cp README.md dist
cp LICENSE dist
cp package.json dist
cp .npmignore dist
- name: Semantic Release
uses: cycjimmy/semantic-release-action@v3
with:
extra_plugins: |
@semantic-release/changelog
@semantic-release/git
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
82 changes: 0 additions & 82 deletions .github/workflows/npm-publish.yml

This file was deleted.

30 changes: 30 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"branches": "main",
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@semantic-release/npm",
{
"pkgRoot": "dist"
}
],
[
"@semantic-release/changelog",
{
"changelogFile": "CHANGELOG.md",
"changelogTitle": "# Changelog"
}
],
[
"@semantic-release/git",
{
"assets": [
"CHANGELOG.md",
"package.json"
]
}
],
"@semantic-release/github"
]
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"start": "electron example/main.js",
"dev": "npm run build && npm run start",
"build": "npm run clean && npm run build:package && npm run build:babel",
"test": ""
"postversion": "cp package.json .. && chmod u+x ../revert.sh && ../revert.sh",
"test": "echo \"Test script here\""
},
"author": "AlexTorresDev <alextorressk@gmail.com>",
"license": "MIT",
Expand Down
3 changes: 3 additions & 0 deletions revert.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Reverts ./dist path changes created in pipeline by package publish to NPM and deletes postversion script in package.json of NPM package
sed -i -e '/"types":/,/},/{s|"\./|"./dist/|g}' -e '/"exports":/,/},/{/\"\.\/main\":/! s|"\./|"./dist/|g; s|"\./main/index.js|"./dist/main/index.js|g}' ../package.json
sed -i '/"postversion":/d' package.json

0 comments on commit 2c06995

Please sign in to comment.