diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml new file mode 100644 index 0000000..a9f40ed --- /dev/null +++ b/.github/workflows/build-release.yml @@ -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 }} \ No newline at end of file diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml deleted file mode 100644 index 9b73c38..0000000 --- a/.github/workflows/npm-publish.yml +++ /dev/null @@ -1,82 +0,0 @@ -name: Build & Publish - -on: - release: - types: [published] - pull_request: - branches: - - main - types: [opened, synchronize] - - workflow_dispatch: - -jobs: - avoid_redundant: - name: ❌ Avoid redundant builds - runs-on: ubuntu-22.04 - steps: - - uses: styfle/cancel-workflow-action@0.9.1 - with: - access_token: ${{ github.token }} - - build: - name: 📦 Build - runs-on: ubuntu-22.04 - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - name: Install Node.js - uses: actions/setup-node@v3 - with: - node-version: "18.x" - - uses: pnpm/action-setup@v2 - with: - version: 7 - run_install: false - - name: Get pnpm store directory - id: pnpm-cache - shell: bash - run: | - echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT - - name: Setup pnpm cache - uses: actions/cache@v3 - with: - path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} - key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} - restore-keys: | - ${{ runner.os }}-pnpm-store- - - name: Install dependencies - run: pnpm install --no-frozen-lockfile - - name: Build package - run: pnpm build - - name: Copy files to dist - run: | - cp LICENSE dist/ - cp README.md dist/ - cp package.json dist/ - cp .npmignore dist/ - - name: Upload artifact - uses: actions/upload-artifact@v3 - with: - name: cet-package - path: dist - - publish: - name: 🚀 Publish - if: github.event_name == 'release' - needs: build - runs-on: ubuntu-22.04 - steps: - - name: Get artifact - uses: actions/download-artifact@v3 - with: - name: cet-package - - name: Install Node.js - uses: actions/setup-node@v3 - with: - node-version: "18.x" - registry-url: https://registry.npmjs.org/ - - name: Publish package to NPM - run: npm publish --access public - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.releaserc.json b/.releaserc.json new file mode 100644 index 0000000..6f36344 --- /dev/null +++ b/.releaserc.json @@ -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" + ] +} \ No newline at end of file diff --git a/package.json b/package.json index a94531e..c07a035 100644 --- a/package.json +++ b/package.json @@ -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 ", "license": "MIT", diff --git a/revert.sh b/revert.sh new file mode 100644 index 0000000..caf1b3d --- /dev/null +++ b/revert.sh @@ -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 \ No newline at end of file