generated from greenelab/lab-website-template
-
Notifications
You must be signed in to change notification settings - Fork 6
69 lines (57 loc) · 1.89 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
69
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
- uses: crazy-max/ghaction-dump-context@v2
- name: Get Pages url
id: pages
uses: actions/configure-pages@v4
- name: Checkout branch contents
uses: actions/checkout@v4
# for debugging
- if: runner.debug == '1'
uses: mxschmitt/action-tmate@v3
# update link to site in readme
- name: Update readme
uses: actions/github-script@v7
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@v18
with:
files: |
README.md
- name: Commit changed files
if: steps.changed.outputs.files_changed == 'true'
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Update url"
outputs:
changed: ${{ steps.changed.outputs.files_changed }}