Skip to content

Commit

Permalink
Fix shellcheck failures and remove silly templating
Browse files Browse the repository at this point in the history
  • Loading branch information
sjagoe committed Oct 11, 2024
1 parent dc6564e commit c1c48f1
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 196 deletions.
22 changes: 1 addition & 21 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,9 @@ jobs:
find . -name '*.sh' -exec shellcheck -s bash '{}' \+
find . -name '*.bash' -exec shellcheck -s bash '{}' \+
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.2"
- name: Install kojo
run: gem install kojo
- run: make
- name: Check for changes
run: |
git status
git_changes="$(git status --porcelain || true)"
# If the output is not empty, there are changes; fail the action
if [ -n "$git_changes" ]; then
echo "Changes found; build the action with 'make' and commit the changes"
exit 1
fi
finalize_status:
runs-on: ubuntu-latest
needs: [shellcheck, build, create_status]
needs: [shellcheck, create_status]
if: ${{ always() }}
steps:
- uses: actions/checkout@v4
Expand Down
28 changes: 4 additions & 24 deletions create/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,10 @@ runs:
shell: bash
env:
COMMIT_STATUS_SHA: ${{ inputs.sha }}
PULL_REQUEST_SHA: ${{ github.event.pull_request.head.sha }}
GITHUB_SHA: ${{ GITHUB_SHA }}
run: |
set -eu -o pipefail
if [ -n "$COMMIT_STATUS_SHA" ]; then
SHA="$COMMIT_STATUS_SHA"
elif [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
SHA="${{ github.event.pull_request.head.sha }}"
else
SHA="${{ github.sha }}"
fi
echo sha="$SHA" >> "$GITHUB_OUTPUT"
"${GITHUB_ACTION_PATH}/get-commit-sha.bash"
- name: Create commit status
shell: bash
env:
Expand All @@ -50,16 +42,4 @@ runs:
DESCRIPTION: "Build status is pending"
CONTEXT: ${{ inputs.context }}
run: |
set -eu -o pipefail
declare -a ARGS
if [[ -n "$TARGET_URL" ]]; then
ARGS=("-f" "target_url=${TARGET_URL}")
fi
gh api "/repos/${GITHUB_REPOSITORY}/statuses/${COMMIT_STATUS_SHA}" \
-X POST \
-f state=pending \
-f description="$DESCRIPTION" \
-f context="$CONTEXT" \
"${ARGS[@]}"
"${GITHUB_ACTION_PATH}/"create-commit-status.bash"
43 changes: 0 additions & 43 deletions create/action.yml.erb

This file was deleted.

4 changes: 2 additions & 2 deletions create/get-commit-sha.bash
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ set -eu -o pipefail
if [ -n "$COMMIT_STATUS_SHA" ]; then
SHA="$COMMIT_STATUS_SHA"
elif [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
SHA="${{ github.event.pull_request.head.sha }}"
SHA="$PULL_REQUEST_SHA"
else
SHA="${{ github.sha }}"
SHA="$GITHUB_SHA"
fi
echo sha="$SHA" >> "$GITHUB_OUTPUT"
61 changes: 2 additions & 59 deletions update/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,52 +33,7 @@ runs:
env:
GITHUB_NEEDS: ${{ inputs.github-needs }}
run: |
set -eu -o pipefail
cat > update_commit_status-needs.json <<EOFNEEDS
${GITHUB_NEEDS}
EOFNEEDS
ERROR=error
CANCELLED=cancelled
FAILURE=failure
SUCCESS=success
function countbyStatus() {
local status="$1"
local with_status=
local count=0
with_status="$(jq '. | with_entries(select(.value.result == "'"$status"'"))' <update_commit_status-needs.json)"
echo "$with_status" 1>&2
count="$(echo "$with_status" | jq '. | length')"
echo "$count"
}
function jobsWithStatus() {
local status="$1"
jq -r '. | to_entries | .[] | select(.value.result == "'"$status"'") | .key' <update_commit_status-needs.json | tr $'\n' ' '
}
function jobsStatuses() {
jq -r '. | to_entries | .[] | .key + ": " .value.result' <update_commit_status-needs.json | tr $'\n' '; ' | sed 's/; $//'
}
successes="$(countbyStatus "$SUCCESS")"
failures="$(countbyStatus "$FAILURE")"
cancelled="$(countbyStatus "$CANCELLED")"
if [[ "$cancelled" -gt 0 ]]; then
final_result="$ERROR"
description="Build ended as 'error' with one or more cancelled stages: $(jobsWithStatus "$CANCELLED")"
elif [[ "$failures" -gt 0 ]]; then
final_result="$FAILURE"
description="Build ended as 'failed' with one or more failed stages: $(jobsWithStatus "$FAILURE")"
elif [[ "$successes" -eq 0 ]]; then
final_result="$ERROR"
description="Build encountered unknown error with no successful stages reported. Job statuses are $(jobsStatuses)"
else
final_result="$SUCCESS"
description="Build succeeded"
fi
echo status="$final_result" >> "$GITHUB_OUTPUT"
echo description="$description" >> "$GITHUB_OUTPUT"
"${GITHUB_ACTION_PATH}/get-commit-status.bash"
- name: Update commit status
shell: bash
env:
Expand All @@ -89,16 +44,4 @@ runs:
CONTEXT: ${{ inputs.context }}
STATUS: ${{ steps.commit_status.outputs.status }}
run: |
set -eu -o pipefail
declare -a ARGS
if [[ -n "$TARGET_URL" ]]; then
ARGS=("-f" "target_url=${TARGET_URL}")
fi
gh api "/repos/${GITHUB_REPOSITORY}/statuses/${COMMIT_STATUS_SHA}" \
-XPOST \
-f state="$STATUS" \
-f description="$DESCRIPTION" \
-f context="$CONTEXT" \
"${ARGS[@]}"
"${GITHUB_ACTION_PATH}/update-commit-status.bash"
47 changes: 0 additions & 47 deletions update/action.yml.erb

This file was deleted.

0 comments on commit c1c48f1

Please sign in to comment.