|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +jobs: |
| 9 | + release: |
| 10 | + name: Release |
| 11 | + runs-on: ubuntu-latest |
| 12 | + permissions: |
| 13 | + contents: write |
| 14 | + pull-requests: write |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + |
| 20 | + - uses: pnpm/action-setup@v4 |
| 21 | + with: |
| 22 | + version: 10.20.0 |
| 23 | + |
| 24 | + - uses: actions/setup-node@v4 |
| 25 | + with: |
| 26 | + node-version: '20' |
| 27 | + cache: 'pnpm' |
| 28 | + |
| 29 | + - name: Install dependencies |
| 30 | + run: pnpm install --frozen-lockfile |
| 31 | + |
| 32 | + - name: Build packages |
| 33 | + run: pnpm build |
| 34 | + |
| 35 | + - name: Commit dist folder (if changed) |
| 36 | + run: | |
| 37 | + git config user.name "github-actions[bot]" |
| 38 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 39 | + git add packages/scripts/dist/ |
| 40 | + if git diff --staged --quiet; then |
| 41 | + echo "No changes to dist folder" |
| 42 | + else |
| 43 | + git commit -m "chore: build scripts package" |
| 44 | + git push |
| 45 | + fi |
| 46 | +
|
| 47 | + - name: Create Release Pull Request or Publish |
| 48 | + id: changesets |
| 49 | + uses: changesets/action@v1 |
| 50 | + with: |
| 51 | + publish: pnpm changeset publish |
| 52 | + version: pnpm changeset version |
| 53 | + commit: 'chore: version packages' |
| 54 | + title: 'chore: version packages' |
| 55 | + env: |
| 56 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 57 | + |
| 58 | + - name: Get Scripts Package Version |
| 59 | + if: steps.changesets.outputs.published == 'true' |
| 60 | + id: version |
| 61 | + run: | |
| 62 | + VERSION=$(grep -o '"version": "[^"]*"' packages/scripts/package.json | cut -d'"' -f4) |
| 63 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 64 | + echo "tag=v$VERSION" >> $GITHUB_OUTPUT |
| 65 | + echo "Released version: $VERSION" |
| 66 | +
|
| 67 | + - name: Create Git Tag |
| 68 | + if: steps.changesets.outputs.published == 'true' |
| 69 | + run: | |
| 70 | + git config user.name "github-actions[bot]" |
| 71 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 72 | + git tag -a "${{ steps.version.outputs.tag }}" -m "Release ${{ steps.version.outputs.tag }}" |
| 73 | + git push origin "${{ steps.version.outputs.tag }}" |
| 74 | +
|
| 75 | + - name: Create GitHub Release for Scripts |
| 76 | + if: steps.changesets.outputs.published == 'true' |
| 77 | + uses: softprops/action-gh-release@v1 |
| 78 | + with: |
| 79 | + tag_name: ${{ steps.version.outputs.tag }} |
| 80 | + name: Scripts Release ${{ steps.version.outputs.tag }} |
| 81 | + body: | |
| 82 | + Automated release of scripts package. |
| 83 | +
|
| 84 | + **Version:** ${{ steps.version.outputs.version }} |
| 85 | +
|
| 86 | + **jsdelivr URLs:** |
| 87 | + - Latest from this version: `https://cdn.jsdelivr.net/gh/${{ github.repository }}@${{ steps.version.outputs.tag }}/packages/scripts/dist/index.js` |
| 88 | + - Latest from major version: `https://cdn.jsdelivr.net/gh/${{ github.repository }}@${{ steps.version.outputs.version }}.*/packages/scripts/dist/index.js` |
| 89 | + - Specific commit: `https://cdn.jsdelivr.net/gh/${{ github.repository }}@${{ github.sha }}/packages/scripts/dist/index.js` |
| 90 | +
|
| 91 | + **Usage in HTML:** |
| 92 | + ```html |
| 93 | + <script defer src="https://cdn.jsdelivr.net/gh/${{ github.repository }}@${{ steps.version.outputs.tag }}/packages/scripts/dist/index.js"></script> |
| 94 | + ``` |
| 95 | + draft: false |
| 96 | + prerelease: false |
| 97 | + env: |
| 98 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 99 | + |
| 100 | + - name: Upload Scripts Artifacts |
| 101 | + if: steps.changesets.outputs.published == 'true' |
| 102 | + uses: actions/upload-artifact@v4 |
| 103 | + with: |
| 104 | + name: scripts-dist |
| 105 | + path: packages/scripts/dist/** |
| 106 | + retention-days: 90 |
0 commit comments