-
Notifications
You must be signed in to change notification settings - Fork 2
132 lines (110 loc) · 5.26 KB
/
ci-pr.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
# 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:
pull_request_target:
branches:
- main
types: [opened, edited, 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@v4
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@v4
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@v5
with:
python-version: '3.11'
- 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.8.1
# 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/
- 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/
merge_vocab --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: Store artifacts
if: ${{ always() }}
uses: actions/upload-artifact@v3
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@8756aa072ef5b4a080af5dc8fef36c5d586e521d
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@8756aa072ef5b4a080af5dc8fef36c5d586e521d
with:
commit_user_name: voc4cat-CI-bot
commit_message: 'CI: vocabulary update in ${{ GITHUB.SERVER_URL }}/${{ GITHUB.REPOSITORY }}/actions/runs/${{ GITHUB.RUN_ID }}'