Skip to content

Commit 5ee32e8

Browse files
feat(workflows): add actionlint
1 parent 708c2a4 commit 5ee32e8

2 files changed

Lines changed: 74 additions & 51 deletions

File tree

.github/workflows/__call-common-lint.yml

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,30 @@ jobs:
2424
- name: Checkout
2525
uses: actions/checkout@v4
2626

27+
- name: Download problem matchers
28+
shell: bash
29+
working-directory: .github
30+
run: |
31+
declare -A files=(
32+
[actionlint]="https://raw.githubusercontent.com/rhysd/actionlint/main/.github/actionlint-matcher.json"
33+
)
34+
35+
# TODO: add more problem matchers
36+
# clang-format: # https://github.com/jidicula/clang-format-action/issues/137#issuecomment-3043722359
37+
38+
for name in "${!files[@]}"; do
39+
url="${files[$name]}"
40+
curl -sSL "$url" -o "${name}.json"
41+
done
42+
2743
- name: Set up Python
2844
uses: actions/setup-python@v5
2945
with:
3046
python-version: '3.12'
3147

32-
- name: Install dependencies
48+
- name: Install Python dependencies
3349
run: |
50+
# shellcheck disable=SC2102 # this is triggered by the [toolchain] extra
3451
python -m pip install --upgrade \
3552
pip \
3653
setuptools \
@@ -40,6 +57,17 @@ jobs:
4057
nb-clean \
4158
nbqa[toolchain]
4259
60+
- name: Install actionlint
61+
id: get_actionlint
62+
shell: bash
63+
run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)
64+
65+
- name: actionlint
66+
shell: bash
67+
run: |
68+
echo "::add-matcher::.github/actionlint.json"
69+
${{ steps.get_actionlint.outputs.executable }} -color
70+
4371
- name: C++ - find files
4472
id: cpp_files
4573
run: |
@@ -72,8 +100,8 @@ jobs:
72100
73101
echo "found cpp files: ${found_files}"
74102
75-
# do not quote to keep this as a single line
76-
echo found_files=${found_files} >> $GITHUB_OUTPUT
103+
# shellcheck disable=SC2086 # do not quote to keep this as a single line
104+
echo found_files=${found_files} >> "${GITHUB_OUTPUT}"
77105
78106
- name: C++ - Clang format lint
79107
if: always() && steps.cpp_files.outputs.found_files
@@ -111,8 +139,8 @@ jobs:
111139
112140
echo "found cmake files: ${found_files}"
113141
114-
# do not quote to keep this as a single line
115-
echo found_files=${found_files} >> $GITHUB_OUTPUT
142+
# shellcheck disable=SC2086 # do not quote to keep this as a single line
143+
echo found_files=${found_files} >> "${GITHUB_OUTPUT}"
116144
117145
- name: CMake - cmake-lint
118146
if: always() && steps.cmake_files.outputs.found_files
@@ -127,8 +155,8 @@ jobs:
127155
128156
echo "found_files: ${found_files}"
129157
130-
# do not quote to keep this as a single line
131-
echo found_files=${found_files} >> $GITHUB_OUTPUT
158+
# shellcheck disable=SC2086 # do not quote to keep this as a single line
159+
echo found_files=${found_files} >> "${GITHUB_OUTPUT}"
132160
133161
- name: Docker - hadolint
134162
if: always() && steps.docker_files.outputs.found_files
@@ -155,7 +183,7 @@ jobs:
155183
docker run --rm -i \
156184
-e "NO_COLOR=0" \
157185
-e "HADOLINT_VERBOSE=1" \
158-
-v $(pwd)/.hadolint.yaml:/.config/hadolint.yaml \
186+
-v "$(pwd)"/.hadolint.yaml:/.config/hadolint.yaml \
159187
hadolint/hadolint < $file || {
160188
failed=1
161189
failed_files="$failed_files $file"
@@ -239,15 +267,14 @@ jobs:
239267
run: |
240268
# check if Cargo.toml exists
241269
if [ -f "Cargo.toml" ]; then
242-
echo "found_cargo=true" >> $GITHUB_OUTPUT
270+
echo "found_cargo=true" >> "${GITHUB_OUTPUT}"
243271
else
244-
echo "found_cargo=false" >> $GITHUB_OUTPUT
272+
echo "found_cargo=false" >> "${GITHUB_OUTPUT}"
245273
fi
246274
247275
- name: Setup Rust
248276
uses: actions-rust-lang/setup-rust-toolchain@v1.13.0
249277
with:
250-
target: ${{ matrix.target }}
251278
components: 'rustfmt'
252279
cache: false
253280

@@ -272,7 +299,7 @@ jobs:
272299
fi
273300
done
274301
275-
echo "found_files=${found_files}" >> $GITHUB_OUTPUT
302+
echo "found_files=${found_files}" >> "${GITHUB_OUTPUT}"
276303
277304
- name: YAML - yamllint
278305
id: yamllint
@@ -303,4 +330,4 @@ jobs:
303330

304331
- name: YAML - log
305332
if: always() && steps.yamllint.outcome == 'failure'
306-
run: cat "${{ steps.yamllint.outputs.logfile }}" >> $GITHUB_STEP_SUMMARY
333+
run: cat "${{ steps.yamllint.outputs.logfile }}" >> "${GITHUB_STEP_SUMMARY}"

.github/workflows/__call-docker.yml

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -79,39 +79,40 @@ jobs:
7979
8080
echo "found dockerfiles: ${dockerfiles}"
8181
82-
# do not quote to keep this as a single line
83-
echo dockerfiles=${dockerfiles} >> $GITHUB_OUTPUT
82+
# shellcheck disable=SC2086 # do not quote to keep this as a single line
83+
echo dockerfiles=${dockerfiles} >> "${GITHUB_OUTPUT}"
8484
8585
MATRIX_COMBINATIONS=""
8686
for FILE in ${dockerfiles}; do
8787
# extract tag from file name
88-
tag=$(echo $FILE | sed -r -z -e 's/(\.\/)*.*\/(Dockerfile)/None/gm')
89-
if [[ $tag == "None" ]]; then
90-
MATRIX_COMBINATIONS="$MATRIX_COMBINATIONS {\"dockerfile\": \"$FILE\"},"
88+
tag=$(echo "${FILE}" | sed -r -z -e 's/(\.\/)*.*\/(Dockerfile)/None/gm')
89+
if [[ "${tag}" == "None" ]]; then
90+
MATRIX_COMBINATIONS="${MATRIX_COMBINATIONS} {\"dockerfile\": \"${FILE}\"},"
9191
else
9292
tag=$(echo $FILE | sed -r -z -e 's/(\.\/)*.*\/(.+)(\.dockerfile)/-\2/gm')
93-
MATRIX_COMBINATIONS="$MATRIX_COMBINATIONS {\"dockerfile\": \"$FILE\", \"tag\": \"$tag\"},"
93+
MATRIX_COMBINATIONS="${MATRIX_COMBINATIONS} {\"dockerfile\": \"${FILE}\", \"tag\": \"${tag}\"},"
9494
fi
9595
done
9696
9797
# removes the last character (i.e. comma)
9898
MATRIX_COMBINATIONS=${MATRIX_COMBINATIONS::-1}
9999
100100
# setup matrix for later jobs
101-
matrix=$((
102-
echo "{ \"include\": [$MATRIX_COMBINATIONS] }"
101+
matrix=$( (
102+
echo "{ \"include\": [${MATRIX_COMBINATIONS}] }"
103103
) | jq -c .)
104104
105-
echo $matrix
106-
echo $matrix | jq .
107-
echo "matrix=$matrix" >> $GITHUB_OUTPUT
105+
echo "${matrix}"
106+
echo "${matrix}" | jq .
107+
echo "matrix=${matrix}" >> "${GITHUB_OUTPUT}"
108+
108109
- name: Additional Outputs
109110
id: additional_outputs
110111
run: |
111112
# set outputs for later jobs
112-
REPOSITORY=${{ github.repository }}
113-
BASE_TAG=$(echo $REPOSITORY | tr '[:upper:]' '[:lower:]')
114-
echo "base_tag=${BASE_TAG}" >> $GITHUB_OUTPUT
113+
REPOSITORY="${{ github.repository }}"
114+
BASE_TAG=$(echo ${REPOSITORY} | tr '[:upper:]' '[:lower:]')
115+
echo "base_tag=${BASE_TAG}" >> "${GITHUB_OUTPUT}"
115116
116117
outputs:
117118
base_tag: ${{ steps.additional_outputs.outputs.base_tag }}
@@ -155,45 +156,38 @@ jobs:
155156
# get branch name
156157
BRANCH=${GITHUB_HEAD_REF}
157158
158-
RELEASE=${{ inputs.publish_release }}
159-
COMMIT=${{ inputs.release_commit }}
159+
RELEASE="${{ inputs.publish_release }}"
160+
COMMIT="${{ inputs.release_commit }}"
160161
161-
if [ -z "$BRANCH" ]; then
162+
if [ -z "${BRANCH}" ]; then
162163
echo "This is a PUSH event"
163-
BRANCH=${{ github.ref_name }}
164-
CLONE_URL=${{ github.event.repository.clone_url }}
164+
BRANCH="${{ github.ref_name }}"
165+
CLONE_URL="${{ github.event.repository.clone_url }}"
165166
else
166167
echo "This is a PULL REQUEST event"
167-
CLONE_URL=${{ github.event.pull_request.head.repo.clone_url }}
168-
fi
169-
170-
# determine to push image to dockerhub and ghcr or not
171-
if [[ $GITHUB_EVENT_NAME == "push" ]]; then
172-
PUSH=true
173-
else
174-
PUSH=false
168+
CLONE_URL="${{ github.event.pull_request.head.repo.clone_url }}"
175169
fi
176170
177171
# setup the tags
178172
BASE_TAG="${{ needs.check_dockerfiles.outputs.base_tag }}"
179173
180174
TAGS="${BASE_TAG}:${COMMIT:0:7}${{ matrix.tag }},ghcr.io/${BASE_TAG}:${COMMIT:0:7}${{ matrix.tag }}"
181175
182-
if [[ $GITHUB_REF == refs/heads/master ]]; then
176+
if [[ "${GITHUB_REF}" == refs/heads/master ]]; then
183177
TAGS="${TAGS},${BASE_TAG}:latest${{ matrix.tag }},ghcr.io/${BASE_TAG}:latest${{ matrix.tag }}"
184178
TAGS="${TAGS},${BASE_TAG}:master${{ matrix.tag }},ghcr.io/${BASE_TAG}:master${{ matrix.tag }}"
185179
else
186180
TAGS="${TAGS},${BASE_TAG}:test${{ matrix.tag }},ghcr.io/${BASE_TAG}:test${{ matrix.tag }}"
187181
fi
188182
189-
if [[ ${NV} != "" ]]; then
183+
if [[ "${NV}" != "" ]]; then
190184
TAGS="${TAGS},${BASE_TAG}:${NV}${{ matrix.tag }},ghcr.io/${BASE_TAG}:${NV}${{ matrix.tag }}"
191185
fi
192186
193187
# parse custom directives out of dockerfile
194188
# try to get the platforms from the dockerfile custom directive, i.e. `# platforms: xxx,yyy`
195189
# directives for PR event, i.e. not push event
196-
if [[ ${RELEASE} == "false" ]]; then
190+
if [[ "${RELEASE}" == "false" ]]; then
197191
while read -r line; do
198192
if [[ $line == "# platforms_pr: "* && $PLATFORMS == "" ]]; then
199193
# echo the line and use `sed` to remove the custom directive
@@ -230,13 +224,15 @@ jobs:
230224
PLATFORMS="linux/amd64"
231225
fi
232226
233-
echo "branch=${BRANCH}" >> $GITHUB_OUTPUT
234-
echo "build_date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
235-
echo "clone_url=${CLONE_URL}" >> $GITHUB_OUTPUT
236-
echo "artifacts=${ARTIFACTS}" >> $GITHUB_OUTPUT
237-
echo "no_cache_filters=${NO_CACHE_FILTERS}" >> $GITHUB_OUTPUT
238-
echo "platforms=${PLATFORMS}" >> $GITHUB_OUTPUT
239-
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
227+
{
228+
echo "branch=${BRANCH}";
229+
echo "build_date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')";
230+
echo "clone_url=${CLONE_URL}";
231+
echo "artifacts=${ARTIFACTS}";
232+
echo "no_cache_filters=${NO_CACHE_FILTERS}";
233+
echo "platforms=${PLATFORMS}";
234+
echo "tags=${TAGS}";
235+
} >> "${GITHUB_OUTPUT}"
240236
241237
- name: Set Up QEMU
242238
uses: docker/setup-qemu-action@v3
@@ -305,7 +301,7 @@ jobs:
305301
-maxdepth 3 \
306302
-type d \
307303
-name 'artifacts' \
308-
-exec bash -c 'cp -rv {}/* ./artifacts/' \;
304+
-exec bash -c 'cp -rv "$1"/* ./artifacts/' _ {} \;
309305
echo "::endgroup::"
310306
311307
echo "::group::Artifacts"

0 commit comments

Comments
 (0)