PR actions #4873
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: PR actions | |
| on: | |
| issue_comment: | |
| types: [created, edited] | |
| jobs: | |
| publish: | |
| name: Publish PR packages | |
| runs-on: ubuntu-latest | |
| if: github.event.issue.pull_request && contains(github.event.comment.body, '/publish') | |
| env: | |
| DOTNET_HOSTBUILDER__RELOADCONFIGONCHANGE: false | |
| steps: | |
| - name: Check if comment author is a contributor | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| comment_author="${{ github.event.comment.user.login }}" | |
| # Check if user has write access using a different approach | |
| permission=$(gh api repos/${{ github.repository }}/collaborators/$comment_author/permission 2>/dev/null | jq -r '.permission // "none"') | |
| if [[ "$permission" == "admin" || "$permission" == "write" ]]; then | |
| echo "Comment author ($comment_author) has $permission access, continuing" | |
| else | |
| echo "Comment author ($comment_author) has $permission access, skipping job" | |
| exit 1 | |
| fi | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@2016bd2012dba4e32de620c46fe006a3ac9f0602 # v5 | |
| with: | |
| dotnet-version: | | |
| 8.0.x | |
| - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 | |
| with: | |
| ref: ${{ format('refs/pull/{0}/head', github.event.issue.number) }} | |
| fetch-depth: 0 | |
| - name: Build PR release version | |
| id: build-version | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| sha=$(gh pr view ${{ github.event.issue.number }} --repo ${{ github.repository }} --json headRefOid | jq -r '.headRefOid' | cut -c1-8) | |
| branch=$(gh pr view ${{ github.event.issue.number }} --repo ${{ github.repository }} --json headRefName | jq -r '.headRefName' | sed 's/.*\///') | |
| version=$(git describe --abbrev=0 --tags 2>/dev/null) | |
| version=$(echo $version | cut -d '-' -f 1) | |
| version="$version-pr.${{ github.run_number }}.$branch.$sha" | |
| version=$(echo $version | sed 's/^v//') | |
| echo "MINVERVERSIONOVERRIDE=$version" >> $GITHUB_ENV | |
| echo "PR_RELEASE_VERSION=$version" >> $GITHUB_OUTPUT | |
| echo $version | |
| - name: Create PR comment | |
| uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4 | |
| id: pr-comment | |
| with: | |
| issue-number: ${{ github.event.issue.number }} | |
| body: | | |
| ## PR release: | |
| * [Altinn.App.Api ${{ steps.build-version.outputs.PR_RELEASE_VERSION }}](https://www.nuget.org/packages/Altinn.App.Api.Experimental/${{ steps.build-version.outputs.PR_RELEASE_VERSION }}) | |
| * [Altinn.App.Core ${{ steps.build-version.outputs.PR_RELEASE_VERSION }}](https://www.nuget.org/packages/Altinn.App.Core.Experimental/${{ steps.build-version.outputs.PR_RELEASE_VERSION }}) | |
| > ⚙️ Building... | |
| - name: Build | |
| run: | | |
| dotnet build -v m -c Release -p:Deterministic=true -p:BuildNumber=${{ github.run_number }} | |
| - name: Test | |
| run: | | |
| dotnet test -v m --no-restore --no-build -c Release | |
| - name: Pack PR release | |
| run: | | |
| dotnet pack -v m --no-restore --no-build -c Release -p:Deterministic=true -p:BuildNumber=${{ github.run_number }} | |
| - name: Versions | |
| run: | | |
| dotnet --version | |
| - name: Publish PR release | |
| run: | | |
| dotnet nuget push src/**/bin/Release/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }} --skip-duplicate | |
| - name: Update PR comment - failure | |
| uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4 | |
| if: failure() | |
| with: | |
| issue-number: ${{ github.event.issue.number }} | |
| comment-id: ${{ steps.pr-comment.outputs.comment-id }} | |
| edit-mode: append | |
| body: | | |
| > ❌ Failed: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
| - name: Update PR comment - success | |
| uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4 | |
| if: success() | |
| with: | |
| issue-number: ${{ github.event.issue.number }} | |
| comment-id: ${{ steps.pr-comment.outputs.comment-id }} | |
| edit-mode: append | |
| body: | | |
| > ✅ Done! | |
| reactions: rocket |