-
Notifications
You must be signed in to change notification settings - Fork 2
169 lines (134 loc) · 5.99 KB
/
cookbook_preproc.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
name: Pre-process example notebooks
on:
workflow_dispatch:
inputs:
pr_number:
description: 'Update the cache for PR#: (leave blank if not a PR)'
required: false
default: ""
type: string
schedule:
- cron: 0 0 * * * # 1/day at midnight UTC
push:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ inputs.pr_number || github.ref || github.run_id }}
cancel-in-progress: true
jobs:
preprocess:
runs-on: ubuntu-latest
steps:
- name: Choose deployment branch
shell: bash -l {0}
run: |
if [[ ${{ github.event_name }} != "workflow_dispatch" ]]; then
echo "DEPLOY_BRANCH=_cookbook_data_$GITHUB_REF_NAME" >> "$GITHUB_ENV"
elif [[ "${{ inputs.pr_number }}" == "" ]]; then
echo "DEPLOY_BRANCH=_cookbook_data_$GITHUB_REF_NAME" >> "$GITHUB_ENV"
else
echo "DEPLOY_BRANCH=_cookbook_data_PR${{ inputs.pr_number }}" >> "$GITHUB_ENV"
fi
- name: Report dispatch to PR
if: github.event_name == 'workflow_dispatch' && inputs.pr_number != ''
uses: thollander/actions-comment-pull-request@v2
with:
pr_number: ${{ inputs.pr_number }}
message: >
A workflow has been dispatched to regenerate the cookbook cache for this PR.
- Run ID: [${{ github.run_id }}]
- Triggering actor: ${{ github.triggering_actor }}
- Target branch: ${{ github.ref_name }}
- Deployment branch: ${{ env.DEPLOY_BRANCH }}
[${{ github.run_id }}]: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
- name: Create check
if: github.event_name == 'workflow_dispatch' && inputs.pr_number != ''
id: create-check
uses: actions/github-script@v6
with:
script: |
const created_run = await github.request(
'POST /repos/{owner}/{repo}/check-runs',
{
owner: context.repo.owner,
repo: context.repo.repo,
name: '${{ github.job }}',
head_sha: '${{ github.sha }}',
details_url: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}',
status: 'in_progress',
started_at: new Date().toISOString(),
output: {
title: 'Regenerate example notebook cache',
summary: 'Results and progress: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}',
text: ''
},
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
}
)
return created_run.data.id
- uses: actions/checkout@v3
- name: Install Conda environment
uses: mamba-org/setup-micromamba@v1
with:
environment-file: devtools/conda-envs/examples_env.yml
- name: Pre-process and execute notebooks
shell: bash -l {0}
run: |
python source/_ext/proc_examples.py --prefix=deploy/ --cache-branch=${DEPLOY_BRANCH}
- name: Deploy cache
shell: bash -l {0}
run: |
cd deploy
git config --global user.name github-actions
git config --global user.email [email protected]
git config --global init.defaultBranch main
# Create an empty repository so we don't have to fetch (guaranteeing atomicity)
git init .
git remote add origin "https://github-actions:${{ github.token }}@github.com/${{ github.repository }}.git"
# Commit the deployment and force push to the deploy branch
git add .
git commit -m "Deploy pre-processed notebook cache"
git push --force origin HEAD:$DEPLOY_BRANCH
- name: Trigger RTD build
# RTD doesn't offer a way to manually trigger builds in PRs, so we'll just do this for other builds
if: github.event_name == 'schedule' || github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.pr_number == '')
shell: bash -l {0}
run: |
curl -X POST -d "branches=$GITHUB_REF_NAME" -d "token=${{ secrets.RTD_WEBHOOK_TOKEN }}" https://readthedocs.org/api/v2/webhook/openff-docs/243876/
- name: Report status to PR
if: always() && github.event_name == 'workflow_dispatch' && inputs.pr_number != ''
uses: thollander/actions-comment-pull-request@v2
with:
pr_number: ${{ inputs.pr_number }}
message: >
A workflow dispatched to regenerate the cookbook cache for this PR has just finished.
- Run ID: [${{ github.run_id }}]
- Triggering actor: ${{ github.triggering_actor }}
- Target branch: ${{ github.ref_name }}
- Deployment branch: ${{ env.DEPLOY_BRANCH }}
- Status: **${{ job.status }}**
If the workflow was successful, changes will only be visible in the ReadTheDocs
preview after it has been [rebuilt].
[${{ github.run_id }}]: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
[rebuilt]: https://readthedocs.org/projects/openff-docs/builds/
- name: Update check
if: always() && github.event_name == 'workflow_dispatch' && inputs.pr_number != ''
uses: actions/github-script@v6
with:
script: |
await github.request(
'PATCH /repos/{owner}/{repo}/check-runs/{check_run_id}',
{
owner: context.repo.owner,
repo: context.repo.repo,
check_run_id: ${{ steps.create-check.outputs.result }},
status: 'completed',
conclusion: '${{ job.status }}',
completed_at: new Date().toISOString(),
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
}
)