Skip to content

Commit da65a79

Browse files
authored
Enforce GHA workflow auditing/linting (#554)
Signed-off-by: Caleb Xu <[email protected]>
1 parent 8c1ce71 commit da65a79

File tree

10 files changed

+89
-19
lines changed

10 files changed

+89
-19
lines changed

.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ updates:
44
directory: "/"
55
schedule:
66
interval: "weekly"
7+
cooldown:
8+
default-days: 4
79
ignore:
810
# Automatic updates for these are disabled as they are updated manually to
911
# align with platform dependencies defined at
@@ -15,6 +17,8 @@ updates:
1517
directory: "/.github"
1618
schedule:
1719
interval: "weekly"
20+
cooldown:
21+
default-days: 4
1822
groups:
1923
actions:
2024
applies-to: "version-updates"
@@ -29,3 +33,5 @@ updates:
2933
directory: "/scripts"
3034
schedule:
3135
interval: "monthly"
36+
cooldown:
37+
default-days: 4

.github/workflows/build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
run: |
3232
# Run go tests
3333
make test
34-
if [[ ! -z $(git status -s) ]]
34+
if [[ -n $(git status -s) ]]
3535
then
3636
echo "go test - errors running go tests : $(git status -s)"
3737
exit 1
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Analyze GitHub Actions security
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '.github/**'
7+
8+
permissions: {}
9+
10+
jobs:
11+
check-actions:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
16+
with:
17+
persist-credentials: false
18+
19+
- name: Setup Go
20+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
21+
with:
22+
go-version-file: go.mod
23+
24+
- name: Run Linters
25+
run: make gha.lint

.github/workflows/functional-tests.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ jobs:
8686
- name: Get Date
8787
id: get-date
8888
run: |
89-
echo "date=$(/bin/date -u "+%Y%m%d")" | tee -a $GITHUB_OUTPUT
89+
echo "date=$(/bin/date -u "+%Y%m%d")" | tee -a "${GITHUB_OUTPUT}"
9090
shell: bash
9191

9292
- uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
@@ -114,7 +114,7 @@ jobs:
114114
echo "Building container image using podman for the tests, tagging as ${image_tag}"
115115
make build-image "IMAGE_TAG=${image_tag}"
116116
podman build -t "quay.io/redhat-certification/chart-verifier:${image_tag}" .
117-
echo "podman_image_tag=${image_tag}" | tee -a $GITHUB_OUTPUT
117+
echo "podman_image_tag=${image_tag}" | tee -a "${GITHUB_OUTPUT}"
118118
119119
- name: Create tarfile
120120
id: create-tarfile
@@ -130,10 +130,10 @@ jobs:
130130
CLUSTER_TOKEN: ${{ secrets.cluster-token }}
131131
run: |
132132
# oc login
133-
API_SERVER=$( echo -n "${CLUSTER_API_SERVER}" | base64 -d)
133+
API_SERVER="$( echo -n "${CLUSTER_API_SERVER}" | base64 -d)"
134134
gpg --version
135135
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
136-
if [ $GITHUB_REPOSITORY == "redhat-certification/chart-verifier" ]; then
136+
if [ "${GITHUB_REPOSITORY}" == "redhat-certification/chart-verifier" ]; then
137137
# TODO: temporarily allow for skipping TLS verification as the new cluster uses local-only certificates
138138
# This if logic isn't removed to remind us to come back and swap this out when a valid cert is put in place.
139139
oc login --insecure-skip-tls-verify --token="${CLUSTER_TOKEN}" --server="${API_SERVER}"

.github/workflows/gosec.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ jobs:
2323
- name: Security scan
2424
shell: bash
2525
run: |
26-
make gosec
27-
if [[ $? != 0 ]]
26+
if ! make gosec
2827
then
2928
echo "gosec scanner failed to run "
3029
exit 1

.github/workflows/main.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ jobs:
2727
id: get_commit_id
2828
run: |
2929
# Make the short commit ID available to the following steps.
30-
COMMIT_ID=$(git rev-parse --short HEAD)
31-
echo "commit_id=$COMMIT_ID" | tee -a $GITHUB_OUTPUT
30+
COMMIT_ID="$(git rev-parse --short HEAD)"
31+
echo "commit_id=$COMMIT_ID" | tee -a "${GITHUB_OUTPUT}"
3232
3333
- name: Build container images
3434
id: build_container_images

.github/workflows/notify-need-ok-to-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Notify ok-to-test required
22

33
on:
4-
pull_request_target:
4+
pull_request_target: # zizmor: ignore[dangerous-triggers] # pull_request_target is needed to be able to comment on the pull request.
55
branches: [main]
66
types:
77
- opened

.github/workflows/pr-functional-tests.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ name: Pull request functional testing
88
# This workflow also handles removing said label on content changes.
99

1010
on:
11-
pull_request_target:
11+
pull_request_target: # zizmor: ignore[dangerous-triggers] # pull_request_target is needed to be able to modify labels on the pull request and to access repository secrets.
1212
branches: [main]
1313
types:
1414
- opened
@@ -189,8 +189,9 @@ jobs:
189189
if: ${{ steps.check_version_updated.outputs.updated == 'true'}}
190190
run: |
191191
git fetch
192-
export ORIGIN_MAIN_SHA=$(git rev-parse origin/main)
193-
echo "origin_main_sha=$ORIGIN_MAIN_SHA" | tee -a $GITHUB_OUTPUT
192+
ORIGIN_MAIN_SHA="$(git rev-parse origin/main)"
193+
export ORIGIN_MAIN_SHA
194+
echo "origin_main_sha=$ORIGIN_MAIN_SHA" | tee -a "${GITHUB_OUTPUT}"
194195
195196
- name: Create release tag
196197
id: create_release_tag

.github/workflows/release.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
- name: Print tag to GITHUB_OUTPUT
6060
id: get_tag
6161
run: |
62-
echo "release_version=${GITHUB_REF#refs/*/}" | tee -a $GITHUB_OUTPUT
62+
echo "release_version=${GITHUB_REF#refs/*/}" | tee -a "${GITHUB_OUTPUT}"
6363
6464
- name: Build binary and make tarball
6565
id: build_bin
@@ -69,8 +69,9 @@ jobs:
6969
make bin
7070
TARBALL_NAME="chart-verifier-${RELEASE_VERSION}.tgz"
7171
tar -zcvf "$TARBALL_NAME" -C out/ chart-verifier
72-
export TARBALL_PATH=$(realpath "$TARBALL_NAME")
73-
echo "tarball_path=$TARBALL_PATH" | tee -a $GITHUB_OUTPUT
72+
TARBALL_PATH="$(realpath "$TARBALL_NAME")"
73+
export TARBALL_PATH
74+
echo "tarball_path=$TARBALL_PATH" | tee -a "${GITHUB_OUTPUT}"
7475
7576
- name: Check that the tag matches the current version
7677
id: check_tag_and_version
@@ -87,7 +88,7 @@ jobs:
8788
env:
8889
REPOSITORY_NAME: ${{ github.event.repository.name }}
8990
RELEASE_VERSION: ${{ steps.get_tag.outputs.release_version }}
90-
run: echo sbom_filename="${REPOSITORY_NAME}-${RELEASE_VERSION}-sbom.spdx.json" | tee -a $GITHUB_OUTPUT
91+
run: echo sbom_filename="${REPOSITORY_NAME}-${RELEASE_VERSION}-sbom.spdx.json" | tee -a "${GITHUB_OUTPUT}"
9192

9293
- name: Generate SBOM
9394
continue-on-error: true
@@ -115,7 +116,7 @@ jobs:
115116
116117
- name: Generate release body
117118
id: release_body
118-
run: echo "release_body=$(ve1/bin/print-release-body)" | tee -a $GITHUB_OUTPUT
119+
run: echo "release_body=$(ve1/bin/print-release-body)" | tee -a "${GITHUB_OUTPUT}"
119120

120121
- name: Create tag and release
121122
env:

Makefile

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ venv.tools.always-reinstall:
144144
./$(VENV_TOOLS_BIN)/pip install ./scripts
145145
cd ..
146146

147+
gha.lint: actionlint zizmor
148+
149+
actionlint: install.actionlint
150+
$(ACTIONLINT)
151+
152+
zizmor: install.zizmor
153+
$(ZIZMOR) .
147154

148155
### Developer Tooling Installation
149156
# gosec
@@ -163,12 +170,43 @@ GOLANGCI_LINT = $(shell pwd)/out/golangci-lint
163170
GOLANGCI_LINT_VERSION ?= v2.2.1
164171
install.golangci-lint: $(GOLANGCI_LINT)
165172
$(GOLANGCI_LINT):
166-
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION))\
173+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION))
174+
175+
# actionlint
176+
ACTIONLINT = $(shell pwd)/out/actionlint
177+
ACTIONLINT_VERSION ?= v1.7.0
178+
install.actionlint: $(ACTIONLINT)
179+
$(ACTIONLINT):
180+
$(call go-install-tool,$(ACTIONLINT),github.com/rhysd/actionlint/cmd/actionlint@$(ACTIONLINT_VERSION))
181+
182+
# zizmor
183+
ZIZMOR = $(shell pwd)/out/zizmor
184+
ZIZMOR_VERSION ?= v1.17.0
185+
ZIZMOR_ARCH = $(shell uname -m | sed 's/amd64/x86_64/g; s/arm64/aarch64/g')
186+
ZIZMOR_OS = $(shell uname -s | sed 's/Linux/unknown-linux-gnu/g; s/Darwin/apple-darwin/g')
187+
ZIZMOR_PLATFORM ?= $(ZIZMOR_ARCH)-$(ZIZMOR_OS)
188+
install.zizmor: $(ZIZMOR)
189+
$(ZIZMOR):
190+
$(call github-release-install-tool,$(shell pwd)/out/zizmor.tar.gz,zizmorcore/zizmor,$(ZIZMOR_VERSION),zizmor-$(ZIZMOR_PLATFORM).tar.gz)
191+
tar -xzf $(shell pwd)/out/zizmor.tar.gz -C $(shell pwd)/out ./zizmor
192+
rm $(shell pwd)/out/zizmor.tar.gz
167193

168194
# go-install-tool will 'go install' any package $2 and install it to $1.
169195
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
170196
define go-install-tool
171197
@[ -f $(1) ] || { \
172198
GOBIN=$(PROJECT_DIR)/out go install $(2) ;\
173199
}
200+
endef
201+
202+
# github-release-install-tool
203+
# Arguments:
204+
# $1 - destination path
205+
# $2 - GitHub repository
206+
# $3 - release version
207+
# $4 - artifact name
208+
define github-release-install-tool
209+
@[ -f $(1) ] || { \
210+
curl -L https://github.com/$(2)/releases/download/$(3)/$(4) -o $(1) ;\
211+
}
174212
endef

0 commit comments

Comments
 (0)