-
Notifications
You must be signed in to change notification settings - Fork 8
173 lines (151 loc) · 5.65 KB
/
publish.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
name: OpenData Release
on:
workflow_dispatch:
inputs:
release_tag:
description: 'Release tag: "{n}.{n}.{n}" e.g. 3.0.0, for Pre-Release "{n}.{n}.{n}rc{n}"'
required: true
pre_release:
description: 'Mark GitHub release as pre-release: [true, false]'
required: true
default: 'false'
env:
RELEASE_TAG: ${{ inputs.release_tag }}
PRE_RELEASE: ${{ inputs.pre_release }}
jobs:
build:
uses: ./.github/workflows/build.yml
secrets: inherit
release:
runs-on: ubuntu-latest
needs: build
outputs:
heading: ${{ steps.slack_vars.outputs.heading }}
title: ${{ steps.slack_vars.outputs.title }}
build_branch: ${{ steps.slack_vars.outputs.branch }}
run_url: ${{ steps.slack_vars.outputs.run_url }}
run_id: ${{ steps.slack_vars.outputs.run_id }}
run_status: ${{ steps.slack_vars.outputs.run_status }}
run_date: ${{ steps.slack_vars.outputs.run_date }}
steps:
- name: is branch valid for release
if: ${{ !startsWith(github.ref_name , 'release/') }}
run: |
echo "Releases must be trigged on branch named 'release/x.x.x'"
exit 1
- name: Check tag is valid for release
if: env.PRE_RELEASE == 'false'
run: |
VALID=$(echo ${{ env.RELEASE_TAG }} | grep -oPc "^(\d+)\.(\d+)\.(\d+)$")
if [[ ! "$VALID" == 1 ]]; then
echo "Release Tag ${{ env.RELEASE_TAG }} is not valid"
exit 1
fi
- name: Check tag is valid for pre-release
if: env.PRE_RELEASE == 'true'
run: |
VALID=$(echo ${{ env.RELEASE_TAG }} | grep -oPc "^(\d+)\.(\d+)\.(\d+)rc(\d+)$")
if [[ ! "$VALID" == 1 ]]; then
echo "Release Tag ${{ env.RELEASE_TAG }} is not valid"
exit 1
fi
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.ref_name }}
fetch-depth: 0
- name: Setup github user
run: |
git config --global user.email ${{ env.GIT_EMAIL }}
git config --global user.name ${{ env.GIT_USERNAME }}
git config --global pull.ff only
env:
GIT_EMAIL: ${{ secrets.BUILD_GIT_EMAIL }}
GIT_USERNAME: ${{ secrets.BUILD_GIT_USERNAME }}
- name: Update Readme
env:
GITHUB_TOKEN: ${{ secrets.BUILD_GIT_TOKEN }}
run: |
./utils/update-readme-release.sh ${{ env.RELEASE_TAG }}
git add ./README.md
git commit -m 'Update Readme.md'
- name: Tag Release
env:
GITHUB_TOKEN: ${{ secrets.BUILD_GIT_TOKEN }}
run: |
git checkout ${{ github.ref_name }}
git tag ${{ env.RELEASE_TAG }}
- name: Download JSON spec
uses: actions/download-artifact@v4
with:
name: extracted_spec
path: ${{ github.workspace }}/
- name: Download EXCEL spec
uses: actions/download-artifact@v4
with:
name: excel_spec
path: ${{ github.workspace }}/
# --- Create Release --- #
- name: Push changes
run: |
git push origin ${{ env.RELEASE_TAG }}
git push
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.BUILD_GIT_TOKEN }}
with:
tag_name: ${{ env.RELEASE_TAG }}
release_name: Release ${{ env.RELEASE_TAG }}
body_path: ""
draft: false
prerelease: ${{ env.PRE_RELEASE }}
# --- Attach build assests --- #
- name: Upload JSON Spec
id: upload-source-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.BUILD_GIT_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ github.workspace }}/${{ needs.build.outputs.json_filename }}
asset_name: ${{ needs.build.outputs.json_filename }}
asset_content_type: application/octet-stream
- name: Upload EXCEL Spec
id: upload-excel-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.BUILD_GIT_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ github.workspace }}/${{ needs.build.outputs.excel_filename }}
asset_name: ${{ needs.build.outputs.excel_filename }}
asset_content_type: application/octet-stream
# --- Slack notify --- #
- name: slack message vars
id: slack_vars
run: |
HEAD=$(echo "*${{ github.event.repository.name}} Release* (${{ env.RELEASE_TAG }})")
DATE=$(date)
TITLE=$(echo "• <https://github.com/${{ github.repository }}/releases/tag/${{ env.RELEASE_TAG }}|${{ github.event.repository.name }} ${{ env.RELEASE_TAG }} - Release Notes>")
JOB_URL=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
echo "heading=$HEAD" >> $GITHUB_OUTPUT
echo "run_date=$DATE" >> $GITHUB_OUTPUT
echo "title=$TITLE" >> $GITHUB_OUTPUT
echo "run_url=$JOB_URL" >> $GITHUB_OUTPUT
echo "run_id=${{ github.run_id }}" >> $GITHUB_OUTPUT
echo "branch=${{ github.ref_name }}" >> $GITHUB_OUTPUT
echo "run_status=${{ job.status }}" >> $GITHUB_OUTPUT
slack:
uses: OasisLMF/OasisLMF/.github/workflows/notify.yml@main
secrets: inherit
needs: release
with:
heading: ${{ needs.release.outputs.heading }}
title: ${{ needs.release.outputs.title }}
build_branch: ${{ needs.release.outputs.build_branch }}
run_url: ${{ needs.release.outputs.run_url }}
run_id: ${{ needs.release.outputs.run_id }}
run_status: ${{ needs.release.outputs.run_status }}
run_date: ${{ needs.release.outputs.run_date }}