PR actions #133
This file contains 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: Setup .NET | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: | | |
8.0.x | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ format('refs/pull/{0}/head', github.event.issue.number) }} | |
fetch-depth: 0 | |
- name: Build PR release version | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
dotnet tool restore | |
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=$(dotnet minver --tag-prefix v --ignore-height --default-pre-release-identifiers preview.0).$branch.$sha | |
echo "MINVERVERSIONOVERRIDE=$version" >> $GITHUB_ENV | |
echo $version | |
- name: Build | |
run: | | |
dotnet build AppLibDotnet.sln -v m -c Release | |
- name: Test | |
run: | | |
dotnet test AppLibDotnet.sln -v m --no-restore --no-build -c Release | |
- name: Pack PR release | |
run: | | |
dotnet pack AppLibDotnet.sln -v m --no-restore --no-build -c Release -p:Deterministic=true | |
- 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 | |
- uses: actions/github-script@v7 | |
name: Comment on PR | |
with: | |
script: | | |
const version = process.env.MINVERVERSIONOVERRIDE; | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: `## Published PR packages:\n` + | |
`\n` + | |
`* [Altinn.App.Api ${version}](https://www.nuget.org/packages/Altinn.App.Api.Experimental/${version})\n` + | |
`* [Altinn.App.Core ${version}](https://www.nuget.org/packages/Altinn.App.Core.Experimental/${version})\n` | |
}) |