diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c59acee..07650b3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,7 +21,7 @@ jobs: shellcheck: # Use newer os for more up-to-date shellcheck - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Run shellcheck on .sh and .bash files files @@ -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: "2.7" - - 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 diff --git a/create/action.yml b/create/action.yml index 2beca52..4d3af3c 100644 --- a/create/action.yml +++ b/create/action.yml @@ -11,6 +11,10 @@ inputs: target-url: description: "URL to include in the status" default: "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" + sha: + description: "Commit sha to attach the status to if it's different from the workflow run commit" + required: false + default: "" outputs: commit_status_sha: @@ -23,16 +27,12 @@ runs: - name: Determine commit to put the build status on id: commit_status_sha 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 [[ "$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: @@ -42,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" diff --git a/create/action.yml.erb b/create/action.yml.erb deleted file mode 100644 index be7fb75..0000000 --- a/create/action.yml.erb +++ /dev/null @@ -1,37 +0,0 @@ -name: 'Create pending github commit statuses' -description: Create a github commit status context in the pending state - -inputs: - github-token: - description: "Github authentication token" - required: true - context: - description: "Github status context" - default: continuous-integration/github-actions/status - target-url: - description: "URL to include in the status" - default: "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" - -outputs: - commit_status_sha: - description: "The commit sha that the status is attached to" - value: ${{ steps.commit_status_sha.outputs.sha }} - -runs: - using: "composite" - steps: - - name: Determine commit to put the build status on - id: commit_status_sha - shell: bash - run: | - @import ../script-import-helper (script_name: "get-commit-sha.bash") - - name: Create commit status - shell: bash - env: - GITHUB_TOKEN: ${{ inputs.github-token }} - TARGET_URL: ${{ inputs.target-url }} - COMMIT_STATUS_SHA: ${{ steps.commit_status_sha.outputs.sha }} - DESCRIPTION: "Build status is pending" - CONTEXT: ${{ inputs.context }} - run: | - @import ../script-import-helper (script_name: "create-commit-status.bash") diff --git a/create/create-commit-status.bash b/create/create-commit-status.bash old mode 100644 new mode 100755 index 28145ac..420a57e --- a/create/create-commit-status.bash +++ b/create/create-commit-status.bash @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + set -eu -o pipefail declare -a ARGS diff --git a/create/get-commit-sha.bash b/create/get-commit-sha.bash old mode 100644 new mode 100755 index c0ed538..ce0bf52 --- a/create/get-commit-sha.bash +++ b/create/get-commit-sha.bash @@ -1,8 +1,12 @@ +#!/usr/bin/env bash + set -eu -o pipefail -if [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then - SHA="${{ github.event.pull_request.head.sha }}" +if [ -n "$COMMIT_STATUS_SHA" ]; then + SHA="$COMMIT_STATUS_SHA" +elif [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then + SHA="$PULL_REQUEST_SHA" else - SHA="${{ github.sha }}" + SHA="$GITHUB_SHA" fi echo sha="$SHA" >> "$GITHUB_OUTPUT" diff --git a/update/action.yml b/update/action.yml index 4449dbb..11dc7e4 100644 --- a/update/action.yml +++ b/update/action.yml @@ -33,52 +33,7 @@ runs: env: GITHUB_NEEDS: ${{ inputs.github-needs }} run: | - set -eu -o pipefail - - cat > update_commit_status-needs.json <&2 - count="$(echo "$with_status" | jq '. | length')" - echo "$count" - } - function jobsWithStatus() { - local status="$1" - jq -r '. | to_entries | .[] | select(.value.result == "'"$status"'") | .key' > "$GITHUB_OUTPUT" - echo description="$description" >> "$GITHUB_OUTPUT" - + "${GITHUB_ACTION_PATH}/get-commit-status.bash" - name: Update commit status shell: bash env: @@ -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" diff --git a/update/action.yml.erb b/update/action.yml.erb deleted file mode 100644 index a150bb5..0000000 --- a/update/action.yml.erb +++ /dev/null @@ -1,47 +0,0 @@ -name: 'Create pending github commit statuses' -description: Update a pending commit status context with the final result - -inputs: - github-token: - description: "Github authentication token" - required: true - github-needs: - description: >- - "needs" object from github actions as JSON format. - - MUST be passed as the github templated toJson(needs) - required: true - context: - description: "Github status context" - default: continuous-integration/github-actions/status - target-url: - description: "URL to include in the status" - default: "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" - sha: - description: >- - The git commit sha to attach the status to. This should be - provided from the `commit_status_sha` output of the create - action from this same repository. - required: true - -runs: - using: "composite" - steps: - - name: Get final commit status - id: commit_status - shell: bash - env: - GITHUB_NEEDS: ${{ inputs.github-needs }} - run: | - @import ../script-import-helper (script_name: "get-commit-status.bash") - - name: Update commit status - shell: bash - env: - GITHUB_TOKEN: ${{ inputs.github-token }} - TARGET_URL: ${{ inputs.target-url }} - COMMIT_STATUS_SHA: ${{ inputs.sha }} - DESCRIPTION: ${{ steps.commit_status.outputs.description }} - CONTEXT: ${{ inputs.context }} - STATUS: ${{ steps.commit_status.outputs.status }} - run: | - @import ../script-import-helper (script_name: "update-commit-status.bash") diff --git a/update/get-commit-status.bash b/update/get-commit-status.bash old mode 100644 new mode 100755 index e21aea1..8528c81 --- a/update/get-commit-status.bash +++ b/update/get-commit-status.bash @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + set -eu -o pipefail cat > update_commit_status-needs.json <