release-command #132
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: Command Release | |
| on: | |
| repository_dispatch: | |
| types: [release-command] | |
| permissions: | |
| pull-requests: write | |
| checks: write | |
| id-token: write | |
| contents: write | |
| jobs: | |
| meta: | |
| needs: [] | |
| runs-on: windows-latest | |
| outputs: | |
| project: ${{ steps.meta.outputs.project }} | |
| package: ${{ steps.meta.outputs.package }} | |
| directory: ${{ steps.meta.outputs.directory }} | |
| releaseNamePrefix: ${{ steps.meta.outputs.releaseNamePrefix }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.client_payload.pull_request.head.ref }} | |
| - id: meta | |
| shell: pwsh | |
| run: | | |
| $directory = "${{ github.event.client_payload.slash_command.args.unnamed.arg1 }}" | |
| $package = "${{ github.event.client_payload.slash_command.args.unnamed.arg2 }}" | |
| Write-Output "package=$package" | |
| Write-Output "package=$package" >> $env:GITHUB_OUTPUT | |
| Write-Output "directory=$directory/src" | |
| Write-Output "directory=$directory/src" >> $env:GITHUB_OUTPUT | |
| $prefix = "" | |
| if($directory -eq "queue") { | |
| $prefix = "fiskaltrust.Middleware.Queue" | |
| Write-Output "releaseNamePrefix=Queue" | |
| Write-Output "releaseNamePrefix=Queue" >> $env:GITHUB_OUTPUT | |
| } elseif($directory -match "scu-([a-z]{2})") { | |
| $prefix = "fiskaltrust.Middleware.SCU.$($matches[1].ToUpper())" | |
| Write-Output "releaseNamePrefix=SCU.$($matches[1].ToUpper())" | |
| Write-Output "releaseNamePrefix=SCU.$($matches[1].ToUpper())" >> $env:GITHUB_OUTPUT | |
| } | |
| $project = $(Get-Item "$directory/src/$prefix.$package").Name | |
| Write-Output "project=$project" | |
| Write-Output "project=$project" >> $env:GITHUB_OUTPUT | |
| release: | |
| runs-on: ubuntu-latest | |
| needs: [meta] | |
| outputs: | |
| version: ${{ steps.create-release.outputs.version }} | |
| tag: ${{ steps.create-release.outputs.tag }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.client_payload.pull_request.head.ref }} | |
| fetch-depth: 0 | |
| token: ${{ secrets.REPOSITORY_WRITE_PAT }} | |
| - name: Install nbgv | |
| run: dotnet tool update -g nbgv | |
| - name: Configure git for PAT | |
| run: | | |
| git config user.name "ReleaseBot" | |
| git config user.email "dev-portal-poscreator@fiskaltrust.de" | |
| git remote set-url origin https://x-access-token:${{ secrets.REPOSITORY_WRITE_PAT }}@github.com/${{ github.repository }}.git | |
| - name: Get Release Data | |
| id: create-release | |
| if: startsWith(github.event.client_payload.pull_request.head.ref, 'release/') | |
| run: | | |
| nbgv tag --project ${{ needs.meta.outputs.directory }}/${{ needs.meta.outputs.project }} | |
| versionOutput=$(nbgv get-version --project ${{ needs.meta.outputs.directory }}/${{ needs.meta.outputs.project }} --public-release -f json) | |
| version=$(echo "$versionOutput" | jq -r '.SemVer2') | |
| tag=$(echo "$versionOutput" | jq -r ".VersionOptions.Release.TagName | sub(\"{version}\"; \"$version\")") | |
| preRelease=$(echo "$versionOutput" | jq -r 'has("PrereleaseVersion") and .PrereleaseVersion != ""') | |
| if ! git rev-parse "$tag" >/dev/null 2>&1; then | |
| echo "Error: Tag $tag does not exist" | |
| exit 1 | |
| fi | |
| git push --tags | |
| if [ "$preRelease" = "false" ]; then | |
| releaseNotes="You can find the full release notes on our docs platform https://docs.fiskaltrust.cloud/changelog/middleware/$version." | |
| else | |
| releaseNotes="This is a prerelease for the next middleware version." | |
| fi | |
| echo "tag=$tag" | |
| echo "tag=$tag" >> $GITHUB_OUTPUT | |
| echo "version=$version" | |
| echo "version=$version" >> $GITHUB_OUTPUT | |
| echo "preRelease=$preRelease" | |
| echo "preRelease=$preRelease" >> $GITHUB_OUTPUT | |
| echo "releaseNotes=$releaseNotes" | |
| echo "releaseNotes=$releaseNotes" >> $GITHUB_OUTPUT | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.create-release.outputs.tag }} | |
| name: "${{ needs.meta.outputs.releaseNamePrefix }}.${{ needs.meta.outputs.package }} v${{ steps.create-release.outputs.version }}" | |
| body: "${{ steps.create-release.outputs.releaseNotes }}" | |
| prerelease: ${{ steps.create-release.outputs.preRelease }} | |
| generate_release_notes: false | |
| make_latest: ${{ steps.create-release.outputs.preRelease == 'false'}} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.REPOSITORY_WRITE_PAT }} | |
| success: | |
| needs: | |
| - release | |
| runs-on: ubuntu-latest | |
| if: success('release') | |
| steps: | |
| - name: Add reaction | |
| uses: peter-evans/create-or-update-comment@v4 | |
| with: | |
| repository: ${{ github.event.client_payload.github.payload.repository.full_name }} | |
| comment-id: ${{ github.event.client_payload.github.payload.comment.id }} | |
| reactions: hooray | |
| reactions-edit-mode: replace | |
| edit-mode: replace | |
| body: | | |
| /${{ github.event.client_payload.slash_command.command }} ${{ github.event.client_payload.slash_command.args.all }} | |
| [](${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ needs.release.outputs.tag }}) | |
| failure: | |
| needs: | |
| - release | |
| runs-on: ubuntu-latest | |
| if: failure() | |
| steps: | |
| - name: Add reaction | |
| uses: peter-evans/create-or-update-comment@v4 | |
| with: | |
| repository: ${{ github.event.client_payload.github.payload.repository.full_name }} | |
| comment-id: ${{ github.event.client_payload.github.payload.comment.id }} | |
| reactions: confused | |
| reactions-edit-mode: replace | |
| edit-mode: replace | |
| body: | | |
| /${{ github.event.client_payload.slash_command.command }} ${{ github.event.client_payload.slash_command.args.all }} | |
| [](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) |