Skip to content

Commit

Permalink
style: apply fixes suggested by linter
Browse files Browse the repository at this point in the history
  • Loading branch information
jnsgruk committed Dec 5, 2023
1 parent 799843a commit 7e1ff68
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 35 deletions.
4 changes: 1 addition & 3 deletions .github/shellcheck-actions.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env bash
set -euo pipefail
info() { echo -e "\e[92m[+] $@\e[0m"; }
error() { echo >&2 -e "\e[31m[!] $@\e[0m"; exit 1; }
warn() { echo -e "\e[33m[-] $@\e[0m"; }
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )

export SHELLCHECK_OPTS=(
Expand All @@ -14,6 +12,6 @@ export SHELLCHECK_OPTS=(
)

for f in "$DIR"/../**/*.yaml; do
echo $f
info "Linting scripts in $f"
yq '.runs.steps[].run' "$f" | grep -v -P "^null$" | shellcheck "${SHELLCHECK_OPTS[@]}" -
done
13 changes: 7 additions & 6 deletions call-for-testing/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ runs:
fi
done
fi
if [[ ! -n "${yaml-path}" ]]; then
echo "No snapcraft.yaml found" >2
if [[ -z "${yaml_path}" ]]; then
echo "No snapcraft.yaml found"
exit 1
fi
echo "yaml-path=${yaml_path}" >> "$GITHUB_OUTPUT"
Expand All @@ -94,10 +94,10 @@ runs:
echo "Found build manifests - populating template with revisions from the manifests"
# Iterate over the manifest files and write the table rows for each architecture
for file in $(ls manifest-*.yaml); do
for file in manifest-*.yaml; do
# Parse the arch and the revision
arch="$(cat "${file}" | yq -r '.architecture')"
rev="$(cat "${file}" | yq -r '.revision')"
arch="$(yq -r '.architecture' "${file}")"
rev="$(yq -r '.revision' "${file}")"
# Write the table row and add the revision to the list we're tracking
table="${table}<tr><td>${arch}</td><td>${rev}</td></tr>"
revisions+=("$rev")
Expand All @@ -106,6 +106,7 @@ runs:
echo "No build manifests found - populating template with information from the store"
# Otherwise, get the latest revision for each architecture in the release channel
# shellcheck disable=SC1083
for arch in ${{ inputs.architectures }}; do
rev="$(snapcraft list-revisions "${snap_name}" --arch "$arch" | grep "latest/${{ inputs.channel }}*" | head -n1 | cut -d' ' -f1)"
revisions+=("$rev")
Expand All @@ -120,7 +121,7 @@ runs:
# Get a comma separated list of revisions
printf -v joined '%s,' "${revisions[@]}"
version="$(cat "$snapcraft_yaml" | yq -r '.version')"
version="$(yq -r '.version' "$snapcraft_yaml")"
echo "version=${version}" >> "$GITHUB_OUTPUT"
echo "revisions=${joined%,}" >> "$GITHUB_OUTPUT"
echo "table=${table}" >> "$GITHUB_OUTPUT"
Expand Down
12 changes: 6 additions & 6 deletions get-architectures/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ runs:
fi
done
fi
if [[ ! -n "${yaml-path}" ]]; then
echo "No snapcraft.yaml found" >2
if [[ -z "${yaml_path}" ]]; then
echo "No snapcraft.yaml found"
exit 1
fi
echo "yaml-path=${yaml_path}" >> "$GITHUB_OUTPUT"
Expand All @@ -58,15 +58,15 @@ runs:
yaml_path: ${{ steps.yaml-path.outputs.yaml-path }}
run: |
# Get the list as a json array. E.g. ["amd64", "arm64"]
architectures_list="$(cat "$yaml_path" | yq -r -I=0 -o=json '[.architectures[]]')"
architectures_list="$(yq -r -I=0 -o=json '[.architectures[]]' | "$yaml_path")"
# Get the list as a space-separated string. E.g. "amd64" "arm64"
architectures="$(cat "$yaml_path" | yq -r -I=0 -o=csv '[.architectures[]]' | tr ',' ' ')"
architectures="$(yq -r -I=0 -o=csv '[.architectures[]]' "$yaml_path" | tr ',' ' ')"
# Handle the case where architectures is a list of objects
if echo "$architectures" | grep -q "build-on"; then
architectures_list="$(cat "$yaml_path" | yq -r -I=0 -o=json '[.architectures[]."build-on"]')"
architectures="$(cat "$yaml_path" | yq -r -I=0 -o=csv '[.architectures[]."build-on"]' | tr ',' ' ')"
architectures_list="$(yq -r -I=0 -o=json '[.architectures[]."build-on"]' "$yaml_path")"
architectures="$(yq -r -I=0 -o=csv '[.architectures[]."build-on"]' "$yaml_path" | tr ',' ' ')"
fi
echo "architectures_list=$architectures_list" >> "$GITHUB_OUTPUT"
Expand Down
8 changes: 4 additions & 4 deletions get-screenshots/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ runs:
fi
done
fi
if [[ ! -n "${yaml-path}" ]]; then
echo "No snapcraft.yaml found" >2
if [[ -z "${yaml_path}" ]]; then
echo "No snapcraft.yaml found"
exit 1
fi
echo "yaml-path=${yaml_path}" >> "$GITHUB_OUTPUT"
Expand All @@ -90,7 +90,7 @@ runs:
# If we got a manifest file then parse the revision from it
if ls manifest-amd64.yaml &>/dev/null; then
rev="$(cat manifest-amd64.yaml | yq -r '.revision')"
rev="$(yq -r '.revision' manifest-amd64.yaml)"
echo "Installing snap revision '${rev}' from build manifest"
ghvmctl install-snap "${snap_name}" --revision "${rev}"
else
Expand Down Expand Up @@ -129,7 +129,7 @@ runs:
run: |
file_prefix="$(date +%Y%m%d)-${snap_name}-${{ inputs.issue-number }}"
pushd ci-screenshots
pushd ci-screenshots || exit 1
mv "$HOME/ghvmctl-screenshots/screenshot-screen.png" "${file_prefix}-screen.png"
mv "$HOME/ghvmctl-screenshots/screenshot-window.png" "${file_prefix}-window.png"
Expand Down
15 changes: 8 additions & 7 deletions promote-to-stable/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ runs:
fi
done
fi
if [[ ! -n "${yaml-path}" ]]; then
echo "No snapcraft.yaml found" >2
if [[ -z "${yaml_path}" ]]; then
echo "No snapcraft.yaml found"
exit 1
fi
echo "yaml-path=${yaml_path}" >> "$GITHUB_OUTPUT"
Expand All @@ -71,6 +71,7 @@ runs:
run: |
echo "The command was '${{ steps.command.outputs.command-name }}' with arguments '${{ steps.command.outputs.command-arguments }}'"
# shellcheck disable=SC1083,SC2206
arguments=(${{ steps.command.outputs.command-arguments }})
revision=${arguments[0]}
channel=${arguments[1]}
Expand All @@ -93,20 +94,20 @@ runs:
fi
# Iterate over each specified revision and release
revs=$(echo $revision | tr "," "\n")
revs=$(echo "$revision" | tr "," "\n")
released_revs=()
for r in $revs; do
snapcraft release $snap_name "$r" "$channel"
snapcraft release "$snap_name" "$r" "$channel"
released_revs+=("$r")
done
# Get a comma separated list of released revisions
printf -v joined '%s,' "${released_revs[@]}"
echo "revisions=${joined%,}" >> $GITHUB_OUTPUT
echo "channel=$channel" >> $GITHUB_OUTPUT
echo "done=$done" >> $GITHUB_OUTPUT
echo "revisions=${joined%,}" >> "$GITHUB_OUTPUT"
echo "channel=$channel" >> "$GITHUB_OUTPUT"
echo "done=$done" >> "$GITHUB_OUTPUT"
- name: Comment on call for testing issue
uses: actions/github-script@v7
Expand Down
4 changes: 2 additions & 2 deletions release-to-candidate/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ runs:
fi
done
fi
if [[ ! -n "${yaml_path}" ]]; then
echo "No snapcraft.yaml found" >2
if [[ -z "${yaml_path}" ]]; then
echo "No snapcraft.yaml found"
exit 1
fi
echo "yaml-path=${yaml_path}" >> "$GITHUB_OUTPUT"
Expand Down
9 changes: 5 additions & 4 deletions sync-version/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ runs:
fi
done
fi
if [[ ! -n "${yaml-path}" ]]; then
echo "No snapcraft.yaml found" >2
if [[ -z "${yaml_path}" ]]; then
echo "No snapcraft.yaml found"
exit 1
fi
echo "yaml-path=${yaml_path}" >> "$GITHUB_OUTPUT"
Expand All @@ -55,14 +55,15 @@ runs:
- name: Run update script
shell: bash
run: |
# shellcheck disable=SC2288,SC2086,SC1083
${{ inputs.update-script }}
- name: Check for modified files
shell: bash
id: git-check
run: |
MODIFIED=$([ -z "`git status --porcelain`" ] && echo "false" || echo "true")
echo "modified=$MODIFIED" >> $GITHUB_OUTPUT
MODIFIED=$([ -z "$(git status --porcelain)" ] && echo "false" || echo "true")
echo "modified=$MODIFIED" >> "$GITHUB_OUTPUT"
- name: Commit changes
if: steps.git-check.outputs.modified == 'true'
Expand Down
6 changes: 3 additions & 3 deletions test-snap-build/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ runs:
fi
done
fi
if [[ ! -n "${yaml_path}" ]]; then
echo "No snapcraft.yaml found" >2
if [[ -z "${yaml_path}" ]]; then
echo "No snapcraft.yaml found"
exit 1
fi
echo "yaml-path=${yaml_path}" >> "$GITHUB_OUTPUT"
Expand Down Expand Up @@ -94,4 +94,4 @@ runs:
if: ${{ inputs.install == 'true' }}
shell: bash
run: |
sudo snap install --classic --dangerous ${{ steps.build.outputs.snap }}
sudo snap install --classic --dangerous "${{ steps.build.outputs.snap }}"

0 comments on commit 7e1ff68

Please sign in to comment.