|
4 | 4 | issue_comment: |
5 | 5 | types: [created] |
6 | 6 |
|
| 7 | +env: |
| 8 | + GO_VERSION: "1.23.6" |
| 9 | + |
7 | 10 | jobs: |
8 | | - e2e: |
9 | | - uses: upbound/uptest/.github/workflows/pr-comment-trigger.yml@main |
10 | | - secrets: |
11 | | - UPTEST_CLOUD_CREDENTIALS: ${{ secrets.UPTEST_CLOUD_CREDENTIALS }} |
12 | | - UPTEST_DATASOURCE: ${{ secrets.UPTEST_DATASOURCE }} |
| 11 | + check-permissions: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + outputs: |
| 14 | + permission: ${{ steps.check-permissions.outputs.permission }} |
| 15 | + steps: |
| 16 | + - name: Get Commenter Permissions |
| 17 | + id: check-permissions |
| 18 | + run: | |
| 19 | + echo "Trigger keyword: '/test-examples'" |
| 20 | + echo "Go version: ${{ env.GO_VERSION }}" |
| 21 | +
|
| 22 | + REPO=${{ github.repository }} |
| 23 | + COMMENTER=${{ github.event.comment.user.login }} |
| 24 | +
|
| 25 | + # Fetch the commenter's repo-level permission grant |
| 26 | + GRANTED=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ |
| 27 | + -H "Accept: application/vnd.github.v3+json" \ |
| 28 | + "https://api.github.com/repos/$REPO/collaborators/$COMMENTER/permission" | jq -r .permission) |
| 29 | +
|
| 30 | + # Make it accessible in the workflow via a job output -- cannot use env |
| 31 | + echo "User $COMMENTER has $GRANTED permissions" |
| 32 | + echo "permission=$GRANTED" >> "$GITHUB_OUTPUT" |
| 33 | +
|
| 34 | + get-example-list: |
| 35 | + needs: check-permissions |
| 36 | + if: ${{ (needs.check-permissions.outputs.permission == 'admin' || needs.check-permissions.outputs.permission == 'write') && github.event.issue.pull_request != null && contains(github.event.comment.body, '/test-examples')}} |
| 37 | + runs-on: ubuntu-latest |
| 38 | + outputs: |
| 39 | + example_list: ${{ steps.get-example-list-name.outputs.example-list }} |
| 40 | + example_hash: ${{ steps.get-example-list-name.outputs.example-hash }} |
| 41 | + |
| 42 | + steps: |
| 43 | + - name: Checkout |
| 44 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 45 | + with: |
| 46 | + submodules: true |
| 47 | + |
| 48 | + - name: Checkout PR |
| 49 | + id: checkout-pr |
| 50 | + env: |
| 51 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 52 | + run: | |
| 53 | + gh pr checkout ${{ github.event.issue.number }} |
| 54 | + git submodule update --init --recursive |
| 55 | + OUTPUT=$(git log -1 --format='%H') |
| 56 | + echo "commit-sha=$OUTPUT" >> $GITHUB_OUTPUT |
| 57 | +
|
| 58 | + - name: Prepare The Example List |
| 59 | + env: |
| 60 | + COMMENT: ${{ github.event.comment.body }} |
| 61 | + id: get-example-list-name |
| 62 | + run: | |
| 63 | + PATHS=$(echo $COMMENT | sed 's/^.*\/test-examples="//g' | cut -d '"' -f 1 | sed 's/,/ /g') |
| 64 | + EXAMPLE_LIST="" |
| 65 | + for P in $PATHS; do EXAMPLE_LIST="${EXAMPLE_LIST},$(find $P -name '*.yaml' | tr '\n' ',')"; done |
| 66 | +
|
| 67 | + sudo apt-get -y install coreutils |
| 68 | + COUNT=$(echo ${EXAMPLE_LIST:1} | grep -o ".yaml" | wc -l) |
| 69 | + if [ $COUNT -gt 1 ]; then EXAMPLE_HASH=$(echo ${EXAMPLE_LIST} | md5sum | cut -f1 -d" "); else EXAMPLE_HASH=$(echo ${EXAMPLE_LIST:1} | sed 's/.$//'); fi |
| 70 | +
|
| 71 | + echo "Examples: ${EXAMPLE_LIST:1}" |
| 72 | + echo "Example Hash: ${EXAMPLE_HASH}" |
| 73 | +
|
| 74 | + echo "example-list=${EXAMPLE_LIST:1}" >> $GITHUB_OUTPUT |
| 75 | + echo "example-hash=${EXAMPLE_HASH}" >> $GITHUB_OUTPUT |
| 76 | +
|
| 77 | + - name: Create Pending Status Check |
| 78 | + env: |
| 79 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 80 | + run: | |
| 81 | + gh api \ |
| 82 | + --method POST \ |
| 83 | + -H "Accept: application/vnd.github+json" \ |
| 84 | + /repos/${{ github.repository }}/statuses/${{ steps.checkout-pr.outputs.commit-sha }} \ |
| 85 | + -f state='pending' \ |
| 86 | + -f target_url='https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' \ |
| 87 | + -f description='Running...' \ |
| 88 | + -f context="Uptest-${{ steps.get-example-list-name.outputs.example-hash }}" |
| 89 | +
|
| 90 | + uptest: |
| 91 | + needs: |
| 92 | + - check-permissions |
| 93 | + - get-example-list |
| 94 | + if: ${{ (needs.check-permissions.outputs.permission == 'admin' || needs.check-permissions.outputs.permission == 'write') && github.event.issue.pull_request != null && contains(github.event.comment.body, '/test-examples')}} |
| 95 | + runs-on: ubuntu-latest |
| 96 | + steps: |
| 97 | + - name: Cleanup Disk |
| 98 | + uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # v1.3.1 |
| 99 | + with: |
| 100 | + large-packages: false |
| 101 | + swap-storage: false |
| 102 | + |
| 103 | + - name: Setup QEMU |
| 104 | + uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0 |
| 105 | + with: |
| 106 | + platforms: all |
| 107 | + |
| 108 | + - name: Checkout |
| 109 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 110 | + with: |
| 111 | + submodules: true |
| 112 | + |
| 113 | + - name: Setup Go |
| 114 | + uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0 |
| 115 | + with: |
| 116 | + go-version: ${{ env.GO_VERSION }} |
| 117 | + |
| 118 | + - name: Checkout PR |
| 119 | + id: checkout-pr |
| 120 | + env: |
| 121 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 122 | + run: | |
| 123 | + gh pr checkout ${{ github.event.issue.number }} |
| 124 | + git submodule update --init --recursive |
| 125 | + OUTPUT=$(git log -1 --format='%H') |
| 126 | + echo "commit-sha=$OUTPUT" >> $GITHUB_OUTPUT |
| 127 | +
|
| 128 | + - name: Vendor Dependencies |
| 129 | + run: make vendor vendor.check |
| 130 | + |
| 131 | + - name: Run Uptest |
| 132 | + id: run-uptest |
| 133 | + env: |
| 134 | + UPTEST_CLOUD_CREDENTIALS: ${{ secrets.UPTEST_CLOUD_CREDENTIALS }} |
| 135 | + UPTEST_EXAMPLE_LIST: ${{ needs.get-example-list.outputs.example_list }} |
| 136 | + UPTEST_TEST_DIR: ./_output/controlplane-dump |
| 137 | + UPTEST_DATASOURCE_PATH: .work/uptest-datasource.yaml |
| 138 | + UPTEST_UPDATE_PARAMETER: "" |
| 139 | + run: | |
| 140 | + mkdir -p .work && echo "${{ secrets.UPTEST_DATASOURCE }}" > .work/uptest-datasource.yaml |
| 141 | + make e2e |
| 142 | +
|
| 143 | + - name: Create Successful Status Check |
| 144 | + env: |
| 145 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 146 | + EXAMPLE_HASH: ${{ needs.get-example-list.outputs.example_hash }} |
| 147 | + run: | |
| 148 | + gh api \ |
| 149 | + --method POST \ |
| 150 | + -H "Accept: application/vnd.github+json" \ |
| 151 | + /repos/${{ github.repository }}/statuses/${{ steps.checkout-pr.outputs.commit-sha }} \ |
| 152 | + -f state='success' \ |
| 153 | + -f target_url='https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' \ |
| 154 | + -f description='Passed' \ |
| 155 | + -f context="Uptest-${EXAMPLE_HASH}" |
| 156 | +
|
| 157 | + - name: Collect Cluster Dump |
| 158 | + if: always() |
| 159 | + run: | |
| 160 | + make controlplane.dump |
| 161 | +
|
| 162 | + - name: Upload Cluster Dump |
| 163 | + if: always() |
| 164 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
| 165 | + with: |
| 166 | + name: controlplane-dump |
| 167 | + path: ./_output/controlplane-dump |
| 168 | + |
| 169 | + - name: Cleanup |
| 170 | + if: always() |
| 171 | + run: | |
| 172 | + eval $(make --no-print-directory build.vars) |
| 173 | + ${KUBECTL} delete managed --all || true |
| 174 | +
|
| 175 | + - name: Create Unsuccessful Status Check |
| 176 | + if: failure() |
| 177 | + env: |
| 178 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 179 | + EXAMPLE_HASH: ${{ needs.get-example-list.outputs.example_hash }} |
| 180 | + run: | |
| 181 | + gh api \ |
| 182 | + --method POST \ |
| 183 | + -H "Accept: application/vnd.github+json" \ |
| 184 | + /repos/${{ github.repository }}/statuses/${{ steps.checkout-pr.outputs.commit-sha }} \ |
| 185 | + -f state='failure' \ |
| 186 | + -f target_url='https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' \ |
| 187 | + -f description='Failed' \ |
| 188 | + -f context="Uptest-${EXAMPLE_HASH}" |
0 commit comments