|
| 1 | +name: 'Build and Test' |
| 2 | +on: # rebuild any PRs and main branch changes |
| 3 | + pull_request: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - "main" |
| 8 | + |
| 9 | +jobs: |
| 10 | + integration-tests: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + permissions: |
| 13 | + contents: write |
| 14 | + actions: write |
| 15 | + env: |
| 16 | + INTEGRATION_TEST_WORKFLOW_FILE: "integration-tests.yml" |
| 17 | + INTEGRATION_TEST_WORKFLOW_ID: 64701969 # This ID Will Change On Fork |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v4 |
| 20 | + - id: nvmrc |
| 21 | + name: Extract Node.JS Version |
| 22 | + shell: bash |
| 23 | + run: | |
| 24 | + echo "node-version=$(cat .nvmrc)" >> "${GITHUB_OUTPUT}" |
| 25 | + - name: Set Node.JS |
| 26 | + uses: actions/setup-node@v4 |
| 27 | + with: |
| 28 | + node-version: "${{ steps.nvmrc.outputs.node-version }}" |
| 29 | + - id: clean-dist |
| 30 | + shell: bash |
| 31 | + run: | |
| 32 | + # Clean the existing dist/ folder so that we only test fresh |
| 33 | + # compiled code |
| 34 | + rm -rf dist/ |
| 35 | + - run: | |
| 36 | + npm ci |
| 37 | + - run: | |
| 38 | + npm run all |
| 39 | + - uses: ./ |
| 40 | + id: fail-ref-workflow-dispatch |
| 41 | + name: "Dispatch Workflow using workflow_dispatch Method, to a Non-existent Branch" |
| 42 | + continue-on-error: true |
| 43 | + with: |
| 44 | + dispatch-method: "workflow_dispatch" |
| 45 | + repo: "${{ github.event.repository.name }}" |
| 46 | + owner: "${{ github.repository_owner }}" |
| 47 | + ref: "non-existent-branch/${{ github.run_id }}" # This branch cannot realistically exist |
| 48 | + workflow: "${{ env.INTEGRATION_TEST_WORKFLOW_FILE }}" |
| 49 | + token: "${{ secrets.GITHUB_TOKEN }}" |
| 50 | + workflow-inputs: '{"placeholder": "placeholder"}' |
| 51 | + - uses: ./ |
| 52 | + id: fail-file-workflow-dispatch |
| 53 | + name: "Dispatch Workflow using workflow_dispatch Method, to a Non-existent Workflow File" |
| 54 | + continue-on-error: true |
| 55 | + with: |
| 56 | + dispatch-method: "workflow_dispatch" |
| 57 | + repo: "${{ github.event.repository.name }}" |
| 58 | + owner: "${{ github.repository_owner }}" |
| 59 | + ref: "main" |
| 60 | + workflow: "${{ github.run_id }}.yml" # This workflow file cannot realistically exist |
| 61 | + token: "${{ secrets.GITHUB_TOKEN }}" |
| 62 | + workflow-inputs: '{"placeholder": "placeholder"}' |
| 63 | + - uses: ./ |
| 64 | + id: fail-inputs-workflow-dispatch |
| 65 | + name: "Dispatch Workflow using workflow_dispatch Method, with an unsupported workflow inputs" |
| 66 | + continue-on-error: true |
| 67 | + with: |
| 68 | + dispatch-method: "workflow_dispatch" |
| 69 | + repo: "${{ github.event.repository.name }}" |
| 70 | + owner: "${{ github.repository_owner }}" |
| 71 | + ref: "main" |
| 72 | + workflow: "${{ env.INTEGRATION_TEST_WORKFLOW_FILE }}" |
| 73 | + token: "${{ secrets.GITHUB_TOKEN }}" |
| 74 | + workflow-inputs: '{"placeholder": 0}' # 0 is not a string type |
| 75 | + - id: verify-fail-workflow-dispatch |
| 76 | + name: "Verify Action Outputs for worflow-dispatch" |
| 77 | + shell: bash |
| 78 | + run: | |
| 79 | + set -euo pipefail |
| 80 | +
|
| 81 | + if [[ "${{ steps.fail-ref-workflow-dispatch.outcome }}" != "failure" ]]; then |
| 82 | + >&2 echo "🔴 fail-ref-workflow-dispatch step was expected to fail"; exit 1 |
| 83 | + fi |
| 84 | +
|
| 85 | + if [[ "${{ steps.fail-file-workflow-dispatch.outcome }}" != "failure" ]]; then |
| 86 | + >&2 echo "🔴 fail-file-workflow-dispatch step was expected to fail"; exit 1 |
| 87 | + fi |
| 88 | +
|
| 89 | + if [[ "${{ steps.fail-inputs-workflow-dispatch.outcome }}" != "failure" ]]; then |
| 90 | + >&2 echo "🔴 fail-inputs-workflow-dispatch step was expected to fail"; exit 1 |
| 91 | + fi |
| 92 | + - uses: ./ |
| 93 | + id: workflow-dispatch |
| 94 | + name: "Dispatch Using workflow_dispatch Method" |
| 95 | + with: |
| 96 | + dispatch-method: "workflow_dispatch" |
| 97 | + repo: "${{ github.event.repository.name }}" |
| 98 | + owner: "${{ github.repository_owner }}" |
| 99 | + ref: "refs/heads/main" |
| 100 | + workflow: "${{ env.INTEGRATION_TEST_WORKFLOW_FILE }}" |
| 101 | + token: "${{ secrets.GITHUB_TOKEN }}" |
| 102 | + workflow-inputs: | |
| 103 | + { |
| 104 | + "string-type": "placeholder", |
| 105 | + "number-type": "1", |
| 106 | + "boolean-type": "true" |
| 107 | + } |
| 108 | + - uses: ./ |
| 109 | + id: repository-dispatch-custom-backoff |
| 110 | + name: "Dispatch Using repositroy_dispatch Method and custom exponential backoff parameters" |
| 111 | + with: |
| 112 | + dispatch-method: "repository_dispatch" |
| 113 | + event-type: "repository-dispatch" |
| 114 | + repo: "${{ github.event.repository.name }}" |
| 115 | + owner: "${{ github.repository_owner }}" |
| 116 | + token: "${{ secrets.GITHUB_TOKEN }}" |
| 117 | + workflow-inputs: | |
| 118 | + { |
| 119 | + "string-type": "placeholder", |
| 120 | + "nested": { |
| 121 | + "number-type": 1, |
| 122 | + "boolean-type": true |
| 123 | + } |
| 124 | + } |
| 125 | + starting-delay-ms: 150 |
| 126 | + max-attempts: 3 |
| 127 | + time-multiple: 1.5 |
| 128 | + - uses: ./ |
| 129 | + id: wait-repository-dispatch |
| 130 | + name: "Dispatch Using repository_dispatch Method And Wait For Run-ID" |
| 131 | + with: |
| 132 | + dispatch-method: "repository_dispatch" |
| 133 | + event-type: "repository-dispatch" |
| 134 | + repo: "${{ github.event.repository.name }}" |
| 135 | + owner: "${{ github.repository_owner }}" |
| 136 | + token: "${{ secrets.GITHUB_TOKEN }}" |
| 137 | + workflow-inputs: | |
| 138 | + { |
| 139 | + "string-type": "placeholder", |
| 140 | + "nested": { |
| 141 | + "number-type": 1, |
| 142 | + "boolean-type": true |
| 143 | + } |
| 144 | + } |
| 145 | + discover: true |
| 146 | + - id: verify-repository-dispatch-outcome |
| 147 | + name: Await Run ID ${{ steps.wait-repository-dispatch.outputs.run-id }} |
| 148 | + uses: codex-/await-remote-run@v1 |
| 149 | + with: |
| 150 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 151 | + repo: ${{ github.event.repository.name }} |
| 152 | + owner: ${{ github.repository_owner }} |
| 153 | + run_id: ${{ steps.wait-repository-dispatch.outputs.run-id }} |
| 154 | + - id: verify-repository-dispatch-outputs |
| 155 | + name: "Verify Action Outputs for repository-dispatch" |
| 156 | + shell: bash |
| 157 | + run: | |
| 158 | + set -euo pipefail |
| 159 | +
|
| 160 | + # wait-repository-dispatch |
| 161 | + if [[ -z "${{ steps.wait-repository-dispatch.outputs.run-id }}" ]]; then |
| 162 | + >&2 echo "🔴 wait-repository-dispatch step should output 'run-id'"; exit 1 |
| 163 | + fi |
| 164 | +
|
| 165 | + if [[ -z "${{ steps.wait-repository-dispatch.outputs.run-url }}" ]]; then |
| 166 | + >&2 echo "🔴 wait-repository-dispatch step should output 'run-url'"; exit 1 |
| 167 | + fi |
0 commit comments