71 lines (69 loc) · 2.93 KB
/
remote_update.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
name: 'Receives a remote update payload, and requests a rebuild'
on:
workflow_dispatch:
inputs:
name:
description: 'Name given to your content in cards and page titles'
required: true
url:
description: 'URL of requesting repository'
required: true
id:
description: 'ID to be used throughout site, including in URL'
required: false
content:
description: 'Path of file to render for page content'
required: false
image:
description: 'Path of image to use as the feature image in cards'
required: false
image_position:
description: "Value for CSS 'background-position' of feature image"
required: false
jobs:
update:
runs-on: ubuntu-18.04
steps:
- name: Checkout site code
uses: actions/checkout@v2
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: '12'
- name: Cache dependencies
id: cache-deps
uses: actions/cache@v2
env:
cache-name: node
with:
path: node_modules
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-
- name: Install dependencies
run: |
npm install
- name: Add a file corresponding to the payload (also check for errors)
run: |
node -e 'require("./lib/remote").createRemoteEntry(${{ toJSON(github.event.inputs)}})'
- name: Create a new commit, only if it is necessary
run: |
name_short="$(echo ${{ github.event.inputs.url }} | sed 's/.*\/\([^\/]*\/[^\/]*$\)/\1/')"
echo "NAME_SHORT=${name_short}" >> $GITHUB_ENV
[ -z "$(git status --porcelain)" ] && echo "Skipping commit as entry already exists." && exit 0
echo "Creating a new commit due to dirty state"
git config --local user.email "actions@github.com"
git config --local user.name "GitHub Action"
git add .
git commit -m "Remote entry update for '$name_short'"
git push
echo "REBUILD_REQUIRED=true" >> $GITHUB_ENV
- name: Request a rebuild if required
run: |
repo_path="../latest"
git clone ${{ github.event.inputs.url }} "$repo_path"
git fetch --all
git checkout origin/gh_pages -- .repo_cache_info || true
[ -z "$REBUILD_REQUIRED" ] && ! node -e 'require("./lib/remote").rebuildRequired("'$NAME_SHORT'", "'$repo_path'") || require("process").exit(1)' && echo "No rebuild required. Skipping step." && exit 0
echo "Rebuild required. Starting a site rebuild"
curl -sS --request POST -H "Accept: application/vnd.github.v3+json" -H "Authorization: token ${{ secrets.QCRBOT_TOKEN }}" https://api.github.com/repos/qcr/qcr.github.io/actions/workflows/build_site.yml/dispatches --data '{"ref": "master"}'