forked from music-encoding/music-encoding
-
Notifications
You must be signed in to change notification settings - Fork 0
256 lines (219 loc) · 10.7 KB
/
deploy.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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# This workflow will perform the following steps for pushes the the develop branch
# * build the Schema and the Guidelines with Ant
# * publish the Schema to music-encoding/schema under ./dev
# * publish the Guidelines to music-encoding/guidelines under ./dev
# Alternatively it will peform the following steps for tags on stable
# * build the Schema and the Guidelines with Ant
# * publish the Schema to music-encoding/schema under ./[TAG-NAME]
# * publish the Guidelines to music-encoding/guidelines under ./[TAG-NAME]
name: Deploy Schema and Guidelines
on:
push:
branches:
- 'develop'
- 'release/**'
tags:
- 'v[1-9][0-9]?.[0-9]'
env:
REPO_OWNER: music-encoding
IS_DEV_OR_TAG: false # will be set dynamically in steps below
# schema
SCHEMA_REPO: ${{ github.repository_owner }}/schema
SCHEMA_BRANCH: main
# guidelines
GUIDELINES_REPO: ${{ github.repository_owner }}/guidelines
GUIDELINES_BRANCH: main
# temporary directories
SCHEMA_DIR: schema-dir
GUIDELINES_DIR: guidelines-dir
TARGET_DIR: '' # will be set dynamically in steps below
jobs:
build:
name: Build and deploy Schema and Guidelines
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Echo properties
run: |
echo "github.repository: ${{ github.repository }}"
echo "github.repository_owner: ${{ github.repository_owner }}"
echo "github.ref: ${{ github.ref }}"
echo "github.ref_type: ${{ github.ref_type }}"
echo "github.ref_name: ${{ github.ref_name }}"
echo "github.sha: ${{ github.sha }}"
echo "github.event_name: ${{ github.event_name }}"
echo "github.event.base_ref: ${{ github.event.base_ref }}"
### BUIDLING THE SCHEMA AND THE GUIDELINES ###
- name: Checkout main repo
uses: actions/checkout@v4
with:
# Whether to checkout submodules: `true` to checkout submodules or `recursive` to
# recursively checkout submodules.
#
# When the `ssh-key` input is not provided, SSH URLs beginning with
# `[email protected]:` are converted to HTTPS.
#
# Default: false
submodules: recursive
- name: Build schema and guidelines with Docker image
run: docker run --rm -v $(pwd):/opt/docker-mei/music-encoding ghcr.io/music-encoding/docker-mei:latest ant -noinput -buildfile music-encoding/build.xml -Ddocker=true -Dgithub.sha=${{ github.sha }} -Dgithub.event_name=${{ github.event_name }} -Dgithub.ref=${{ github.ref }}
### UPLOADING THE ARTIFACTS ###
- name: Upload PDF
uses: actions/upload-artifact@v4
with:
name: pdf
path: ${{ github.workspace }}/dist/guidelines/pdf/MEI_Guidelines_*.pdf
- name: Upload Prince XML log
uses: actions/upload-artifact@v4
with:
name: prince_log
path: ${{ github.workspace }}/build/prince.log
### Block further steps if not running on develop or tag
- name: Block steps if not on develop or tag
if: github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags/v')
run: echo "IS_DEV_OR_TAG=true" >> $GITHUB_ENV
### VALIDATE IS_DEV_OR_TAG VARIABLE
- name: Validate IS_DEV_OR_TAG
run: echo "IS_DEV_OR_TAG=$IS_DEV_OR_TAG"
### SET TARGET_DIR environment variable for dev version
- name: Set TARGET_DIR for dev
if: github.repository_owner == env.REPO_OWNER && github.ref == 'refs/heads/develop'
run: echo "TARGET_DIR=dev" >> $GITHUB_ENV
### SET TAG_VERSION environment variable for tagged release
- name: Set TAG_VERSION for tagged release
if: github.repository_owner == env.REPO_OWNER && startsWith(github.ref, 'refs/tags/v')
run: echo "TAG_VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
### VALIDATE TARGET NAME & TAG VERSION
- name: Validate TARGET_DIR
if: github.repository_owner == env.REPO_OWNER && env.IS_DEV_OR_TAG == 'true'
run: |
echo "TARGET_DIR=$TARGET_DIR"
echo "TAG_VERSION=$TAG_VERSION"
### PUBLISHING THE SCHEMA ###
- name: Checkout SCHEMA_REPO into SCHEMA_DIR
if: github.repository_owner == env.REPO_OWNER && env.IS_DEV_OR_TAG == 'true'
uses: actions/checkout@v4
with:
# repository to check out
repository: ${{ env.SCHEMA_REPO }}
# Deploy key as secret for accessing <owner>/<SCHEMA_REPO>;
# cf. explanation in https://github.com/rism-ch/verovio/pull/1751
ssh-key: ${{ secrets.GH_ACTIONS_DEPLOY_KEY_SCHEMA }}
# ref (branch, tag or SHA) to check out
ref: ${{ env.SCHEMA_BRANCH }}
# relative path under $GITHUB_WORKSPACE to place the repository
path: ${{ env.SCHEMA_DIR }}
- name: Create correct TARGET_DIR for schema on release (e.g., 5.0)
if: github.repository_owner == env.REPO_OWNER && startsWith(github.ref, 'refs/tags/v')
run: |
echo ${TAG_VERSION:1:3}
echo "TARGET_DIR=${TAG_VERSION:1:3}" >> $GITHUB_ENV
- name: Validate SCHEMA_DIR
if: github.repository_owner == env.REPO_OWNER && env.IS_DEV_OR_TAG == 'true'
run: echo "SCHEMA_DIR=$SCHEMA_DIR/$TARGET_DIR"
- name: Copy built schema to SCHEMA_DIR
if: github.repository_owner == env.REPO_OWNER && env.IS_DEV_OR_TAG == 'true'
run: |
rm -rf $SCHEMA_DIR/$TARGET_DIR
cp -r dist/schemata/ $SCHEMA_DIR/
mv $SCHEMA_DIR/schemata $SCHEMA_DIR/$TARGET_DIR
- name: Copy mei-source_canonicalized to SCHEMA_DIR
if: github.repository_owner == env.REPO_OWNER && env.IS_DEV_OR_TAG == 'true'
run: find ${{ github.workspace }}/build -name 'mei-source_canonicalized_*.xml' -exec cp {} $SCHEMA_DIR/$TARGET_DIR/ \;
- name: Check git status before commit
if: github.repository_owner == env.REPO_OWNER && env.IS_DEV_OR_TAG == 'true'
working-directory: ${{ env.SCHEMA_DIR }}
run: |
git config --get remote.origin.url
git status
- name: Configure git
if: github.repository_owner == env.REPO_OWNER && env.IS_DEV_OR_TAG == 'true'
working-directory: ${{ env.SCHEMA_DIR }}
run: |
echo "Configuring git..."
git config user.name "github-actions"
git config user.email "[email protected]"
- name: Commit files
if: github.repository_owner == env.REPO_OWNER && env.IS_DEV_OR_TAG == 'true'
working-directory: ${{ env.SCHEMA_DIR }}
run: |
echo "Running git commit..."
git add .
git commit -m "Auto-commit of schema build for ${{ github.repository }}@${{ github.sha }}"
- name: Push changes to SCHEMA
if: github.repository_owner == env.REPO_OWNER && env.IS_DEV_OR_TAG == 'true'
working-directory: ${{ env.SCHEMA_DIR }}
run: git push origin HEAD:$SCHEMA_BRANCH
### PUBLISHING THE GUIDELINES ###
- name: Checkout GUIDELINES_REPO into GUIDELINES_DIR
if: github.repository_owner == env.REPO_OWNER && env.IS_DEV_OR_TAG == 'true'
uses: actions/checkout@v4
with:
# repository to check out
repository: ${{ env.GUIDELINES_REPO }}
# Deploy key as secret for accessing <owner>/<GUIDELINES_REPO>;
# cf. explanation in https://github.com/rism-ch/verovio/pull/1751
ssh-key: ${{ secrets.GH_ACTIONS_DEPLOY_KEY_GUIDELINES }}
# ref (branch, tag or SHA) to check out
ref: ${{ env.GUIDELINES_BRANCH }}
# relative path under $GITHUB_WORKSPACE to place the repository
path: ${{ env.GUIDELINES_DIR }}
- name: Create correct TARGET_DIR for guidelines on release (e.g., v5)
if: github.repository_owner == env.REPO_OWNER && startsWith(github.ref, 'refs/tags/v')
run: |
echo ${TAG_VERSION:0:2}
echo "TARGET_DIR=${TAG_VERSION:0:2}" >> $GITHUB_ENV
- name: Validate GUIDELINES_DIR
if: github.repository_owner == env.REPO_OWNER && env.IS_DEV_OR_TAG == 'true'
run: echo "GUIDELINES_DIR=$GUIDELINES_DIR/$TARGET_DIR"
- name: Copy built web guidelines to GUIDELINES_DIR
if: github.repository_owner == env.REPO_OWNER && env.IS_DEV_OR_TAG == 'true'
run: |
rm -rf $GUIDELINES_DIR/$TARGET_DIR
cp -r dist/guidelines/web $GUIDELINES_DIR/
mv $GUIDELINES_DIR/web $GUIDELINES_DIR/$TARGET_DIR
- name: Copy built PDF guidelines to GUIDELINES_DIR, if release is being created
if: github.repository_owner == env.REPO_OWNER && startsWith(github.ref, 'refs/tags/v')
run: find ${{ github.workspace }}/dist/guidelines/pdf -name 'MEI_Guidelines_*.pdf' -exec cp {} $GUIDELINES_DIR/$TARGET_DIR/ \;
- name: Check git status before commit
if: github.repository_owner == env.REPO_OWNER && env.IS_DEV_OR_TAG == 'true'
working-directory: ${{ env.GUIDELINES_DIR }}
run: |
git config --get remote.origin.url
git status
- name: Configure git
if: github.repository_owner == env.REPO_OWNER && env.IS_DEV_OR_TAG == 'true'
working-directory: ${{ env.GUIDELINES_DIR }}
run: |
echo "Configuring git..."
git config user.name "github-actions"
git config user.email "[email protected]"
- name: Commit files
if: github.repository_owner == env.REPO_OWNER && env.IS_DEV_OR_TAG == 'true'
working-directory: ${{ env.GUIDELINES_DIR }}
run: |
echo "Running git commit..."
git add .
git commit -m "Auto-commit of guidelines build for ${{ github.repository }}@${{ github.sha }}"
- name: Push changes to GUIDELINES
if: github.repository_owner == env.REPO_OWNER && env.IS_DEV_OR_TAG == 'true'
working-directory: ${{ env.GUIDELINES_DIR }}
run: git push origin HEAD:$GUIDELINES_BRANCH
# Create a release, when a tag is pushed
# could be remodelled to automatically create the tag, too
# but then the version would have to be determined programatically
- name: Create release
if: startsWith(github.ref, 'refs/tags/v')
uses: ncipollo/release-action@2c591bcc8ecdcd2db72b97d6147f871fcd833ba5 # ratchet:ncipollo/[email protected]
with:
allowUpdates: false
artifacts: "${{ github.workspace }}/dist/guidelines/pdf/MEI_Guidelines_${{ github.ref_name }}.pdf"
artifactErrorsFailBuild: true
commit: ${{ github.sha }}
draft: true
generateReleaseNotes: true
name: "MEI ${{ github.ref_name }}"
prerelease: false
replacesArtifacts: true
tag: "" # ref_name will be used if it is a tag