-
Notifications
You must be signed in to change notification settings - Fork 3
140 lines (122 loc) · 4.95 KB
/
worker.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
name: Worker
on:
push:
branches: [main]
schedule:
- cron: "0,10,20,30,40,50 * * * *"
workflow_dispatch:
jobs:
update:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
submodules: "true"
- name: Import GPG key
id: import-gpg
uses: crazy-max/ghaction-import-gpg@v4
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
git_config_global: true
git_user_signingkey: true
git_commit_gpgsign: true
fingerprint: "BD98B3F42545FF93EFF55F7F3F39AA1432CA6AD7"
- name: Get next job
id: get-next-job
uses: Nautilus-Cyberneering/git-queue@v1
with:
queue_name: "library-update"
action: "next-job"
- name: Parse job payload
id: parse-payload
if: ${{ steps.get-next-job.outputs.job_found == 'true' }}
shell: bash
run: |
PAYLOAD="${{ steps.get-next-job.outputs.job_payload }}" ./scripts/parse-payload.sh
- name: Build job started message payload
id: build-start-payload
if: ${{ steps.get-next-job.outputs.job_found == 'true' }}
shell: bash
run: |
PAYLOAD="Successfully started job according to specification in commit:
https://github.com/josecelano/library-consumer/commit/${{ steps.get-next-job.outputs.job_commit }}"
PAYLOAD="${PAYLOAD//'%'/'%25'}"
PAYLOAD="${PAYLOAD//$'\n'/'%0A'}"
PAYLOAD="${PAYLOAD//$'\r'/'%0D'}"
echo "::set-output name=payload::$(echo "$PAYLOAD")"
- name: Mark job as started
id: start-job
if: ${{ steps.get-next-job.outputs.job_found == 'true' }}
uses: Nautilus-Cyberneering/git-queue@v1
with:
queue_name: "library-update"
action: "start-job"
job_payload: ${{ steps.build-start-payload.outputs.payload }}
# Begin mutual exclusion job
- name: Update submodule
id: update-submodule
if: ${{ steps.get-next-job.outputs.job_found == 'true' }}
shell: bash
run: |
cd libraries/aaa
git fetch --all
git checkout ${{ steps.parse-payload.outputs.current_ref }} && echo "::set-output name=updated::true"
- name: Commit submodule update
id: commit-submodule-update
if: ${{ steps.get-next-job.outputs.job_found == 'true' }}
shell: bash
run: |
git add libraries/aaa
git commit -m "update library aaa to commit ${{ steps.parse-payload.outputs.current_ref }}"
- name: Sync files from library
if: ${{ steps.get-next-job.outputs.job_found == 'true' }}
id: copy-library
run: |
rsync -a --delete --include="*/" --include="*.txt" --exclude="*" ./libraries/aaa/data/ ./libraries_mirror/aaa
- name: Apply changes with a single commit
if: ${{ steps.get-next-job.outputs.job_found == 'true' }}
run: |
git add libraries_mirror/aaa
# commit only if there are changes
git diff-index --quiet HEAD || git commit -m "library aaa synced to commit ${{ steps.parse-payload.outputs.current_ref }}"
# End mutual exclusion job
- name: Build job finished message payload
id: build-finish-payload
if: ${{ steps.start-job.outputs.job_started == 'true' }}
shell: bash
run: |
PAYLOAD="Successfully finished job according to specification in commit:
https://github.com/josecelano/library-consumer/commit/${{ steps.get-next-job.outputs.job_commit }}"
PAYLOAD="${PAYLOAD//'%'/'%25'}"
PAYLOAD="${PAYLOAD//$'\n'/'%0A'}"
PAYLOAD="${PAYLOAD//$'\r'/'%0D'}"
echo "::set-output name=payload::$(echo "$PAYLOAD")"
- name: Mark job as finished
id: finish-job
if: ${{ steps.start-job.outputs.job_started == 'true' }}
uses: Nautilus-Cyberneering/git-queue@v1
with:
queue_name: "library-update"
action: "finish-job"
job_payload: ${{ steps.build-finish-payload.outputs.payload }}
- name: Debug step outputs
if: ${{ steps.get-next-job.outputs.job_found == 'true' }}
run: |
echo -e "previous_ref: ${{ steps.parse-payload.outputs.previous_ref }}"
echo -e "current_ref: ${{ steps.parse-payload.outputs.current_ref }}"
echo -e "updated: ${{ steps.update-submodule.outputs.updated }}"
echo -e "start payload:\n${{ steps.build-start-payload.outputs.payload }}"
echo -e "finish payload:\n${{ steps.build-finish-payload.outputs.payload }}"
- name: Show new commits
run: |
git log --pretty="fuller" --show-signature -5
- name: Push
id: push
if: ${{ steps.get-next-job.outputs.job_found == 'true' }}
shell: bash
run: |
git push