From 61fc2986ede5b4093588b83cc04eb1f68bc3b310 Mon Sep 17 00:00:00 2001 From: Andrew Roth Date: Sun, 3 Oct 2021 09:58:56 -0700 Subject: [PATCH 1/4] wip --- .github/workflows/example-command.yml | 15 +++++++++++++++ .github/workflows/slash-command-dispatch.yml | 14 ++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 .github/workflows/example-command.yml create mode 100644 .github/workflows/slash-command-dispatch.yml diff --git a/.github/workflows/example-command.yml b/.github/workflows/example-command.yml new file mode 100644 index 0000000000..3c23f928ca --- /dev/null +++ b/.github/workflows/example-command.yml @@ -0,0 +1,15 @@ +name: example-command +on: + repository_dispatch: + types: [example-command] +jobs: + example: + runs-on: ubuntu-latest + steps: + - name: Add reaction + uses: peter-evans/create-or-update-comment@v1 + with: + token: ${{ secrets.PAT }} + repository: ${{ github.event.client_payload.github.payload.repository.full_name }} + comment-id: ${{ github.event.client_payload.github.payload.comment.id }} + reaction-type: hooray diff --git a/.github/workflows/slash-command-dispatch.yml b/.github/workflows/slash-command-dispatch.yml new file mode 100644 index 0000000000..4a9f9c3d73 --- /dev/null +++ b/.github/workflows/slash-command-dispatch.yml @@ -0,0 +1,14 @@ +name: Slash Command Dispatch +on: + issue_comment: + types: [created] +jobs: + slashCommandDispatch: + runs-on: ubuntu-latest + steps: + - name: Slash Command Dispatch + uses: peter-evans/slash-command-dispatch@v2 + with: + token: ${{ secrets.PAT }} + commands: example + repository: defenseunicorns/zarf From 6223a84b42ea33d10ff28598ead7b4dce4b69043 Mon Sep 17 00:00:00 2001 From: Andrew Roth Date: Sun, 3 Oct 2021 12:34:15 -0700 Subject: [PATCH 2/4] wip --- .github/workflows/example-command.yml | 15 -- .github/workflows/slash-command-dispatch.yml | 5 +- .github/workflows/test-command.yml | 179 +++++++++++++++++++ 3 files changed, 182 insertions(+), 17 deletions(-) delete mode 100644 .github/workflows/example-command.yml create mode 100644 .github/workflows/test-command.yml diff --git a/.github/workflows/example-command.yml b/.github/workflows/example-command.yml deleted file mode 100644 index 3c23f928ca..0000000000 --- a/.github/workflows/example-command.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: example-command -on: - repository_dispatch: - types: [example-command] -jobs: - example: - runs-on: ubuntu-latest - steps: - - name: Add reaction - uses: peter-evans/create-or-update-comment@v1 - with: - token: ${{ secrets.PAT }} - repository: ${{ github.event.client_payload.github.payload.repository.full_name }} - comment-id: ${{ github.event.client_payload.github.payload.comment.id }} - reaction-type: hooray diff --git a/.github/workflows/slash-command-dispatch.yml b/.github/workflows/slash-command-dispatch.yml index 4a9f9c3d73..9de4ef5d63 100644 --- a/.github/workflows/slash-command-dispatch.yml +++ b/.github/workflows/slash-command-dispatch.yml @@ -10,5 +10,6 @@ jobs: uses: peter-evans/slash-command-dispatch@v2 with: token: ${{ secrets.PAT }} - commands: example - repository: defenseunicorns/zarf + commands: test + permission: write + issue-type: pull-request diff --git a/.github/workflows/test-command.yml b/.github/workflows/test-command.yml new file mode 100644 index 0000000000..6b88493a5f --- /dev/null +++ b/.github/workflows/test-command.yml @@ -0,0 +1,179 @@ +# Attribution for a bunch of this goes to CloudPosse +# https://github.com/cloudposse/actions/blob/master/.github/workflows/test-command.yml + +name: test +on: + repository_dispatch: + types: [test-command] + +defaults: + run: + # We need -e -o pipefail for consistency with GitHub Actions's default behavior + shell: bash -e -o pipefail {0} + +jobs: + # Parse the command so we can decide which tests to run. Examples: "/test all", "/test validate", "/test e2e" + # We can do as many of these as we want to get as granular as we want. + parse: + runs-on: ubuntu-latest + outputs: + run-ping: ${{ steps.parse.outputs.ping }} + run-hello: ${{ steps.parse.outputs.hello }} + run-quote: ${{ steps.parse.outputs.quote }} + steps: + - name: Parse Args + id: parse + env: + DEBUG: ${{ toJSON(github.event.client_payload.slash_command) }} + ARGS_V1: ${{ github.event.client_payload.slash_command.arg1 }} + ARGS_V2: ${{ github.event.client_payload.slash_command.args.unnamed.all }} + shell: bash + run: | + ARGS="${ARGS_V1}${ARGS_V2}" + printf "Args are %s\n" "$ARGS" + printf "\n\nslash_command is %s\n\n" "$DEBUG" + COMMANDS=(PING HELLO QUOTE) + if printf "%s" "${ARGS^^}" | grep -qE '\bALL\b'; then + # "all" explicitly does not include "ping" + for cmd in "${COMMANDS[@]}"; do + [[ $cmd == "PING" ]] && ! { printf "%s" "${ARGS^^}" | grep -qE '\bPING\b'; } && continue + printf -v "$cmd" "true" + done + else + for cmd in "${COMMANDS[@]}"; do + if printf "%s" "${ARGS^^}" | grep -qE "\b${cmd}\b"; then + printf -v "$cmd" "true" + fi + done + fi + for out in "${COMMANDS[@]}"; do + printf "::set-output name=%s::%s\n" "${out,,}" "${!out:-false}" + printf "%s=%s\n" "${out,,}" "${!out:-false}" + done + + # Do a simple ping/pong status update to validate things are working + ping: + runs-on: ubuntu-latest + needs: parse + if: needs.parse.outputs.run-ping == 'true' + steps: + # Update GitHub status for dispatch events + - name: "Update GitHub Status for this ref" + uses: "docker://cloudposse/github-status-updater" + with: + args: "-action update_state -ref ${{ github.event.client_payload.pull_request.head.sha }} -repo ${{ github.event.client_payload.github.payload.repository.name }}" + env: + GITHUB_TOKEN: ${{ secrets.PAT }} + GITHUB_STATE: success + GITHUB_CONTEXT: "/test ping" + GITHUB_DESCRIPTION: "pong" + GITHUB_TARGET_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} + GITHUB_REF: ${{ github.event.client_payload.pull_request.head.ref }} + GITHUB_OWNER: ${{ github.event.client_payload.github.payload.repository.owner.login }} + + # Do a "hello world" example pipeline run + hello: + runs-on: ubuntu-latest + needs: parse + if: needs.parse.outputs.run-hello == 'true' + steps: + # Update GitHub status for pending pipeline run + - name: "Update GitHub Status for pending" + uses: docker://cloudposse/github-status-updater + with: + args: "-action update_state -ref ${{ github.event.client_payload.pull_request.head.sha }} -repo ${{ github.event.client_payload.github.payload.repository.name }}" + env: + GITHUB_TOKEN: ${{ secrets.PAT }} + GITHUB_STATE: pending + GITHUB_CONTEXT: "/test hello" + GITHUB_DESCRIPTION: "started by @${{ github.event.client_payload.github.actor }}" + GITHUB_TARGET_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} + GITHUB_REF: ${{ github.event.client_payload.pull_request.head.ref }} + GITHUB_OWNER: ${{ github.event.client_payload.github.payload.repository.owner.login }} + + # Checkout the code from GitHub Pull Request + - name: "Checkout the code" + uses: actions/checkout@v2 + with: + token: ${{ secrets.PAT }} + repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }} + ref: ${{ github.event.client_payload.pull_request.head.ref }} + + # Echo "Hello world!" + - name: "Echo something" + run: | + echo "Hello world!" + + # # Throw a failure to test fail conditions + # - name: "Fail" + # run: | + # exit 1 + + # # Wait a long time to give the dev time to test cancel conditions + # - name: "Wait" + # run: | + # sleep 600 + + # Update GitHub status for failing pipeline run + - name: "Update GitHub Status for failure" + if: ${{ failure() }} + uses: docker://cloudposse/github-status-updater + with: + args: "-action update_state -ref ${{ github.event.client_payload.pull_request.head.sha }} -repo ${{ github.event.client_payload.github.payload.repository.name }}" + env: + GITHUB_TOKEN: ${{ secrets.PAT }} + GITHUB_STATE: failure + GITHUB_CONTEXT: "/test hello" + GITHUB_DESCRIPTION: "run failed" + GITHUB_TARGET_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} + GITHUB_REF: ${{ github.event.client_payload.pull_request.head.ref }} + GITHUB_OWNER: ${{ github.event.client_payload.github.payload.repository.owner.login }} + + # Update GitHub status for successful pipeline run + - name: "Update GitHub Status for success" + uses: docker://cloudposse/github-status-updater + with: + args: "-action update_state -ref ${{ github.event.client_payload.pull_request.head.sha }} -repo ${{ github.event.client_payload.github.payload.repository.name }}" + env: + GITHUB_TOKEN: ${{ secrets.PAT }} + GITHUB_STATE: success + GITHUB_CONTEXT: "/test hello" + GITHUB_DESCRIPTION: "run passed" + GITHUB_TARGET_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} + GITHUB_REF: ${{ github.event.client_payload.pull_request.head.ref }} + GITHUB_OWNER: ${{ github.event.client_payload.github.payload.repository.owner.login }} + + # Update GitHub status for cancelled pipeline run + - name: "Update GitHub Status for cancelled" + if: ${{ cancelled() }} + uses: docker://cloudposse/github-status-updater + with: + args: "-action update_state -ref ${{ github.event.client_payload.pull_request.head.sha }} -repo ${{ github.event.client_payload.github.payload.repository.name }}" + env: + GITHUB_TOKEN: ${{ secrets.PAT }} + GITHUB_STATE: error + GITHUB_CONTEXT: "/test hello" + GITHUB_DESCRIPTION: "run cancelled" + GITHUB_TARGET_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} + GITHUB_REF: ${{ github.event.client_payload.pull_request.head.ref }} + GITHUB_OWNER: ${{ github.event.client_payload.github.payload.repository.owner.login }} + + # Add a quote to the status section + quote: + runs-on: ubuntu-latest + needs: parse + if: needs.parse.outputs.run-quote == 'true' + steps: + # Update GitHub status + - name: "Update GitHub Status for successful pipeline run" + uses: "docker://cloudposse/github-status-updater" + with: + args: "-action update_state -ref ${{ github.event.client_payload.pull_request.head.sha }} -repo ${{ github.event.client_payload.github.payload.repository.name }}" + env: + GITHUB_TOKEN: ${{ secrets.PAT }} + GITHUB_STATE: success + GITHUB_CONTEXT: "/test quote" + GITHUB_DESCRIPTION: "Insanity is doing the same thing over and over and expecting different results." + GITHUB_TARGET_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} + GITHUB_REF: ${{ github.event.client_payload.pull_request.head.ref }} + GITHUB_OWNER: ${{ github.event.client_payload.github.payload.repository.owner.login }} From f835eaf3e05f2da148847a17264e5b3bf0e9c7a7 Mon Sep 17 00:00:00 2001 From: Andrew Roth Date: Sun, 3 Oct 2021 09:58:56 -0700 Subject: [PATCH 3/4] wip --- .github/workflows/example-command.yml | 15 +++++++++++++++ .github/workflows/slash-command-dispatch.yml | 14 ++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 .github/workflows/example-command.yml create mode 100644 .github/workflows/slash-command-dispatch.yml diff --git a/.github/workflows/example-command.yml b/.github/workflows/example-command.yml new file mode 100644 index 0000000000..3c23f928ca --- /dev/null +++ b/.github/workflows/example-command.yml @@ -0,0 +1,15 @@ +name: example-command +on: + repository_dispatch: + types: [example-command] +jobs: + example: + runs-on: ubuntu-latest + steps: + - name: Add reaction + uses: peter-evans/create-or-update-comment@v1 + with: + token: ${{ secrets.PAT }} + repository: ${{ github.event.client_payload.github.payload.repository.full_name }} + comment-id: ${{ github.event.client_payload.github.payload.comment.id }} + reaction-type: hooray diff --git a/.github/workflows/slash-command-dispatch.yml b/.github/workflows/slash-command-dispatch.yml new file mode 100644 index 0000000000..4a9f9c3d73 --- /dev/null +++ b/.github/workflows/slash-command-dispatch.yml @@ -0,0 +1,14 @@ +name: Slash Command Dispatch +on: + issue_comment: + types: [created] +jobs: + slashCommandDispatch: + runs-on: ubuntu-latest + steps: + - name: Slash Command Dispatch + uses: peter-evans/slash-command-dispatch@v2 + with: + token: ${{ secrets.PAT }} + commands: example + repository: defenseunicorns/zarf From bd37db70e6dcc198296f8b96c1d841ee0e1d094b Mon Sep 17 00:00:00 2001 From: Andrew Roth Date: Sun, 3 Oct 2021 12:34:15 -0700 Subject: [PATCH 4/4] wip --- .github/workflows/example-command.yml | 15 -- .github/workflows/slash-command-dispatch.yml | 5 +- .github/workflows/test-command.yml | 179 +++++++++++++++++++ 3 files changed, 182 insertions(+), 17 deletions(-) delete mode 100644 .github/workflows/example-command.yml create mode 100644 .github/workflows/test-command.yml diff --git a/.github/workflows/example-command.yml b/.github/workflows/example-command.yml deleted file mode 100644 index 3c23f928ca..0000000000 --- a/.github/workflows/example-command.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: example-command -on: - repository_dispatch: - types: [example-command] -jobs: - example: - runs-on: ubuntu-latest - steps: - - name: Add reaction - uses: peter-evans/create-or-update-comment@v1 - with: - token: ${{ secrets.PAT }} - repository: ${{ github.event.client_payload.github.payload.repository.full_name }} - comment-id: ${{ github.event.client_payload.github.payload.comment.id }} - reaction-type: hooray diff --git a/.github/workflows/slash-command-dispatch.yml b/.github/workflows/slash-command-dispatch.yml index 4a9f9c3d73..9de4ef5d63 100644 --- a/.github/workflows/slash-command-dispatch.yml +++ b/.github/workflows/slash-command-dispatch.yml @@ -10,5 +10,6 @@ jobs: uses: peter-evans/slash-command-dispatch@v2 with: token: ${{ secrets.PAT }} - commands: example - repository: defenseunicorns/zarf + commands: test + permission: write + issue-type: pull-request diff --git a/.github/workflows/test-command.yml b/.github/workflows/test-command.yml new file mode 100644 index 0000000000..6b88493a5f --- /dev/null +++ b/.github/workflows/test-command.yml @@ -0,0 +1,179 @@ +# Attribution for a bunch of this goes to CloudPosse +# https://github.com/cloudposse/actions/blob/master/.github/workflows/test-command.yml + +name: test +on: + repository_dispatch: + types: [test-command] + +defaults: + run: + # We need -e -o pipefail for consistency with GitHub Actions's default behavior + shell: bash -e -o pipefail {0} + +jobs: + # Parse the command so we can decide which tests to run. Examples: "/test all", "/test validate", "/test e2e" + # We can do as many of these as we want to get as granular as we want. + parse: + runs-on: ubuntu-latest + outputs: + run-ping: ${{ steps.parse.outputs.ping }} + run-hello: ${{ steps.parse.outputs.hello }} + run-quote: ${{ steps.parse.outputs.quote }} + steps: + - name: Parse Args + id: parse + env: + DEBUG: ${{ toJSON(github.event.client_payload.slash_command) }} + ARGS_V1: ${{ github.event.client_payload.slash_command.arg1 }} + ARGS_V2: ${{ github.event.client_payload.slash_command.args.unnamed.all }} + shell: bash + run: | + ARGS="${ARGS_V1}${ARGS_V2}" + printf "Args are %s\n" "$ARGS" + printf "\n\nslash_command is %s\n\n" "$DEBUG" + COMMANDS=(PING HELLO QUOTE) + if printf "%s" "${ARGS^^}" | grep -qE '\bALL\b'; then + # "all" explicitly does not include "ping" + for cmd in "${COMMANDS[@]}"; do + [[ $cmd == "PING" ]] && ! { printf "%s" "${ARGS^^}" | grep -qE '\bPING\b'; } && continue + printf -v "$cmd" "true" + done + else + for cmd in "${COMMANDS[@]}"; do + if printf "%s" "${ARGS^^}" | grep -qE "\b${cmd}\b"; then + printf -v "$cmd" "true" + fi + done + fi + for out in "${COMMANDS[@]}"; do + printf "::set-output name=%s::%s\n" "${out,,}" "${!out:-false}" + printf "%s=%s\n" "${out,,}" "${!out:-false}" + done + + # Do a simple ping/pong status update to validate things are working + ping: + runs-on: ubuntu-latest + needs: parse + if: needs.parse.outputs.run-ping == 'true' + steps: + # Update GitHub status for dispatch events + - name: "Update GitHub Status for this ref" + uses: "docker://cloudposse/github-status-updater" + with: + args: "-action update_state -ref ${{ github.event.client_payload.pull_request.head.sha }} -repo ${{ github.event.client_payload.github.payload.repository.name }}" + env: + GITHUB_TOKEN: ${{ secrets.PAT }} + GITHUB_STATE: success + GITHUB_CONTEXT: "/test ping" + GITHUB_DESCRIPTION: "pong" + GITHUB_TARGET_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} + GITHUB_REF: ${{ github.event.client_payload.pull_request.head.ref }} + GITHUB_OWNER: ${{ github.event.client_payload.github.payload.repository.owner.login }} + + # Do a "hello world" example pipeline run + hello: + runs-on: ubuntu-latest + needs: parse + if: needs.parse.outputs.run-hello == 'true' + steps: + # Update GitHub status for pending pipeline run + - name: "Update GitHub Status for pending" + uses: docker://cloudposse/github-status-updater + with: + args: "-action update_state -ref ${{ github.event.client_payload.pull_request.head.sha }} -repo ${{ github.event.client_payload.github.payload.repository.name }}" + env: + GITHUB_TOKEN: ${{ secrets.PAT }} + GITHUB_STATE: pending + GITHUB_CONTEXT: "/test hello" + GITHUB_DESCRIPTION: "started by @${{ github.event.client_payload.github.actor }}" + GITHUB_TARGET_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} + GITHUB_REF: ${{ github.event.client_payload.pull_request.head.ref }} + GITHUB_OWNER: ${{ github.event.client_payload.github.payload.repository.owner.login }} + + # Checkout the code from GitHub Pull Request + - name: "Checkout the code" + uses: actions/checkout@v2 + with: + token: ${{ secrets.PAT }} + repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }} + ref: ${{ github.event.client_payload.pull_request.head.ref }} + + # Echo "Hello world!" + - name: "Echo something" + run: | + echo "Hello world!" + + # # Throw a failure to test fail conditions + # - name: "Fail" + # run: | + # exit 1 + + # # Wait a long time to give the dev time to test cancel conditions + # - name: "Wait" + # run: | + # sleep 600 + + # Update GitHub status for failing pipeline run + - name: "Update GitHub Status for failure" + if: ${{ failure() }} + uses: docker://cloudposse/github-status-updater + with: + args: "-action update_state -ref ${{ github.event.client_payload.pull_request.head.sha }} -repo ${{ github.event.client_payload.github.payload.repository.name }}" + env: + GITHUB_TOKEN: ${{ secrets.PAT }} + GITHUB_STATE: failure + GITHUB_CONTEXT: "/test hello" + GITHUB_DESCRIPTION: "run failed" + GITHUB_TARGET_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} + GITHUB_REF: ${{ github.event.client_payload.pull_request.head.ref }} + GITHUB_OWNER: ${{ github.event.client_payload.github.payload.repository.owner.login }} + + # Update GitHub status for successful pipeline run + - name: "Update GitHub Status for success" + uses: docker://cloudposse/github-status-updater + with: + args: "-action update_state -ref ${{ github.event.client_payload.pull_request.head.sha }} -repo ${{ github.event.client_payload.github.payload.repository.name }}" + env: + GITHUB_TOKEN: ${{ secrets.PAT }} + GITHUB_STATE: success + GITHUB_CONTEXT: "/test hello" + GITHUB_DESCRIPTION: "run passed" + GITHUB_TARGET_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} + GITHUB_REF: ${{ github.event.client_payload.pull_request.head.ref }} + GITHUB_OWNER: ${{ github.event.client_payload.github.payload.repository.owner.login }} + + # Update GitHub status for cancelled pipeline run + - name: "Update GitHub Status for cancelled" + if: ${{ cancelled() }} + uses: docker://cloudposse/github-status-updater + with: + args: "-action update_state -ref ${{ github.event.client_payload.pull_request.head.sha }} -repo ${{ github.event.client_payload.github.payload.repository.name }}" + env: + GITHUB_TOKEN: ${{ secrets.PAT }} + GITHUB_STATE: error + GITHUB_CONTEXT: "/test hello" + GITHUB_DESCRIPTION: "run cancelled" + GITHUB_TARGET_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} + GITHUB_REF: ${{ github.event.client_payload.pull_request.head.ref }} + GITHUB_OWNER: ${{ github.event.client_payload.github.payload.repository.owner.login }} + + # Add a quote to the status section + quote: + runs-on: ubuntu-latest + needs: parse + if: needs.parse.outputs.run-quote == 'true' + steps: + # Update GitHub status + - name: "Update GitHub Status for successful pipeline run" + uses: "docker://cloudposse/github-status-updater" + with: + args: "-action update_state -ref ${{ github.event.client_payload.pull_request.head.sha }} -repo ${{ github.event.client_payload.github.payload.repository.name }}" + env: + GITHUB_TOKEN: ${{ secrets.PAT }} + GITHUB_STATE: success + GITHUB_CONTEXT: "/test quote" + GITHUB_DESCRIPTION: "Insanity is doing the same thing over and over and expecting different results." + GITHUB_TARGET_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} + GITHUB_REF: ${{ github.event.client_payload.pull_request.head.ref }} + GITHUB_OWNER: ${{ github.event.client_payload.github.payload.repository.owner.login }}