generated from caltechlibrary/template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
97 lines (90 loc) · 4.52 KB
/
action.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
# GitHub Actions definition for Waystation.
#
# Copyright 2022-2024 California Institute of Technology.
# License: Modified BSD 3-clause – see file "LICENSE" in the project website.
# Website: https://github.com/caltechlibrary/waystation
name: Waystation
description: Archive a repository's GitHub Pages in the Wayback Machine
author: Michael Hucka – https://github.com/mhucka
branding:
icon: camera
color: orange
inputs:
dry_run:
description: Print what would be done without actually doing it.
default: false
required: false
save_errors:
# Corresponds to "saveErrors" in the Wayback Machine GitHub Action.
description: Whether the Wayback Machine should save pages that return HTTP status 4xx-5xx.
default: false
required: false
save_outlinks:
# Corresponds to "saveOutlinks" in the Wayback Machine GitHub Action.
description: Tell the Wayback Machine to save links to external web pages.
default: true
required: false
save_screenshot:
# Corresponds to "saveScreenshot" in the Wayback Machine GitHub Action.
description: Tell the Wayback Machine to save a screenshot of the front page.
default: true
required: false
debug:
description: Print context and variables in the GitHub Actions log.
default: false
required: false
runs:
using: composite
steps:
- name: Get GitHub Pages URL.
# This stores the URL in env.pages_url. The value will be "null" if
# no pages URL is returned for any reason.
shell: bash
run: |
echo pages_url=$(curl -s -H 'Accept: application/vnd.github+json' -H "Authorization: Bearer ${{github.token}}" https://api.github.com/repos/${{github.repository}}/pages | jq '.html_url' | tr -d '"') >> $GITHUB_ENV
- name: Dump GitHub Actions context and variables if debugging is on.
if: inputs.debug == true || inputs.debug == 'true'
env:
# Setting this variable and then printing it below is not strictly
# necessary; you could put the expression directly into the echo
# command below. But when I do that, I get a doubling of the output.
GITHUB_CONTEXT: ${{toJSON(github)}}
shell: bash
run: |
echo "dry_run = ${{inputs.dry_run}}"
echo "pages_url = ${{env.pages_url}}"
echo "save_outlinks = ${{inputs.save_outlinks}}"
echo "save_screenshots = ${{inputs.save_screenshots}}"
echo "debug = ${{inputs.debug}}"
echo "====================="
echo "$GITHUB_CONTEXT"
- name: Quit if GitHub Pages URL is null.
if: startsWith(env.pages_url, 'null') == true
uses: actions/github-script@v7
with:
script: |
core.setFailed("Could not retrieve the GitHub Pages URL for repository ${{github.repository}}.")
- name: Proceed if this is not a dry run.
if: startsWith(env.pages_url, 'null') != true && inputs.dry_run != true && inputs.dry_run != 'true'
uses: JamieMagee/[email protected]
with:
url: ${{env.pages_url}}
saveOutlinks: ${{inputs.save_outlinks}}
saveScreenshot: ${{inputs.save_screenshot}}
- name: Summarize the results of the run.
shell: bash
env:
wm_url: https://web.archive.org/web/${{env.pages_url}}
run: |
echo \#\# Results of sending the GitHub Pages to the Wayback Machine >> $GITHUB_STEP_SUMMARY
echo Dry run: ${{inputs.dry_run}} >> $GITHUB_STEP_SUMMARY
echo GitHub repository for this action: \`${{github.repository}}\` >> $GITHUB_STEP_SUMMARY
echo GitHub Pages URL for the repository: ${{env.pages_url}} >> $GITHUB_STEP_SUMMARY
echo **URL in the Wayback Machine**: ${{env.wm_url}} >> $GITHUB_STEP_SUMMARY
echo Date and time of this run: $(date "+%F %T (%Z)") >> $GITHUB_STEP_SUMMARY
echo ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ >> $GITHUB_STEP_SUMMARY
echo Note: sometimes the Wayback Machine takes extra long to start >> $GITHUB_STEP_SUMMARY
echo archiving a site. If your GitHub Pages URL is not yet found at >> $GITHUB_STEP_SUMMARY
echo Wayback Machine URL above, wait for a time and then try to >> $GITHUB_STEP_SUMMARY
echo look up your GitHub Pages URL again. >> $GITHUB_STEP_SUMMARY
echo ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ >> $GITHUB_STEP_SUMMARY