From 9d8ed3d1f5bc793f5bf3f3bb15911057b5ec18cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20G=C3=B6tz?= Date: Thu, 16 Apr 2026 16:19:46 +0200 Subject: [PATCH] chore: try to optimize ci --- .github/workflows/release.yml | 130 ++++++++++++++++++++++++++-------- 1 file changed, 101 insertions(+), 29 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ffa9ed19..8022bf1d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,65 +1,99 @@ -# Template used https://superface.ai/blog/npm-publish-gh-actions-changelog name: Release on: workflow_dispatch: inputs: release_version: - description: 'Version to release (follow SemVer e.g. 1.0.0)' + description: 'Version to release (SemVer, e.g. 1.0.0)' required: true +concurrency: + group: release + cancel-in-progress: false + permissions: contents: write pull-requests: write env: - NODE_VERSION: 22.x + NODE_VERSION: 24.x + jobs: + validate: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + with: + fetch-depth: 0 + + - name: Validate semver format + run: | + if ! echo "${{ github.event.inputs.release_version }}" | grep -qE '^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$'; then + echo "::error::Invalid semver format: '${{ github.event.inputs.release_version }}'. Expected format: X.Y.Z (e.g. 1.0.0, 2.1.0-beta.1)" + exit 1 + fi + + - name: Check tag does not exist + run: | + if git rev-parse "v${{ github.event.inputs.release_version }}" >/dev/null 2>&1; then + echo "::error::Tag v${{ github.event.inputs.release_version }} already exists" + exit 1 + fi + + github-release: + needs: [validate] runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 with: fetch-depth: 0 + + - uses: actions/setup-node@v6 + with: + node-version: ${{ env.NODE_VERSION }} + cache: 'npm' + + - run: npm ci + - name: Git configuration run: | git config --global user.email "github-actions@github.com" git config --global user.name "Github Actions on behalf of @${{ github.triggering_actor }}" - - name: Bump Release Version - run: | - npm ci - npx nx release --skip-publish ${{ github.event.inputs.release_version }} - - name: Push Changes - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Bump release version + run: npx nx release --skip-publish ${{ github.event.inputs.release_version }} + + - name: Push release branch and tags run: | git checkout -b release/${{ github.event.inputs.release_version }} git push --tags origin release/${{ github.event.inputs.release_version }} - - name: Merge Release Data via Pull Request + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Create pull request uses: actions/github-script@v9 with: script: | const { repo, owner } = context.repo; - const result = await github.rest.pulls.create({ - title: 'Release ${{ github.event.inputs.release_version }}', - owner, - repo, - head: 'release/${{ github.event.inputs.release_version }}', + const version = '${{ github.event.inputs.release_version }}'; + + const pr = await github.rest.pulls.create({ + owner, repo, + title: `Release ${version}`, + head: `release/${version}`, base: 'main', - body: [ - 'Adds release data', - 'This PR is auto-generated by', - '[actions/github-script](https://github.com/actions/github-script).' - ].join('\n') + body: `Automated release PR for v${version}\n\nCreated by [GitHub Actions](${context.serverUrl}/${owner}/${repo}/actions/runs/${context.runId}).` }); + await github.rest.issues.addLabels({ - owner, - repo, - issue_number: result.data.number, + owner, repo, + issue_number: pr.data.number, labels: ['release', 'automated pr'] }); - - name: Release + + - name: Create GitHub Release uses: softprops/action-gh-release@v2 with: tag_name: v${{ github.event.inputs.release_version }} @@ -72,19 +106,22 @@ jobs: - uses: actions/checkout@v6 with: ref: v${{ github.event.inputs.release_version }} + - uses: actions/setup-node@v6 with: node-version: ${{ env.NODE_VERSION }} cache: 'npm' + - run: npm ci - run: npm run build + - uses: actions/upload-artifact@v7 with: name: release-dist path: packages/*/dist/ retention-days: 1 - publish-package: + publish-github-packages: needs: [build] runs-on: ubuntu-latest permissions: @@ -95,27 +132,55 @@ jobs: - uses: actions/checkout@v6 with: ref: v${{ github.event.inputs.release_version }} + - uses: actions/setup-node@v6 with: node-version: ${{ env.NODE_VERSION }} scope: '@lion5' registry-url: 'https://npm.pkg.github.com' + cache: 'npm' + - run: npm ci + - uses: actions/download-artifact@v8 with: name: release-dist path: packages/ - - name: Publish To Github Packages + + - name: Publish to GitHub Packages run: npx nx release publish --registry https://npm.pkg.github.com env: NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + publish-npm: + needs: [build] + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + steps: + - uses: actions/checkout@v6 + with: + ref: v${{ github.event.inputs.release_version }} + - uses: actions/setup-node@v6 with: node-version: ${{ env.NODE_VERSION }} scope: '@lion5' registry-url: 'https://registry.npmjs.org' - - name: Publish To NPM Packages - run: npx nx release publish --registry https://registry.npmjs.org + cache: 'npm' + + - run: npm ci + + - uses: actions/download-artifact@v8 + with: + name: release-dist + path: packages/ + + - name: Publish to NPM + run: npx nx release publish --registry https://registry.npmjs.org --access public + env: + NPM_CONFIG_PROVENANCE: true publish-documentation: needs: [build] @@ -131,20 +196,27 @@ jobs: - uses: actions/checkout@v6 with: ref: v${{ github.event.inputs.release_version }} + - uses: actions/setup-node@v6 with: node-version: ${{ env.NODE_VERSION }} cache: 'npm' + - run: npm ci + - uses: actions/download-artifact@v8 with: name: release-dist path: packages/ + - run: npm run docs:build + - uses: actions/configure-pages@v6 + - uses: actions/upload-pages-artifact@v4 with: path: './packages/storybook-host/storybook-static/' + - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v5