Skip to content

Commit 9badacc

Browse files
ci: harden env and workflow inputs in run blocks (#286)
1 parent bb25a7c commit 9badacc

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

.github/workflows/jekyll-build.yml

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ on:
5959
description: 'Personal access token of the bot account'
6060
required: true
6161

62+
env:
63+
INPUT_SITE_ARTIFACT: ${{ inputs.site_artifact }}
64+
INPUT_EXTRACT_ARCHIVE: ${{ inputs.extract_archive }}
65+
INPUT_CONFIG_FILE: ${{ inputs.config_file }}
66+
INPUT_TARGET_BRANCH: ${{ inputs.target_branch }}
67+
INPUT_CLEAN_GH_PAGES: ${{ inputs.clean_gh_pages }}
68+
INPUT_THEME_REF: ${{ inputs.theme_ref }}
69+
INPUT_BASE_URL: ${{ inputs.base_url }}
70+
6271
jobs:
6372
build:
6473
name: Build Jekyll
@@ -67,7 +76,7 @@ jobs:
6776
- name: Input validation
6877
run: |
6978
error=false
70-
if [ "${{ inputs.site_artifact }}" == 'site' ]; then
79+
if [ "${INPUT_SITE_ARTIFACT}" == 'site' ]; then
7180
echo "Artifact name cannot be 'site'"
7281
error=true
7382
fi
@@ -80,37 +89,37 @@ jobs:
8089
uses: actions/checkout@v6
8190
with:
8291
repository: LizardByte/LizardByte.github.io
83-
ref: ${{ github.repository == 'LizardByte/LizardByte.github.io' && github.ref || inputs.theme_ref }}
92+
ref: ${{ github.repository == 'LizardByte/LizardByte.github.io' && github.ref || env.INPUT_THEME_REF }}
8493
submodules: recursive
8594
path: theme
8695

8796
- name: Download input artifact
88-
if: inputs.site_artifact != ''
97+
if: env.INPUT_SITE_ARTIFACT != ''
8998
uses: actions/download-artifact@v6
9099
with:
91-
name: ${{ inputs.site_artifact }}
100+
name: ${{ env.INPUT_SITE_ARTIFACT }}
92101
path: project
93102

94103
- name: Extract archive
95-
if: inputs.site_artifact != '' && inputs.extract_archive != ''
104+
if: env.INPUT_SITE_ARTIFACT != '' && env.INPUT_EXTRACT_ARCHIVE != ''
96105
working-directory: project
97106
run: |
98-
case "${{ inputs.extract_archive }}" in
107+
case "${INPUT_EXTRACT_ARCHIVE}" in
99108
*.tar.gz|*.tgz)
100-
tar -xzf "${{ inputs.extract_archive }}" -C .
109+
tar -xzf "${INPUT_EXTRACT_ARCHIVE}" -C .
101110
;;
102111
*.tar)
103-
tar -xf "${{ inputs.extract_archive }}" -C .
112+
tar -xf "${INPUT_EXTRACT_ARCHIVE}" -C .
104113
;;
105114
*.zip)
106-
7z x "${{ inputs.extract_archive }}" -o.
115+
7z x "${INPUT_EXTRACT_ARCHIVE}" -o.
107116
;;
108117
*)
109118
echo "Unsupported archive format"
110119
exit 1
111120
;;
112121
esac
113-
rm -f "${{ inputs.extract_archive }}"
122+
rm -f "${INPUT_EXTRACT_ARCHIVE}"
114123
115124
- name: Setup project
116125
if: github.repository == 'LizardByte/LizardByte.github.io'
@@ -184,10 +193,10 @@ jobs:
184193
run: |
185194
config_file="_config_ci.yml"
186195
echo "---" > "${config_file}"
187-
if [ "${{ inputs.base_url }}" == '_auto' ]; then
196+
if [ "${INPUT_BASE_URL}" == '_auto' ]; then
188197
echo "baseurl: '${{ steps.configure-pages.outputs.base_path }}'" >> $config_file
189198
else
190-
echo "baseurl: '${{ inputs.base_url }}'" >> "${config_file}"
199+
echo "baseurl: '${INPUT_BASE_URL}'" >> "${config_file}"
191200
fi
192201
193202
cat "${config_file}"
@@ -200,12 +209,12 @@ jobs:
200209
run: |
201210
# if inputs.config_file exists
202211
config_files="_config_ci.yml,_config_theme.yml"
203-
if [ -e "${{ inputs.config_file }}" ]; then
204-
cat ${{ inputs.config_file }}
205-
config_files="${config_files},${{ inputs.config_file }}"
212+
if [ -e "${INPUT_CONFIG_FILE}" ]; then
213+
cat "${INPUT_CONFIG_FILE}"
214+
config_files="${config_files},${INPUT_CONFIG_FILE}"
206215
fi
207216
208-
bundle exec jekyll build --future --config ${config_files}
217+
bundle exec jekyll build --future --config "${config_files}"
209218
210219
- name: Prepare Artifacts # uploading artifacts may fail if not zipped due to very large quantity of files
211220
shell: bash
@@ -232,14 +241,14 @@ jobs:
232241
- name: Checkout gh-pages
233242
uses: actions/checkout@v6
234243
with:
235-
ref: ${{ inputs.target_branch }}
244+
ref: ${{ env.INPUT_TARGET_BRANCH }}
236245
path: gh-pages
237246
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of the personal token
238247
fetch-depth: 0 # otherwise, will fail to push refs to dest repo
239248

240249
# empty contents of gh-pages
241250
- name: Clean
242-
if: inputs.clean_gh_pages
251+
if: env.INPUT_CLEAN_GH_PAGES == 'true'
243252
run: rm -f -r ./gh-pages/*
244253

245254
- name: Download artifact
@@ -262,6 +271,6 @@ jobs:
262271
author_email: ${{ secrets.GH_BOT_EMAIL }}
263272
author_name: ${{ secrets.GH_BOT_NAME }}
264273
directory: gh-pages
265-
branch: ${{ inputs.target_branch }}
274+
branch: ${{ env.INPUT_TARGET_BRANCH }}
266275
force: false
267276
message: "Deploy site from ${{ github.sha }}"

0 commit comments

Comments
 (0)