-
Notifications
You must be signed in to change notification settings - Fork 3
131 lines (130 loc) · 4.83 KB
/
PRNugetPublish.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
---
name: PRNugetPublish
on:
workflow_run:
workflows:
- "PRCodeArtifact"
types:
- completed
jobs:
pr_info:
name: Determine PR number and SHA
runs-on: ubuntu-22.04
strategy:
fail-fast: false
outputs:
pr_num: ${{ steps.vars.outputs.pr_num }}
pr_run_num: ${{ steps.vars.outputs.pr_run_num }}
pr_sha: ${{ steps.vars.outputs.pr_sha }}
pr_prefix: ${{ steps.vars.outputs.pr_prefix }}
steps:
- name: Download PR source code artifact
id: download-pr-artifact
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh run --repo ${{ github.repository }} download ${{ github.event.workflow_run.id }}
- name: Display structure of downloaded files
run: ls -R
- name: Setup output vars
id: vars
run: |
echo "pr_num=$(cat Kirel.Repositories*/pr_number)" >> $GITHUB_OUTPUT
echo "pr_run_num=$(cat Kirel.Repositories*/pr_run_number)" >> $GITHUB_OUTPUT
echo "pr_sha=$(cat Kirel.Repositories*/pr_sha)" >> $GITHUB_OUTPUT
echo "pr_prefix=-DANGER-pr$(cat Kirel.Repositories*/pr_number)-$(cat Kirel.Repositories*/pr_run_number)" >> $GITHUB_OUTPUT
- name: Replace source code to src dir
run: |
mv Kirel.Repositories*/src src
rm -rf Kirel.Repositories*
- name: Checkout main
uses: actions/checkout@v3
with:
ref: 'main'
path: 'main'
- name: Save source code to cache
uses: actions/cache@v3
with:
path: |
src
main
key: src-${{ steps.vars.outputs.pr_sha }}
build:
name: Build and publish
permissions:
checks: write
runs-on: ubuntu-22.04
needs: pr_info
strategy:
fail-fast: false
matrix:
package: [ Core, EntityFramework ]
env:
RUN_ID: ${{ github.event.workflow_run.id }}
steps:
- name: Source cache
uses: actions/cache@v3
with:
path: |
src
main
key: src-${{ needs.pr_info.outputs.pr_sha }}
- name: Display structure of cached files
run: ls -R
- name: Setup dotnet
uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.x'
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: |
echo "$GITHUB_CONTEXT"
- name: Link PR Check
id: pr_check
uses: actions/github-script@v6
with:
script: |
args = {
owner: context.repo.owner,
repo: context.repo.repo,
head_sha: "${{ needs.pr_info.outputs.pr_sha }}",
name: "NuGet / ${{ matrix.package }} Upload",
status: 'in_progress',
};
console.log("Arguments:", args);
let result = await github.rest.checks.create(args);
console.log("Result:", result);
return {
check_run_id: result.data.id
};
- name: Version check
run: |
curr_ver=$(cat main/src/Kirel.Repositories.${{ matrix.package }}/Kirel.Repositories.${{ matrix.package }}.csproj | grep PackageVersion |sed s/'\s'//g | sed 's/<\/PackageVersion>//g' | sed 's/<PackageVersion>//g')
pr_ver=$(cat src/Kirel.Repositories.${{ matrix.package }}/Kirel.Repositories.${{ matrix.package }}.csproj | grep PackageVersion |sed s/'\s'//g | sed 's/<\/PackageVersion>//g' | sed 's/<PackageVersion>//g')
if [[ "$curr_ver" != "$pr_ver" ]]; then echo "::error::${{ matrix.package }}: incorrect version" && exit 1; fi
- name: Build
run: |
dotnet restore src/Kirel.Repositories.${{ matrix.package }}/Kirel.Repositories.${{ matrix.package }}.csproj
dotnet build --version-suffix ${{ needs.pr_info.outputs.pr_prefix }} src/Kirel.Repositories.${{ matrix.package }}/Kirel.Repositories.${{ matrix.package }}.csproj
dotnet pack -o ./packages --version-suffix ${{ needs.pr_info.outputs.pr_prefix }} src/Kirel.Repositories.${{ matrix.package }}/Kirel.Repositories.${{ matrix.package }}.csproj
- name: Publish
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: |
dotnet nuget push packages/*.nupkg -k ${NUGET_API_KEY} -s nuget.org
- name: Update PR Check
uses: actions/github-script@v6
if: always()
with:
script: |
let args = {
owner: context.repo.owner,
repo: context.repo.repo,
check_run_id: ${{ fromJSON(steps.pr_check.outputs.result).check_run_id }},
status: 'completed',
conclusion: '${{ job.status }}'
};
console.log("Arguments:", args);
let result = await github.rest.checks.update(args);
console.log("Result:", result);