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