Skip to content

Commit 2f7313f

Browse files
refactor: harden inputs and secret usage
Moves input and secret references to environment variables for improved readability and maintainability. Updates all usages in steps to reference the new env variables, reducing repetition and simplifying future changes.
1 parent bc6d9c2 commit 2f7313f

1 file changed

Lines changed: 34 additions & 26 deletions

File tree

.github/workflows/copr-ci.yml

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,34 @@ on:
3939
description: 'Copr CLI configuration file. See https://copr.fedorainfracloud.org/api'
4040
required: true
4141

42+
env:
43+
INPUTS_AUTO_UPDATE_PACKAGE: ${{ inputs.auto_update_package }}
44+
INPUTS_COPR_PR_WEBHOOK_TOKEN: ${{ inputs.copr_pr_webhook_token }}
45+
INPUTS_COPR_OWNERNAME: ${{ inputs.copr_ownername }}
46+
INPUTS_GITHUB_ORG_OWNER: ${{ inputs.github_org_owner }}
47+
INPUTS_JOB_TIMEOUT: ${{ inputs.job_timeout }}
48+
SECRETS_COPR_BETA_WEBHOOK_TOKEN: ${{ secrets.COPR_BETA_WEBHOOK_TOKEN }}
49+
SECRETS_COPR_STABLE_WEBHOOK_TOKEN: ${{ secrets.COPR_STABLE_WEBHOOK_TOKEN }}
50+
SECRETS_COPR_CLI_CONFIG: ${{ secrets.COPR_CLI_CONFIG }}
51+
4252
jobs:
4353
package-init:
4454
name: Create/update copr package
4555
runs-on: ubuntu-latest
4656
container: fedora:latest
4757
env:
4858
BASE_URL: https://copr.fedorainfracloud.org/api_3
49-
OWNERNAME: ${{ inputs.copr_ownername }}
5059
PACKAGE_NAME: ${{ github.event.repository.name }}
5160
SOURCE_TYPE_TEXT: "custom"
5261
steps:
5362
- name: Debug inputs
5463
run: |
5564
echo "inputs:"
56-
echo "copr_pr_webhook_token: ${{ inputs.copr_pr_webhook_token }}"
57-
echo "github_org_owner: ${{ inputs.github_org_owner }}"
58-
echo "copr_ownername: ${{ inputs.copr_ownername }}"
59-
echo "auto_update_package: ${{ inputs.auto_update_package }}"
60-
echo "job_timeout: ${{ inputs.job_timeout }}"
65+
echo "copr_pr_webhook_token: ${INPUTS_COPR_PR_WEBHOOK_TOKEN}"
66+
echo "github_org_owner: ${INPUTS_GITHUB_ORG_OWNER}"
67+
echo "copr_ownername: ${INPUTS_COPR_OWNERNAME}"
68+
echo "auto_update_package: ${INPUTS_AUTO_UPDATE_PACKAGE}"
69+
echo "job_timeout: ${INPUTS_JOB_TIMEOUT}"
6170
6271
- name: Test secrets
6372
id: test_secrets
@@ -66,18 +75,18 @@ jobs:
6675
inputs.auto_update_package == true
6776
run: |
6877
# return if secrets.COPR_CLI_CONFIG is empty
69-
if [ -z "${{ secrets.COPR_CLI_CONFIG }}" ]; then
78+
if [[ -z "${SECRETS_COPR_CLI_CONFIG}" ]]; then
7079
echo "Copr CLI configuration file is empty. Exiting..."
7180
7281
# if a pull request exit with 0
73-
if [ "${{ github.event_name }}" = "pull_request" ]; then
82+
if [[ "${{ github.event_name }}" = "pull_request" ]]; then
7483
echo "SKIP_REMAINING_JOBS=true" >> "${GITHUB_OUTPUT}"
7584
else
7685
exit 1
7786
fi
7887
else
7988
mkdir -p ~/.config
80-
echo "${{ secrets.COPR_CLI_CONFIG }}" > ~/.config/copr
89+
echo "${SECRETS_COPR_CLI_CONFIG}" > ~/.config/copr
8190
fi
8291
8392
- name: Install dependencies
@@ -97,7 +106,7 @@ jobs:
97106
)
98107
99108
# download the latest copr-ci.sh script
100-
if [ "${{ github.repository }}" = "LizardByte/copr-ci" ]; then
109+
if [[ "${{ github.repository }}" = "LizardByte/copr-ci" ]]; then
101110
# use the version from the same ref
102111
ref="${{ github.ref }}"
103112
else
@@ -118,7 +127,8 @@ jobs:
118127
119128
for project in "${projects[@]}"; do
120129
# check if 404 on get package (package does not exist)
121-
url="${BASE_URL}/package?ownername=${OWNERNAME}&projectname=${project}&packagename=${PACKAGE_NAME}"
130+
url_query="ownername=${INPUTS_COPR_OWNERNAME}&projectname=${project}&packagename=${PACKAGE_NAME}"
131+
url="${BASE_URL}/package?${url_query}"
122132
status_code=$(curl --write-out '%{http_code}' --silent --output /dev/null "${url}")
123133
124134
if [[ "$status_code" == 404 ]]; then
@@ -136,7 +146,7 @@ jobs:
136146
--script-resultdir "${resultdir}" \
137147
--script-chroot "${chroot}" \
138148
--name "${PACKAGE_NAME}" \
139-
--timeout $((60 * ${{ inputs.job_timeout }})) \
149+
--timeout $((60 * INPUTS_JOB_TIMEOUT)) \
140150
"${project}"
141151
142152
done
@@ -174,7 +184,7 @@ jobs:
174184
mkdir -p .github/matchers
175185
176186
# download the latest rpmlint.json matcher
177-
if [ ! "${{ github.repository }}" = "LizardByte/copr-ci" ]; then
187+
if [[ ! "${{ github.repository }}" = "LizardByte/copr-ci" ]]; then
178188
# not in copr-ci repo, so download the rpmlint.json
179189
ref="master" # default to master branch
180190
curl \
@@ -186,31 +196,29 @@ jobs:
186196
echo "::add-matcher::.github/matchers/rpmlint.json"
187197
188198
# repo specific matchers
189-
if [ -f ".github/matchers/copr-ci.json" ]; then
199+
if [[ -f ".github/matchers/copr-ci.json" ]]; then
190200
echo "Found copr-ci.json matcher, adding it..."
191201
echo "::add-matcher::.github/matchers/copr-ci.json"
192202
fi
193203
194204
- name: Get properties
195-
env:
196-
COPR_PR_WH_TOKEN: ${{ inputs.copr_pr_webhook_token }}
197205
run: |
198206
# package name = repository name
199207
package=${{ github.event.repository.name }}
200-
copr_base="https://copr.fedorainfracloud.org/webhooks/custom-dir/${{ inputs.copr_ownername }}"
208+
copr_base="https://copr.fedorainfracloud.org/webhooks/custom-dir/${INPUTS_COPR_OWNERNAME}"
201209
202210
# release and released type
203-
if [ "${{ github.event_name }}" = "release" ]; then
204-
if [ "${{ github.event.action }}" = "prereleased" ]; then
211+
if [[ "${{ github.event_name }}" = "release" ]]; then
212+
if [[ "${{ github.event.action }}" = "prereleased" ]]; then
205213
BUILD_CHANNEL="beta"
206-
COPR_PUSH_WEBHOOK="${copr_base}/${BUILD_CHANNEL}/${{ secrets.COPR_BETA_WEBHOOK_TOKEN }}/${package}/"
207-
elif [ "${{ github.event.action }}" = "released" ]; then
214+
COPR_PUSH_WEBHOOK="${copr_base}/${BUILD_CHANNEL}/${SECRETS_COPR_BETA_WEBHOOK_TOKEN}/${package}/"
215+
elif [[ "${{ github.event.action }}" = "released" ]]; then
208216
BUILD_CHANNEL="stable"
209-
COPR_PUSH_WEBHOOK="${copr_base}/${BUILD_CHANNEL}/${{ secrets.COPR_STABLE_WEBHOOK_TOKEN }}/${package}/"
217+
COPR_PUSH_WEBHOOK="${copr_base}/${BUILD_CHANNEL}/${SECRETS_COPR_STABLE_WEBHOOK_TOKEN}/${package}/"
210218
fi
211-
elif [ "${{ github.event_name }}" = "pull_request" ]; then
219+
elif [[ "${{ github.event_name }}" = "pull_request" ]]; then
212220
BUILD_CHANNEL="pulls:pr:${{ github.event.number }}"
213-
COPR_PR_WEBHOOK="${copr_base}/${BUILD_CHANNEL}/${{ env.COPR_PR_WH_TOKEN }}/${package}/"
221+
COPR_PR_WEBHOOK="${copr_base}/${BUILD_CHANNEL}/${INPUTS_COPR_PR_WEBHOOK_TOKEN}/${package}/"
214222
fi
215223
216224
{
@@ -243,7 +251,7 @@ jobs:
243251
github.secret_source
244252
run: |
245253
mkdir -p ~/.config
246-
echo "${{ secrets.COPR_CLI_CONFIG }}" > ~/.config/copr
254+
echo "${SECRETS_COPR_CLI_CONFIG}" > ~/.config/copr
247255
248256
copr-cli \
249257
cancel \
@@ -255,7 +263,7 @@ jobs:
255263
steps.build.outcome != 'skipped'
256264
run: |
257265
package=${{ github.event.repository.name }}
258-
base_url="https://download.copr.fedorainfracloud.org/results/${{ inputs.copr_ownername }}/${BUILD_CHANNEL}"
266+
base_url="https://download.copr.fedorainfracloud.org/results/${INPUTS_COPR_OWNERNAME}/${BUILD_CHANNEL}"
259267
260268
# get chroots and prefixed build_id
261269
build_url="https://copr.fedorainfracloud.org/api_3/build/${{ steps.build.outputs.BUILD_ID }}"

0 commit comments

Comments
 (0)