-
Notifications
You must be signed in to change notification settings - Fork 0
190 lines (158 loc) · 6.58 KB
/
validate-and-release.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
name: Validate SKOS Vocabulary (and release if on main)
on:
workflow_call:
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: write
pages: write
id-token: write
jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v2
with:
path: vocab
- name: Checkout workflow dependencies
uses: actions/checkout@v2
with:
repository: openactive/skos-vocabulary-workflows
path: workflow
- name: Install Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: '20.x'
- name: Install dependencies
run: npm install @openactive/skos handlebars ajv
- name: Validate vocabulary.jsonld
uses: actions/github-script@v7
with:
script: |
const Ajv = require('ajv');
const fs = require('fs');
const Handlebars = require('handlebars');
const skos = require('@openactive/skos');
const vocabularyIdentifier = context.repo.repo;
var schemaHandlebarsTemplateFile = "./workflow/workflow-dependencies/schema/skos-vocabulary.schema.json.hbs";
var skosFile = `./vocab/data/${vocabularyIdentifier}.jsonld`;
const schemaHandlebarsTemplate = Handlebars.compile(fs.readFileSync(schemaHandlebarsTemplateFile, 'utf8'));
const schema = JSON.parse(schemaHandlebarsTemplate({ 'VOCAB_IDENTIFIER': vocabularyIdentifier }));
const data = JSON.parse(fs.readFileSync(skosFile, 'utf8'));
var ajv = new Ajv({ allErrors: 'true', verbose: 'true' });
var validate = ajv.compile(schema);
var is_valid = validate(data);
// Try to load into SKOS.js (will throw on failure)
var scheme = new skos.ConceptScheme(data);
if(is_valid){
console.log(`${vocabularyIdentifier}.jsonld passed validation`);
} else {
const errorMessage = `${vocabularyIdentifier}.jsonld failed validation`
console.log(`${errorMessage}\n=======\n`);
console.log(validate.errors);
throw new Error(errorMessage);
}
release:
needs: validate
runs-on: ubuntu-latest
if: ${{ !contains(toJSON(github.event.commits.*.message), '[no-release]') && github.ref == 'refs/heads/main' }}
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false
# Deploy to the github-pages environment
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Check out repository
uses: actions/checkout@v2
with:
path: vocab
- name: Checkout workflow dependencies
uses: actions/checkout@v2
with:
repository: openactive/skos-vocabulary-workflows
path: workflow
- name: Get current time
id: timestamp
uses: nanzm/[email protected]
with:
format: 'YYYY-MM-DD_HH-mm-ss'
- name: Read version from file (if it exists)
id: version
run: |
if [ -f vocab/data/version.txt ]; then
version=$(cat vocab/data/version.txt)
else
version=""
fi
echo "::set-output name=version::$version"
- name: Render PR body
id: fetch_pr
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const { data: pulls } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'closed',
head: context.sha
});
const pr = pulls.find(pr => pr.merge_commit_sha === context.sha);
if (pr) {
return `${pr.body || ''}\n\nAssociated PR: #${pr.number}`;
} else {
console.log('No associated PR found; skipping release creation.');
return '';
}
- name: Install dependencies
run: npm install handlebars
if: ${{ steps.fetch_pr.outputs.result != '' }}
- name: Render redirect index.html to data folder for deployment
uses: actions/github-script@v7
if: ${{ steps.fetch_pr.outputs.result != '' }}
with:
script: |
const fs = require('fs');
const Handlebars = require('handlebars');
// Vocabulary identifier is the repository name
const vocabularyIdentifier = context.repo.repo;
// Extract Vocabulary Title from the source vocabulary file
const skosFile = `./vocab/data/${vocabularyIdentifier}.jsonld`;
const data = JSON.parse(fs.readFileSync(skosFile, 'utf8'));
const vocabularyTitle = data.title;
// Render the index.html file
const indexTemplateFile = "./workflow/workflow-dependencies/gh-pages/index.hbs";
const indexHandlebarsTemplate = Handlebars.compile(fs.readFileSync(indexTemplateFile, 'utf8'));
const indexHtml = indexHandlebarsTemplate({ 'VOCAB_IDENTIFIER': vocabularyIdentifier, 'VOCAB_TITLE': vocabularyTitle });
// Write the index.html file
const indexFileLocation = "./vocab/data/index.html";
fs.writeFileSync(indexFileLocation, indexHtml);
- name: Setup Pages
if: ${{ steps.fetch_pr.outputs.result != ''}}
uses: actions/configure-pages@v4
- name: Upload artifact
if: ${{ steps.fetch_pr.outputs.result != ''}}
uses: actions/upload-pages-artifact@v3
with:
# Upload only /data/ directory
path: './vocab/data/'
- name: Deploy artifact to GitHub Pages
if: ${{ steps.fetch_pr.outputs.result != ''}}
id: deployment
uses: actions/deploy-pages@v4
- name: Create Release
if: ${{ steps.fetch_pr.outputs.result != '' }}
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.version.outputs.version || steps.timestamp.outputs.time }}
release_name: Release v${{ steps.version.outputs.version || steps.timestamp.outputs.time }}
body: ${{ steps.fetch_pr.outputs.result }}
draft: false
prerelease: false