-
Notifications
You must be signed in to change notification settings - Fork 15
147 lines (124 loc) · 6.47 KB
/
Copy pathci-pr.yml
File metadata and controls
147 lines (124 loc) · 6.47 KB
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
# This action runs when a pull request to main is created or updated
# (but not when it is merged into main).
name: CI on pull request create or update
on:
# Using "pull_request" is not sufficient to allow commits to PR branches in
# forks. Since the workflow only accesses the xlsx and turtle files, but does
# not run any code, it is safe to use pull_request_target. More info:
# https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/
pull_request_target:
branches:
- main
types: [opened, reopened, synchronize]
workflow_dispatch:
env:
FORCE_COLOR: "1" # Make tool output pretty.
PIP_DISABLE_PIP_VERSION_CHECK: "1"
PIP_PROGRESS_BAR: "off"
LOGLEVEL: "DEBUG"
RUN_URL: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID
jobs:
build_vocab:
name: Merge & build vocabulary
# Run on all pull request types except merge which has its own workflow.
if: ${{ !github.event.pull_request.merged }}
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
# Give the default GITHUB_TOKEN write permission to commit to the PR branch.
contents: write
steps:
- name: Checkout PR branch into cwd
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3
with:
# Checkout the fork/head-repository to push changes to the fork.
# Without this the base repository will be checked out and committed to.
repository: ${{ github.event.pull_request.head.repo.full_name }}
# Checkout the branch made in the fork.
ref: ${{ github.head_ref }}
- name: Checkout main branch into directory _main_branch/
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3
with:
ref: main
path: _main_branch
# This sparse-checkout includes all toplevel files and everything below vocabularies/
sparse-checkout: |
vocabularies/
fetch-depth: 1
- uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548
with:
python-version: '3.13'
- name: Install dependencies
run: |
python -VV
python -m pip install --upgrade pip setuptools wheel
# install tagged version
python -m pip install git+https://github.com/nfdi4cat/voc4cat-tool.git@v0.10.0
# python -m pip install git+https://github.com/nfdi4cat/voc4cat-tool.git@main
# install custom pylode 2.x (adds sorted collections,
# uses URIs as fragment IDs and is git-installable)
python -m pip install git+https://github.com/dalito/pyLODE.git@nfdi4cat-2.x
# Example for installing from private repo:
# python -m pip install git+https://anon:${{ SECRETS.READ_PAT_VOC4CAT }}@github.com/dalito/voc4cat-tool.git@main
- name: Set dynamic environment variables.
run: |
echo "RUN_DATE=$(date +'%Y-%m-%dT%H%M')" >> $GITHUB_ENV
- name: Run voc4cat (pre-convert checks)
run: |
voc4cat --version
# check inbox file names
voc4cat check --config _main_branch/idranges.toml --logfile outbox/voc4cat.log --ci-pre inbox-excel-vocabs/ _main_branch/vocabularies
# check xlsx file(s). If the check fails, write annotated file to outbox.
voc4cat check --config _main_branch/idranges.toml --logfile outbox/voc4cat.log --outdir outbox inbox-excel-vocabs/
- name: Run voc4cat (convert)
run: |
# convert file(s) from xlsx in inbox to turtle in outbox
voc4cat convert --config _main_branch/idranges.toml --logfile outbox/voc4cat.log --outdir outbox inbox-excel-vocabs/
if [ ! -f outbox/*.ttl ]; then
echo "No ttl file in outbox. Building joined vocabulary ttl-file from individual ttl-files in vocabulary."
voc4cat transform --join --logfile outbox/voc4cat.log --outdir outbox/ vocabularies/
fi
- name: Run voc4cat (post-convert checks)
run: |
# check all ttl file(s) in outbox
voc4cat check --config _main_branch/idranges.toml --logfile outbox/voc4cat.log outbox/
# check if vocabulary changes are allowed
voc4cat check --config _main_branch/idranges.toml --logfile outbox/voc4cat.log --ci-post _main_branch/vocabularies outbox/
- name: Run voc4cat (build HTML documentation)
run: |
voc4cat docs --logfile outbox/voc4cat.log --force outbox/
- name: Split vocabulary and merge into vocabulary dir (in PR branch)
run: |
voc4cat transform --split --inplace --logfile outbox/voc4cat.log --outdir outbox_new_voc outbox/
voc4cat-merge --logfile outbox/voc4cat.log outbox_new_voc/ vocabularies/
# copy xlsx to outbox so that the xlsx file is part of the artifact
find inbox-excel-vocabs -name '*.xlsx' -exec cp {} -t outbox/ \;
git status
- name: Run voc4cat (re-build updated Excel file and joined turtle vocabulary file)
# Passing the config is important to make use of the prefixes therein.
run: |
mkdir -p outbox/updated-xlsx-ttl
voc4cat convert --config idranges.toml --logfile outbox/voc4cat.log --template templates/voc4cat_template_043.xlsx outbox/updated-xlsx-ttl
voc4cat transform --config idranges.toml --logfile outbox/voc4cat.log -O outbox/updated-xlsx-ttl --join vocabularies/
- name: Store artifacts
if: ${{ always() }}
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4
with:
name: voc4cat-outbox_${{ env.RUN_DATE }}_run${{ GITHUB.RUN_ID }}
path: outbox/
- name: Add/stage vocabulary changes
# Pinning of action managed by dependabot
uses: stefanzweifel/git-auto-commit-action@28e16e81777b558cc906c8750092100bbb34c5e3
with:
# glob pattern of files which should be added to the commit
file_pattern: 'vocabularies/\*.ttl'
- name: Remove Excel vocabulary files from inbox
run: |
git rm inbox-excel-vocabs/\*.xlsx || echo "No xlsx files to remove."
git status
- name: Commit vocabulary changes & xlsx cleanup on behalf of PR-author
# Pinning of action managed by dependabot
uses: stefanzweifel/git-auto-commit-action@28e16e81777b558cc906c8750092100bbb34c5e3
with:
commit_user_name: voc4cat-CI-bot
commit_message: 'CI: vocabulary update in ${{ GITHUB.SERVER_URL }}/${{ GITHUB.REPOSITORY }}/actions/runs/${{ GITHUB.RUN_ID }}'