generated from greenelab/lab-website-template
-
Notifications
You must be signed in to change notification settings - Fork 0
68 lines (57 loc) · 1.87 KB
/
update-url.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
name: update-url
run-name: update site after url change
on:
# run when called from another workflow
workflow_call:
outputs:
changed:
value: ${{ jobs.update-url.outputs.changed }}
# run if user manually requests it
workflow_dispatch:
permissions:
contents: write
jobs:
update-url:
runs-on: ubuntu-latest
steps:
# for debugging
- name: Print contexts
uses: crazy-max/ghaction-dump-context@v1
- name: Get Pages url
id: pages
uses: actions/configure-pages@v2
with:
enablement: false
- name: Checkout branch contents
uses: actions/checkout@v3
# update link to site in readme
- name: Update readme
uses: actions/github-script@v6
with:
script: |
const { readFileSync, writeFileSync } = require("fs");
const file = "README.md";
let contents = readFileSync(file).toString();
const find = /\*\*\[.*\]\(.*\)\*\*/;
const host = "${{ steps.pages.outputs.host }}";
const path = "${{ steps.pages.outputs.base_path }}";
const url = "${{ steps.pages.outputs.base_url }}";
const replace = `**[${host}${path}](${url})**`;
if (contents.match(find))
contents = contents.replace(find, replace);
else
contents = `Visit ${replace} 🚀\n\n` + contents;
writeFileSync(file, contents);
- name: Check if readme changed
id: changed
uses: tj-actions/verify-changed-files@v13
with:
files: |
README.md
- name: Commit changed files
if: steps.changed.outputs.files_changed == 'true'
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "Update url"
outputs:
changed: ${{ steps.changed.outputs.files_changed }}