|
| 1 | +name: Versioned Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write # we need this to be able to push tags |
| 10 | + |
| 11 | +jobs: |
| 12 | + release_tag: |
| 13 | + name: Release version |
| 14 | + runs-on: ubuntu-24.04 |
| 15 | + steps: |
| 16 | + - name: Checkout code |
| 17 | + uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + ssh-key: ${{ secrets.PUSH_KEY }} |
| 20 | + fetch-tags: true |
| 21 | + fetch-depth: 0 |
| 22 | + |
| 23 | + - name: Read and validate VERSION |
| 24 | + id: version |
| 25 | + run: | |
| 26 | + VERSION=$(cat VERSION) |
| 27 | + if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-dev)?$ ]]; then |
| 28 | + echo "Invalid version format in VERSION file: $VERSION" |
| 29 | + exit 1 |
| 30 | + fi |
| 31 | + echo "New version: $VERSION" |
| 32 | + echo "version=$VERSION" >> $GITHUB_ENV |
| 33 | +
|
| 34 | + - name: Skip release if version is a dev version |
| 35 | + if: contains(env.version, '-dev') |
| 36 | + run: | |
| 37 | + echo "Skipping development version release: ${{ env.version }}" |
| 38 | + echo "SKIP=true" >> $GITHUB_ENV |
| 39 | + exit 0 |
| 40 | + |
| 41 | + - name: Check if VERSION is already tagged |
| 42 | + id: check_tag |
| 43 | + run: | |
| 44 | + if git rev-parse "refs/tags/${{ env.version }}" >/dev/null 2>&1; then |
| 45 | + echo "Tag ${{ env.version }} already exists. Skipping release." |
| 46 | + echo "SKIP=true" >> $GITHUB_ENV |
| 47 | + exit 0 |
| 48 | + fi |
| 49 | + echo "Tag ${{ env.version }} doesn't exists. Proceeding with release." |
| 50 | +
|
| 51 | + - name: Create Git tag |
| 52 | + if: ${{ env.SKIP != 'true' }} |
| 53 | + run: | |
| 54 | + AUTHOR_NAME=$(git log -1 --pretty=format:'%an') |
| 55 | + AUTHOR_EMAIL=$(git log -1 --pretty=format:'%ae') |
| 56 | + echo "Tagging as $AUTHOR_NAME <$AUTHOR_EMAIL>" |
| 57 | +
|
| 58 | + echo "AUTHOR_NAME=$AUTHOR_NAME" >> $GITHUB_ENV |
| 59 | + echo "AUTHOR_EMAIL=$AUTHOR_EMAIL" >> $GITHUB_ENV |
| 60 | +
|
| 61 | + git config user.name "$AUTHOR_NAME" |
| 62 | + git config user.email "$AUTHOR_EMAIL" |
| 63 | +
|
| 64 | + git tag -a "${{ env.version }}" -m "Release ${{ env.version }}" |
| 65 | + git push origin "${{ env.version }}" |
| 66 | +
|
| 67 | + - name: Build Changelog |
| 68 | + id: github_release |
| 69 | + uses: mikepenz/release-changelog-builder-action@v5 |
| 70 | + with: |
| 71 | + mode: "PR" |
| 72 | + configurationJson: | |
| 73 | + { |
| 74 | + "template": "#{{CHANGELOG}}", |
| 75 | + "pr_template": "- #{{TITLE}}: ##{{NUMBER}}", |
| 76 | + "categories": [ |
| 77 | + { |
| 78 | + "title": "## Feature", |
| 79 | + "labels": ["feat", "feature"] |
| 80 | + }, |
| 81 | + { |
| 82 | + "title": "## Fix", |
| 83 | + "labels": ["fix", "bug"] |
| 84 | + }, |
| 85 | + { |
| 86 | + "title": "## Other", |
| 87 | + "labels": [] |
| 88 | + } |
| 89 | + ], |
| 90 | + "label_extractor": [ |
| 91 | + { |
| 92 | + "pattern": "^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test){1}(\\([\\w\\-\\.]+\\))?(!)?: ([\\w ])+([\\s\\S]*)", |
| 93 | + "on_property": "title", |
| 94 | + "target": "$1" |
| 95 | + } |
| 96 | + ] |
| 97 | + } |
| 98 | + env: |
| 99 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 100 | + |
| 101 | + - name: Create GitHub release |
| 102 | + if: ${{ env.SKIP != 'true' }} |
| 103 | + uses: softprops/action-gh-release@v2 |
| 104 | + with: |
| 105 | + tag_name: ${{ env.version }} |
| 106 | + name: Release ${{ env.version }} |
| 107 | + body: "Automated release for version ${{ env.version }}" |
| 108 | + draft: false |
| 109 | + prerelease: false |
| 110 | + env: |
| 111 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 112 | + |
| 113 | + - name: Push dev VERSION |
| 114 | + if: ${{ env.SKIP != 'true' }} |
| 115 | + run: | |
| 116 | + echo "${{ env.version }}-dev" > VERSION |
| 117 | + git config user.name "${{ env.AUTHOR_NAME }}" |
| 118 | + git config user.email "${{ env.AUTHOR_EMAIL }}" |
| 119 | + git add VERSION |
| 120 | + git commit -m "Update VERSION to ${{ env.version }}-dev" |
| 121 | + git push origin main |
0 commit comments