|
| 1 | +name: e2e |
| 2 | +on: |
| 3 | + issue_comment: |
| 4 | + types: [created] |
| 5 | + |
| 6 | +env: |
| 7 | + E2E_CHECK_NAME: e2e tests |
| 8 | + |
| 9 | +jobs: |
| 10 | + triage: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + name: Comment evaluate |
| 13 | + outputs: |
| 14 | + run-e2e: ${{ startsWith(github.event.comment.body,'/run-e2e') && steps.checkUserMember.outputs.isTeamMember == 'true' }} |
| 15 | + pr_num: ${{ steps.parser.outputs.pr_num }} |
| 16 | + image_tag: "pr-${{ steps.parser.outputs.pr_num }}-${{ steps.parser.outputs.commit_sha }}" |
| 17 | + commit_sha: ${{ steps.parser.outputs.commit_sha }} |
| 18 | + version_buildflags: ${{ steps.parser.outputs.version_buildflags }} |
| 19 | + image_build_hash: ${{ steps.parser.outputs.image_build_hash }} |
| 20 | + |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v3 |
| 23 | + |
| 24 | + - uses: tspascoal/get-user-teams-membership@v2 |
| 25 | + id: checkUserMember |
| 26 | + with: |
| 27 | + username: ${{ github.actor }} |
| 28 | + team: 'dev' |
| 29 | + GITHUB_TOKEN: ${{ secrets.GH_CHECKING_USER_AUTH }} |
| 30 | + |
| 31 | + - name: Update comment with the execution url |
| 32 | + if: ${{ startsWith(github.event.comment.body,'/run-e2e') && steps.checkUserMember.outputs.isTeamMember == 'true' }} |
| 33 | + uses: peter-evans/create-or-update-comment@v2 |
| 34 | + with: |
| 35 | + comment-id: ${{ github.event.comment.id }} |
| 36 | + body: | |
| 37 | + **Update:** You can check the progress [here](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}) |
| 38 | + reactions: rocket |
| 39 | + |
| 40 | + - name: Parse git info |
| 41 | + if: ${{ startsWith(github.event.comment.body,'/run-e2e') && steps.checkUserMember.outputs.isTeamMember == 'true' }} |
| 42 | + id: parser |
| 43 | + env: |
| 44 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 45 | + run: | |
| 46 | + # Get PR number |
| 47 | + PR_URL="${{ github.event.issue.pull_request.url }}" |
| 48 | + PR_NUM=${PR_URL##*/} |
| 49 | + echo "Checking out from PR #$PR_NUM based on URL: $PR_URL" |
| 50 | + echo "::set-output name=pr_num::$PR_NUM" |
| 51 | + # Get commit SHA |
| 52 | + git config --global --add safe.directory "$GITHUB_WORKSPACE" |
| 53 | + gh pr checkout $PR_NUM |
| 54 | + SHA=$(git log -n 1 --pretty=format:"%H") |
| 55 | + echo "::set-output name=commit_sha::$SHA" |
| 56 | + GIT_COMMIT=$(git describe --match=NeVeRmAtCh --tags --always --dirty | cut -c 1-7) |
| 57 | + BUILD_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ) |
| 58 | + VERSION=$(git describe --tags `git rev-list --tags --max-count=1` | sed 's/v\(\)/\1/') |
| 59 | + PKG=github.com/bentoml/yatai-image-builder |
| 60 | + VERSION_BUILDFLAGS="-X '${PKG}/version.GitCommit=${GIT_COMMIT}' -X '${PKG}/version.Version=${VERSION}' -X '${PKG}/version.BuildDate=${BUILD_DATE}'" |
| 61 | + echo "::set-output name=version_buildflags::$VERSION_BUILDFLAGS" |
| 62 | + echo "::set-output name=image_build_hash::${{ hashFiles('Dockerfile', 'main.go', './apis/**', './controllers/**', './utils/**', './version/**', './yatai-client/**', '**/go.sum', '**go.mod') }}" |
| 63 | +
|
| 64 | + build-test-images: |
| 65 | + needs: triage |
| 66 | + if: needs.triage.outputs.run-e2e == 'true' |
| 67 | + runs-on: ubuntu-latest |
| 68 | + steps: |
| 69 | + - name: Set status in-progress |
| 70 | + uses: LouisBrunner/[email protected] |
| 71 | + with: |
| 72 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 73 | + sha: ${{ needs.triage.outputs.commit_sha }} |
| 74 | + name: ${{ env.E2E_CHECK_NAME }} |
| 75 | + status: in_progress |
| 76 | + details_url: https://github.com/${{github.repository}}/actions/runs/${{github.run_id}} |
| 77 | + |
| 78 | + - uses: actions/checkout@v3 |
| 79 | + |
| 80 | + - name: Register workspace path |
| 81 | + run: git config --global --add safe.directory "$GITHUB_WORKSPACE" |
| 82 | + |
| 83 | + - name: Checkout Pull Request |
| 84 | + env: |
| 85 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 86 | + id: checkout |
| 87 | + run: | |
| 88 | + gh pr checkout ${{ needs.triage.outputs.pr_num }} |
| 89 | +
|
| 90 | + - name: Set up Docker Buildx |
| 91 | + id: buildx |
| 92 | + # Use the action from the master, as we've seen some inconsistencies with @v1 |
| 93 | + # Issue: https://github.com/docker/build-push-action/issues/286 |
| 94 | + uses: docker/setup-buildx-action@master |
| 95 | + with: |
| 96 | + install: true |
| 97 | + |
| 98 | + - name: Login to Quay.io |
| 99 | + uses: docker/login-action@v1 |
| 100 | + with: |
| 101 | + registry: quay.io |
| 102 | + username: ${{ secrets.QUAY_USERNAME }} |
| 103 | + password: ${{ secrets.QUAY_ROBOT_TOKEN }} |
| 104 | + |
| 105 | + - name: Cache Docker layers |
| 106 | + uses: actions/cache@v2 |
| 107 | + with: |
| 108 | + path: /tmp/.buildx-cache |
| 109 | + # Key is named differently to avoid collision |
| 110 | + key: ${{ runner.os }}-multi-buildx-${{ needs.triage.outputs.image_build_hash }} |
| 111 | + restore-keys: | |
| 112 | + ${{ runner.os }}-multi-buildx |
| 113 | +
|
| 114 | + - name: Build test image |
| 115 | + uses: docker/build-push-action@v2 |
| 116 | + with: |
| 117 | + build-args: 'VERSION_BUILDFLAGS=${{ needs.triage.outputs.version_buildflags }}' |
| 118 | + context: . |
| 119 | + push: true |
| 120 | + tags: quay.io/bentoml/test-yatai-image-builder:${{ needs.triage.outputs.image_tag }} |
| 121 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 122 | + # Note the mode=max here |
| 123 | + # More: https://github.com/moby/buildkit#--export-cache-options |
| 124 | + # And: https://github.com/docker/buildx#--cache-tonametypetypekeyvalue |
| 125 | + cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new |
| 126 | + |
| 127 | + - name: Move cache |
| 128 | + run: | |
| 129 | + rm -rf /tmp/.buildx-cache |
| 130 | + mv /tmp/.buildx-cache-new /tmp/.buildx-cache |
| 131 | +
|
| 132 | + run-test: |
| 133 | + needs: [triage, build-test-images] |
| 134 | + if: needs.triage.outputs.run-e2e == 'true' |
| 135 | + runs-on: ubuntu-latest |
| 136 | + steps: |
| 137 | + - name: Set status in-progress |
| 138 | + uses: LouisBrunner/[email protected] |
| 139 | + with: |
| 140 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 141 | + sha: ${{ needs.triage.outputs.commit_sha }} |
| 142 | + name: ${{ env.E2E_CHECK_NAME }} |
| 143 | + status: in_progress |
| 144 | + details_url: https://github.com/${{github.repository}}/actions/runs/${{github.run_id}} |
| 145 | + |
| 146 | + - name: Checkout |
| 147 | + uses: actions/checkout@v3 |
| 148 | + |
| 149 | + - name: Register workspace path |
| 150 | + run: git config --global --add safe.directory "$GITHUB_WORKSPACE" |
| 151 | + |
| 152 | + - name: Checkout Pull Request |
| 153 | + env: |
| 154 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 155 | + id: checkout |
| 156 | + run: | |
| 157 | + gh pr checkout ${{ needs.triage.outputs.pr_num }} |
| 158 | +
|
| 159 | + - name: Install KinD |
| 160 | + run: ./tests/gh-actions/install_kind.sh |
| 161 | + |
| 162 | + - name: Install Helm |
| 163 | + run: ./tests/gh-actions/install_helm.sh |
| 164 | + |
| 165 | + - name: Create KinD Cluster |
| 166 | + run: kind create cluster --config tests/gh-actions/kind-cluster-1-24.yaml |
| 167 | + |
| 168 | + - uses: oNaiPs/secrets-to-env-action@v1 |
| 169 | + with: |
| 170 | + secrets: ${{ toJSON(secrets) }} |
| 171 | + |
| 172 | + - name: Run e2e test |
| 173 | + continue-on-error: true |
| 174 | + id: test |
| 175 | + env: |
| 176 | + YATAI_DEPLOYMENT_IMG_REPO: test-yatai-image-builder |
| 177 | + YATAI_DEPLOYMENT_IMG_TAG: ${{ needs.triage.outputs.image_tag }} |
| 178 | + run: | |
| 179 | + ./tests/e2e/installation_test.sh |
| 180 | + make test-e2e |
| 181 | +
|
| 182 | + - name: Set status success |
| 183 | + uses: LouisBrunner/[email protected] |
| 184 | + if: steps.test.outcome == 'success' |
| 185 | + with: |
| 186 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 187 | + sha: ${{ needs.triage.outputs.commit_sha }} |
| 188 | + name: ${{ env.E2E_CHECK_NAME }} |
| 189 | + conclusion: success |
| 190 | + details_url: https://github.com/${{github.repository}}/actions/runs/${{github.run_id}} |
| 191 | + |
| 192 | + - name: React to comment with success |
| 193 | + uses: dkershner6/reaction-action@v1 |
| 194 | + if: steps.test.outcome == 'success' |
| 195 | + with: |
| 196 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 197 | + commentId: ${{ github.event.comment.id }} |
| 198 | + reaction: "hooray" |
| 199 | + |
| 200 | + - name: React to comment with failure |
| 201 | + uses: dkershner6/reaction-action@v1 |
| 202 | + if: steps.test.outcome != 'success' |
| 203 | + with: |
| 204 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 205 | + commentId: ${{ github.event.comment.id }} |
| 206 | + reaction: "confused" |
| 207 | + |
| 208 | + - name: Set status failure |
| 209 | + uses: LouisBrunner/[email protected] |
| 210 | + if: steps.test.outcome != 'success' |
| 211 | + with: |
| 212 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 213 | + sha: ${{ needs.triage.outputs.commit_sha }} |
| 214 | + name: ${{ env.E2E_CHECK_NAME }} |
| 215 | + conclusion: failure |
| 216 | + details_url: https://github.com/${{github.repository}}/actions/runs/${{github.run_id}} |
0 commit comments