Milestone 2 #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Auto Release | |
| on: | |
| pull_request: | |
| types: [closed] | |
| branches: | |
| - main | |
| jobs: | |
| release: | |
| # Only run if PR was merged AND came from dev branch | |
| if: github.event.pull_request.merged == true && github.event.pull_request.head.ref == 'dev' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Get version | |
| id: version | |
| run: | | |
| git fetch --tags | |
| LATEST=$(git tag -l "v[0-9]*.[0-9]*.[0-9]*" | sort -V | tail -n 1) | |
| if [ -z "$LATEST" ]; then | |
| NEW_VERSION="v0.2.0" | |
| else | |
| VERSION=${LATEST#v} | |
| IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION" | |
| MINOR=$((MINOR + 1)) | |
| NEW_VERSION="v${MAJOR}.${MINOR}.0" | |
| fi | |
| echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
| - name: Check tag exists | |
| id: check | |
| run: | | |
| if git rev-parse "${{ steps.version.outputs.version }}" >/dev/null 2>&1; then | |
| echo "skip=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "skip=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Create changelog | |
| if: steps.check.outputs.skip == 'false' | |
| run: | | |
| echo "Release ${{ steps.version.outputs.version }}" > notes.md | |
| echo "" >> notes.md | |
| echo "Changes:" >> notes.md | |
| echo "- Merged from dev branch" >> notes.md | |
| - name: Push tag | |
| if: steps.check.outputs.skip == 'false' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag -a "${{ steps.version.outputs.version }}" -m "Release ${{ steps.version.outputs.version }}" | |
| git push origin "${{ steps.version.outputs.version }}" | |
| - name: Create release | |
| if: steps.check.outputs.skip == 'false' | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.version.outputs.version }} | |
| name: Release ${{ steps.version.outputs.version }} | |
| body_path: notes.md | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |