-
Notifications
You must be signed in to change notification settings - Fork 2
231 lines (199 loc) · 9.1 KB
/
semantic-release.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
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
name: Release Workflow
on:
workflow_dispatch:
jobs:
check-release:
runs-on: ubuntu-latest
concurrency: check-release
permissions:
id-token: write
contents: write
outputs:
new_release_published: ${{ steps.semantic_release_version.outputs.new_release_published }}
new_release_version: ${{ steps.semantic_release_version.outputs.new_release_version }}
prerelease: ${{ steps.check-prerelease.outputs.prerelease }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "lts/*"
- name: Install dependencies
run: |
sudo snap install yq
npm install @semantic-release/changelog @semantic-release/github
- name: Semantic Release (Determine new version)
id: semantic_release_version
uses: cycjimmy/semantic-release-action@v4
with:
extra_plugins: |
@semantic-release/changelog
@semantic-release/github
dry_run: true
ci: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Output new release version
run: |
echo Version: ${{ steps.semantic_release_version.outputs.new_release_version }}
echo new_release_published: ${{ steps.semantic_release_version.outputs.new_release_published }}
- name: Check pre-release
id: check-prerelease
run: |
if [[ "${{ steps.semantic_release_version.outputs.new_release_version }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "prerelease=false" >> $GITHUB_OUTPUT
else
echo "prerelease=true" >> $GITHUB_OUTPUT
fi
shell: bash
- name: Echo Prelease
run: |
echo pre-release: ${{ steps.check-prerelease.outputs.prerelease }}
perform-release:
needs: check-release
if: needs.check-release.outputs.new_release_published == 'true'
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
outputs:
new_release_published: ${{ steps.semantic_release.outputs.new_release_published }}
new_release_version: ${{ steps.semantic_release.outputs.new_release_version }}
new_release_git_tag: ${{ steps.semantic_release.outputs.new_release_git_tag }}
prerelease: ${{ needs.check-release.outputs.prerelease }}
ig_canonical: ${{ steps.yaml-data.outputs.canonical }}
ig_id: ${{ steps.yaml-data.outputs.id }}
ig_asset_filename: ${{ steps.generate-asset-filename.outputs.ig_asset_filename }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "lts/*"
- name: Install dependencies
run: |
sudo snap install yq
npm install @semantic-release/changelog @semantic-release/github
- name: Update sushi-config.yaml with new version
run: |
yq eval '.version = "${{ needs.check-release.outputs.new_release_version }}"' -i sushi-config.yaml
# read id, version and canonical from sushi-config.yaml
- name: Read YAML file
id: yaml-data
run: |
VERSION=$(yq eval '.version' sushi-config.yaml)
ID=$(yq eval '.id' sushi-config.yaml)
CANONICAL=$(yq eval '.canonical' sushi-config.yaml)
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "id=$ID" >> $GITHUB_OUTPUT
echo "canonical=$CANONICAL" >> $GITHUB_OUTPUT
- name: Generate asset filename
id: generate-asset-filename
run: echo "ig_asset_filename=${{ steps.yaml-data.outputs.id }}-${{ needs.check-release.outputs.new_release_version }}.tgz" >> $GITHUB_OUTPUT
# display outputs from read-yaml action
- name: Display read-yaml output
run: |
echo "id: ${{ steps.yaml-data.outputs.id }}"
echo "target url: ${{ steps.yaml-data.outputs.canonical }}"
echo "version: ${{ steps.yaml-data.outputs.version }}"
echo "asset filename: ${{ steps.generate-asset-filename.outputs.ig_asset_filename }}"
- name: Run the IG publisher
uses: docker://hl7fhir/ig-publisher-base:latest
with:
args: ./run-ig-publisher.sh
- name: Move package.tgz to output directory
run: |
mkdir -p dist/
mv ./output/package.tgz dist/${{ steps.generate-asset-filename.outputs.ig_asset_filename }}
- name: Deploy to GitHub Pages
if: needs.check-release.outputs.prerelease == 'false'
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./output
force_orphan: true
- name: Semantic Release (Create release)
id: semantic_release
uses: cycjimmy/semantic-release-action@v4
with:
extra_plugins: |
@semantic-release/changelog
@semantic-release/github
ci: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
update-package-feed:
needs: perform-release
if: needs.perform-release.outputs.new_release_published == 'true' && needs.perform-release.outputs.prerelease == 'false'
runs-on: ubuntu-latest
steps:
- name: Output new release version
run: |
echo ${{ needs.perform-release.outputs.new_release_version }}
- name: Install dependencies
run: |
sudo apt-get install -y xmlstarlet gh
# Checkout the external repository where package-feed.xml is located
- name: Checkout external repository
uses: actions/checkout@v3
with:
repository: 'umg-minai/fhir-package-feed'
token: ${{ secrets.FHIR_PACKAGE_FEED_REPO_TOKEN }}
path: 'external-repo'
# Update package-feed.xml in the external repository
- name: Update package-feed.xml
run: |
cd external-repo
TITLE="${{ needs.perform-release.outputs.ig_id }}#${{ needs.perform-release.outputs.new_release_version }}"
NEW_LINK="https://github.com/${{ github.repository }}/releases/download/${{ needs.perform-release.outputs.new_release_git_tag }}/${{ needs.perform-release.outputs.ig_asset_filename }}?raw=true"
NEW_GUID=$NEW_LINK
DESCRIPTION="Release ${{ needs.perform-release.outputs.new_release_version }} of ${{ needs.perform-release.outputs.ig_id }}"
PUB_DATE=$(date -u +"%a, %d %b %Y %H:%M:%S %Z")
VERSION="${{ needs.perform-release.outputs.new_release_version }}"
CREATOR="${{ github.actor }}"
KIND="IG"
XML_FILE="package-feed.xml"
ITEM_EXISTS=$(xmlstarlet sel -t -v "count(/rss/channel/item[title='$TITLE'])" $XML_FILE)
if [ "$ITEM_EXISTS" -eq "0" ]; then
echo "Item does not exist, adding new item..."
xmlstarlet ed --inplace \
-s /rss/channel -t elem -n item -v "" \
-s "//item[last()]" -t elem -n title -v "$TITLE" \
-s "//item[last()]" -t elem -n description -v "$DESCRIPTION" \
-s "//item[last()]" -t elem -n link -v "$NEW_LINK" \
-s "//item[last()]" -t elem -n guid -v "$NEW_GUID" \
-s "//item[last()]" -t elem -n dc:creator -v "$CREATOR" \
-s "//item[last()]" -t elem -n fhir:version -v "$VERSION" \
-s "//item[last()]" -t elem -n fhir:kind -v "$KIND" \
-s "//item[last()]" -t elem -n pubDate -v "$PUB_DATE" \
$XML_FILE
else
echo "Item exists, updating..."
xmlstarlet ed --inplace \
-u "/rss/channel/item[title='$TITLE']/link" -v "$NEW_LINK" \
-u "/rss/channel/item[title='$TITLE']/guid" -v "$NEW_GUID" \
-u "/rss/channel/item[title='$TITLE']/description" -v "$DESCRIPTION" \
-u "/rss/channel/item[title='$TITLE']/dc:creator" -v "$CREATOR" \
-u "/rss/channel/item[title='$TITLE']/fhir:version" -v "$VERSION" \
-u "/rss/channel/item[title='$TITLE']/fhir:kind" -v "$KIND" \
-u "/rss/channel/item[title='$TITLE']/pubDate" -v "$PUB_DATE" \
$XML_FILE
fi
shell: bash
- name: Push new branch
run: |
cd external-repo
git config user.name '${{ github.actor }}'
git config user.email '${{ github.actor }}@users.noreply.github.com'
NEW_BRANCH="update-package-feed-${{ needs.perform-release.outputs.ig_id }}-${{ needs.perform-release.outputs.new_release_version }}"
git checkout -b $NEW_BRANCH
git add package-feed.xml
git commit -m "Update package-feed.xml with new release information"
git push --set-upstream origin $NEW_BRANCH
gh pr create --repo umg-minai/fhir-package-feed-test --head $NEW_BRANCH --base main --title "Add ${{ needs.perform-release.outputs.ig_id }}-${{ needs.perform-release.outputs.new_release_version }}" --body "Automated update of package-feed.xml with new release information"
env:
GITHUB_TOKEN: ${{ secrets.FHIR_PACKAGE_FEED_REPO_TOKEN }}