-
Notifications
You must be signed in to change notification settings - Fork 1
135 lines (123 loc) · 4.36 KB
/
pages-gh-cli.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
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
name: Deploy Pages via GH CLI
on:
# push:
# branches:
# - main
workflow_dispatch:
# Allow one concurrent deployment
concurrency:
group: "pages-gh-cli-deploy"
cancel-in-progress: true
defaults:
run:
shell: bash
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read # to read the repository itself
outputs: # make artifact-id available in deploy job
artifact-id: ${{ steps.artifact-upload.outputs.artifact-id }}
artifact-url: ${{ steps.artifact-upload.outputs.artifact-url }}
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up NodeJs
uses: actions/setup-node@v4
with:
node-version-file: '.node-version'
- name: Setup Pages
id: pages
uses: actions/configure-pages@v4
- name: Install Dependencies
run: npm ci
- name: Generate Site
run: npx antora antora-playbook.yml
- name: Upload artifact
uses: actions/upload-artifact@v4
id: artifact-upload
with:
name: page-artifact
path: build/site
if-no-files-found: error
configure:
runs-on: ubuntu-latest
permissions:
contents: read # to read the repository itself
pages: write # to configure to Pages
needs: build
steps:
- name: Check Page Exists
id: exists
run: |
if gh api --silent \
--header "Accept: application/vnd.github+json" \
--header "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${GH_REPOSITORY}/pages" ; then
echo "page_configured=true" >> "$GITHUB_OUTPUT"
else
echo "page_configured=false" >> "$GITHUB_OUTPUT"
fi
env:
GH_REPOSITORY: ${{ github.repository }}
GH_TOKEN: ${{ github.token }}
- name: Setup Page
run: |
echo "::debug::GH_REPOSITORY=${GH_REPOSITORY}"
echo "::debug::PAGE_CONFIGURED=${PAGE_CONFIGURED}"
jq --null-input --raw-output \
'{ "build_type": "workflow" }' \
> request.json
method=POST
if [[ ${PAGE_CONFIGURED} = true ]]; then
method=PUT
fi
curl -L \
-X ${method} \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GH_TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${GH_REPOSITORY}/pages \
-d '{ "build_type": "workflow" }'
# Causes a Resource not accessible by integration (HTTP 403) error
# Probably related to https://github.com/orgs/community/discussions/35595
# gh api \
# --method ${method} \
# --header "Accept: application/vnd.github+json" \
# --header "X-GitHub-Api-Version: 2022-11-28" \
# "/repos/${GH_REPOSITORY}/pages" \
# --input request.json
env:
PAGE_CONFIGURED: ${{ steps.exists.outputs.page_configured }}
GH_REPOSITORY: ${{ github.repository }}
GH_TOKEN: ${{ github.token }}
deploy:
runs-on: ubuntu-latest
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
actions: read # to access the artifact of the previous workflow
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source
needs: [build, configure]
steps:
- name: Deploy to GitHub Pages
run: |
echo "::debug::GH_REPOSITORY=${GH_REPOSITORY}"
echo "::debug::GH_SHA=${GH_SHA}"
echo "::debug::GH_ARTIFACT_ID=${GH_ARTIFACT_ID}"
echo "::debug::GH_ARTIFACT_URL=${GH_ARTIFACT_URL}"
gh api \
--method POST \
--header "Accept: application/vnd.github+json" \
--header "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${GH_REPOSITORY}/pages/deployment" \
-f artifact_id="${GH_ARTIFACT_ID}" \
-f environment='github-pages' \
-f pages_build_version="${GH_SHA}" \
-f oidc_token="${GH_TOKEN}"
env:
GH_REPOSITORY: ${{ github.repository }}
GH_SHA: ${{ github.sha }}
GH_TOKEN: ${{ github.token }}
GH_ARTIFACT_ID: ${{ needs.build.outputs.artifact-id }}
GH_ARTIFACT_URL: ${{ needs.build.outputs.artifact-url }}