|
| 1 | +name: Release from Issue |
| 2 | + |
| 3 | +on: |
| 4 | + issues: |
| 5 | + types: [opened] |
| 6 | + |
| 7 | +jobs: |
| 8 | + validate: |
| 9 | + if: startsWith(github.event.issue.title, 'release ') || startsWith(github.event.issue.title, 'Release ') |
| 10 | + runs-on: ubuntu-latest |
| 11 | + outputs: |
| 12 | + version: ${{ steps.extract.outputs.VERSION }} |
| 13 | + should_proceed: ${{ steps.validate.outputs.should_proceed }} |
| 14 | + steps: |
| 15 | + - name: Extract version |
| 16 | + id: extract |
| 17 | + run: | |
| 18 | + TITLE="${{ github.event.issue.title }}" |
| 19 | + VERSION=$(echo "$TITLE" | grep -oP '(?<=[Rr]elease )v?\K\d+\.\d+\.\d+') |
| 20 | + echo "VERSION=$VERSION" >> $GITHUB_OUTPUT |
| 21 | + |
| 22 | + - name: Validate version |
| 23 | + id: validate |
| 24 | + run: | |
| 25 | + VERSION="${{ steps.extract.outputs.VERSION }}" |
| 26 | + |
| 27 | + if git ls-remote --tags origin | grep -q "refs/tags/v$VERSION"; then |
| 28 | + echo "Tag v$VERSION already exists!" |
| 29 | + echo "should_proceed=false" >> $GITHUB_OUTPUT |
| 30 | + exit 0 |
| 31 | + fi |
| 32 | + |
| 33 | + LATEST=$(git ls-remote --tags origin | grep -oP 'refs/tags/v\K\d+\.\d+\.\d+$' | sort -V | tail -1) |
| 34 | + if [ -n "$LATEST" ] && [ "$(printf '%s\n%s' "$LATEST" "$VERSION" | sort -V | tail -1)" != "$VERSION" ]; then |
| 35 | + echo "Version v$VERSION is not newer than latest v$LATEST!" |
| 36 | + echo "should_proceed=false" >> $GITHUB_OUTPUT |
| 37 | + exit 0 |
| 38 | + fi |
| 39 | + |
| 40 | + echo "should_proceed=true" >> $GITHUB_OUTPUT |
| 41 | + continue-on-error: true |
| 42 | + |
| 43 | + release: |
| 44 | + needs: validate |
| 45 | + if: needs.validate.outputs.should_proceed == 'true' |
| 46 | + runs-on: ubuntu-latest |
| 47 | + permissions: |
| 48 | + contents: write |
| 49 | + issues: write |
| 50 | + |
| 51 | + steps: |
| 52 | + - uses: actions/checkout@v4 |
| 53 | + |
| 54 | + - name: Update version in README |
| 55 | + run: | |
| 56 | + VERSION="${{ needs.validate.outputs.version }}" |
| 57 | + sed -i "/Latest version:/s/\[[0-9.]\+\]/[${VERSION}]/" README.md |
| 58 | + |
| 59 | + - name: Commit and push |
| 60 | + run: | |
| 61 | + git config user.name "github-actions[bot]" |
| 62 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 63 | + git add . |
| 64 | + git commit -m "Release v${{ needs.validate.outputs.version }}" |
| 65 | + git push |
| 66 | + |
| 67 | + - name: Create tag |
| 68 | + run: | |
| 69 | + git tag v${{ needs.validate.outputs.version }} |
| 70 | + git push origin v${{ needs.validate.outputs.version }} |
| 71 | + |
| 72 | + - name: Success comment |
| 73 | + uses: actions/github-script@v7 |
| 74 | + with: |
| 75 | + script: | |
| 76 | + const version = '${{ needs.validate.outputs.version }}'; |
| 77 | + const releaseUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/releases/tag/v${version}`; |
| 78 | + |
| 79 | + await github.rest.issues.createComment({ |
| 80 | + owner: context.repo.owner, |
| 81 | + repo: context.repo.repo, |
| 82 | + issue_number: context.issue.number, |
| 83 | + body: `✅ **Release v${version} completed!**\n\n- 📝 Version bumped in README\n- 🏷️ Tag \`v${version}\` created\n- 🚀 Release: ${releaseUrl}` |
| 84 | + }); |
| 85 | + |
| 86 | + await github.rest.issues.update({ |
| 87 | + owner: context.repo.owner, |
| 88 | + repo: context.repo.repo, |
| 89 | + issue_number: context.issue.number, |
| 90 | + state: 'closed' |
| 91 | + }); |
0 commit comments