-
Notifications
You must be signed in to change notification settings - Fork 0
204 lines (158 loc) · 6.43 KB
/
package-publish.yaml
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
name: "publish packages"
on:
push:
branches: [ "master" ]
paths:
- 'src/**'
- '.github/workflows/package-publish.yaml'
- 'scripts/*'
- '*.props'
- '!samples'
jobs:
find-changed-packages:
name: "find changed packages"
runs-on: ubuntu-latest
if: ${{ github.actor != 'itmo-is-dev-ci[bot]' }}
outputs:
packages: ${{ steps.changed-packages.outputs.changed-package-projects }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: find Directory.Build.props changes
id: find-build
run: |
changes_count=$(git --no-pager diff ${{ github.event.before }} ${{ github.event.after }} Directory.Build.props \
| grep -Ec '^\+ ') || :
echo changes-count="$changes_count" >> "$GITHUB_OUTPUT"
- name: find Directory.Packages.props changes
id: find-packages
run: |
source ./scripts/common-scripts.sh
changed_packages=$(git --no-pager diff ${{ github.event.before }} ${{ github.event.after }} Directory.Packages.props \
| grep -E '^\+ ' \
| get_tag_attribute_value 'Include' \
| lines_to_json_array) || :
echo changed-packages="$changed_packages" >> "$GITHUB_OUTPUT"
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v45
- name: find changed package projects
id: find-changed-package-projects
if: ${{ steps.find-build.outputs.changes-count == 0 }}
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
ALL_CHANGED_DEPENDENCIES: ${{ steps.find-packages.outputs.changed-packages }}
run: |
source ./scripts/changes-scripts.sh
changed_package_projects=$({
echo "$ALL_CHANGED_FILES" | find_changed_projects;
echo "$ALL_CHANGED_DEPENDENCIES" | find_changed_dependencies
} | sort | uniq | lines_to_json_array)
echo changed-package-projects="$changed_package_projects" >> "$GITHUB_OUTPUT"
- name: calculate final changed packages
id: changed-packages
env:
SELECTED_PACKAGES: ${{ steps.find-changed-package-projects.outputs.changed-package-projects }}
run: |
source ./scripts/project-scripts.sh
if [[ ${{ steps.find-build.outputs.changes-count }} -eq 0 ]]
then
echo changed-package-projects="$SELECTED_PACKAGES" >> "$GITHUB_OUTPUT"
else
echo changed-package-projects="$(find_package_projects | lines_to_json_array)" >> "$GITHUB_OUTPUT"
fi
commit-patches:
name: commit patch versions
runs-on: ubuntu-latest
needs: find-changed-packages
environment: itmo-is-dev-ci
permissions:
contents: write
if: ${{
needs.find-changed-packages.outputs.packages != '[]'
&& needs.find-changed-packages.outputs.packages != ''
}}
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ secrets.ITMO_IS_DEV_CI_APP_ID }}
private-key: ${{ secrets.ITMO_IS_DEV_CI_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
- name: set config
run: |
git config user.name github-actions
git config user.email [email protected]
- name: change patch versions
env:
CHANGED_PACKAGES: ${{ needs.find-changed-packages.outputs.packages }}
run: |
source ./scripts/common-scripts.sh
source ./scripts/platform-scripts.sh
echo "$CHANGED_PACKAGES" | json_array_to_lines | while read -r line
do
change_package_patch_version "$line" ${{ github.run_number }}
done
- name: commit patch version changes
env:
CHANGED_PACKAGES: ${{ needs.find-changed-packages.outputs.packages }}
run: |
source ./scripts/common-scripts.sh
git add ./src/**/*.csproj
git commit -m'[deploy] commited patch #${{ github.run_number }}' -m "$(echo "$CHANGED_PACKAGES" | json_array_to_lines)"
git push
publish-package:
name: ${{ matrix.package }}
runs-on: ubuntu-latest
needs:
- find-changed-packages
- commit-patches
environment:
name: nuget.org
url: ${{ steps.deployment-url.outputs.url }}
if: ${{
needs.find-changed-packages.outputs.packages != '[]'
&& needs.find-changed-packages.outputs.packages != ''
}}
strategy:
matrix:
package: ${{ fromJSON(needs.find-changed-packages.outputs.packages) }}
steps:
- uses: actions/checkout@v4
- name: change patch versions
env:
CHANGED_PACKAGES: ${{ needs.find-changed-packages.outputs.packages }}
run: |
source ./scripts/common-scripts.sh
source ./scripts/platform-scripts.sh
echo "$CHANGED_PACKAGES" | json_array_to_lines | while read -r line
do
change_package_patch_version "$line" ${{ github.run_number }}
done
- name: generate deployment url
id: deployment-url
run: |
source ./scripts/platform-scripts.sh
full_name=$(echo ${{ matrix.package }} | short_name_to_full_name)
package_version=$(get_package_version ${{ matrix.package }})
url=https://www.nuget.org/packages/"$full_name"/"$package_version"
echo url="$url" >> "$GITHUB_OUTPUT"
- name: format csproj path
id: csproj
run: |
source ./scripts/common-scripts.sh
csproj_path=$(echo ${{ matrix.package }} | short_name_to_csproj_path)
csproj_dir=$(echo ${{ matrix.package }} | short_name_to_dir_path)
echo path="$csproj_path" >> "$GITHUB_OUTPUT"
echo dir="$csproj_dir" >> "$GITHUB_OUTPUT"
- name: restore
run: dotnet restore ${{ steps.csproj.outputs.path }}
- name: build
run: dotnet build ${{ steps.csproj.outputs.path }} -c Release --no-restore
- name: publish
run: |
nuget_path=$(ls ${{ steps.csproj.outputs.dir }}/bin/Release/*.nupkg)
dotnet nuget push "$nuget_path" --source "nuget.org" --api-key ${{ secrets.NUGET_API_KEY }}