|
| 1 | +# .github/workflows/release.yml |
| 2 | +name: Create Release |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - master |
| 8 | + |
| 9 | +jobs: |
| 10 | + release: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + permissions: |
| 13 | + contents: write |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout code |
| 17 | + uses: actions/checkout@v5 |
| 18 | + with: |
| 19 | + fetch-depth: 0 |
| 20 | + |
| 21 | + - name: Setup Node.js |
| 22 | + uses: actions/setup-node@v6 |
| 23 | + with: |
| 24 | + node-version: '20' |
| 25 | + |
| 26 | + - name: Install dependencies |
| 27 | + run: npm install |
| 28 | + |
| 29 | + - name: Build |
| 30 | + run: npm run build |
| 31 | + |
| 32 | + - name: Get version from package.json |
| 33 | + id: package_version |
| 34 | + run: | |
| 35 | + VERSION=$(node -p "require('./package.json').version") |
| 36 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 37 | + echo "tag=v$VERSION" >> $GITHUB_OUTPUT |
| 38 | +
|
| 39 | + - name: Check if tag exists |
| 40 | + id: check_tag |
| 41 | + run: | |
| 42 | + if git rev-parse "v${{ steps.package_version.outputs.version }}" >/dev/null 2>&1; then |
| 43 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 44 | + else |
| 45 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 46 | + fi |
| 47 | +
|
| 48 | + - name: Configure Git |
| 49 | + if: steps.check_tag.outputs.exists == 'false' |
| 50 | + run: | |
| 51 | + git config user.name "github-actions[bot]" |
| 52 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 53 | +
|
| 54 | + - name: Delete and recreate release branch |
| 55 | + if: steps.check_tag.outputs.exists == 'false' |
| 56 | + run: | |
| 57 | + # Check if release branch exists remotely |
| 58 | + if git ls-remote --heads origin release | grep -q release; then |
| 59 | + echo "Deleting existing release branch..." |
| 60 | + git push origin --delete release |
| 61 | + fi |
| 62 | + |
| 63 | + # Create fresh release branch from master |
| 64 | + git checkout -b release |
| 65 | + |
| 66 | + # Add built files |
| 67 | + git add -f build/ |
| 68 | + |
| 69 | + # Commit built files |
| 70 | + git commit -m "build: release v${{ steps.package_version.outputs.version }}" |
| 71 | + |
| 72 | + # Force push release branch |
| 73 | + git push -f origin release |
| 74 | +
|
| 75 | + - name: Create Git tag on release branch |
| 76 | + if: steps.check_tag.outputs.exists == 'false' |
| 77 | + run: | |
| 78 | + git tag -a "v${{ steps.package_version.outputs.version }}" -m "Release v${{ steps.package_version.outputs.version }}" |
| 79 | + git push origin "v${{ steps.package_version.outputs.version }}" |
| 80 | +
|
| 81 | + - name: Create Release |
| 82 | + if: steps.check_tag.outputs.exists == 'false' |
| 83 | + uses: softprops/action-gh-release@v1 |
| 84 | + with: |
| 85 | + tag_name: v${{ steps.package_version.outputs.version }} |
| 86 | + name: Release v${{ steps.package_version.outputs.version }} |
| 87 | + draft: false |
| 88 | + prerelease: false |
| 89 | + generate_release_notes: true |
| 90 | + target_commitish: release |
| 91 | + env: |
| 92 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 93 | + |
| 94 | + - name: Skip - Release already exists |
| 95 | + if: steps.check_tag.outputs.exists == 'true' |
| 96 | + run: | |
| 97 | + echo "Release v${{ steps.package_version.outputs.version }} already exists. Skipping release creation." |
| 98 | + echo "To create a new release, bump the version in package.json" |
0 commit comments