|
| 1 | +name: Run go-scalr tests on pr in any other repo |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + inputs: |
| 5 | + repo: |
| 6 | + description: The repository with pull request |
| 7 | + required: true |
| 8 | + pr_id: |
| 9 | + description: The number of the pull request |
| 10 | + required: true |
| 11 | + pr_head_sha: |
| 12 | + description: The head sha of the pull request |
| 13 | + required: true |
| 14 | + pr_branch: |
| 15 | + description: Pull request branch |
| 16 | + base_branch: |
| 17 | + description: Base branch of pull request |
| 18 | +concurrency: |
| 19 | + group: ${{ github.ref }}-${{ github.workflow }} |
| 20 | + cancel-in-progress: true |
| 21 | + |
| 22 | +jobs: |
| 23 | + tests: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + name: tests |
| 26 | + env: |
| 27 | + SCALR_TOKEN: ${{ secrets.SCALR_TOKEN }} |
| 28 | + UPSTREAM_ID: ${{ github.run_number }} |
| 29 | + steps: |
| 30 | + - uses: actions/checkout@v3 |
| 31 | + - name: Log pr link |
| 32 | + run: | |
| 33 | + echo ":taco: Pull request: https://github.com/Scalr/${{ inputs.repo }}/pull/${{ inputs.pr_id }} " >> $GITHUB_STEP_SUMMARY |
| 34 | + - name: Get current job log URL |
| 35 | + uses: Tiryoh/gha-jobid-action@v0 |
| 36 | + id: get-job-id |
| 37 | + with: |
| 38 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 39 | + job_name: ${{ github.job }} |
| 40 | + - name: Set pending status |
| 41 | + uses: actions/github-script@v3 |
| 42 | + with: |
| 43 | + github-token: ${{ secrets.GH_PAT }} |
| 44 | + script: | |
| 45 | + github.repos.createCommitStatus({ |
| 46 | + owner: 'Scalr', |
| 47 | + repo: '${{ inputs.repo }}', |
| 48 | + sha: '${{ inputs.pr_head_sha }}', |
| 49 | + state: 'pending', |
| 50 | + description: 'Starting go-scalr tests', |
| 51 | + context: 'go-scalr', |
| 52 | + target_url: '${{ steps.get-job-id.outputs.html_url }}', |
| 53 | + }) |
| 54 | + - uses: actions/setup-go@v3 |
| 55 | + with: |
| 56 | + go-version: "1.18" |
| 57 | + - name: Clone fatmouse repo |
| 58 | + uses: actions/checkout@v3 |
| 59 | + with: |
| 60 | + repository: Scalr/fatmouse |
| 61 | + path: fatmouse |
| 62 | + token: ${{ secrets.GH_PAT }} |
| 63 | + - name: Set DB_BRANCH |
| 64 | + if: ${{ contains(github.event.head_commit.message, '[DB_BRANCH]') }} |
| 65 | + run: echo "DB_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV |
| 66 | + - id: auth |
| 67 | + uses: google-github-actions/auth@v0 |
| 68 | + with: |
| 69 | + credentials_json: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }} |
| 70 | + - name: Set up Cloud SDK |
| 71 | + uses: google-github-actions/setup-gcloud@v0 |
| 72 | + - name: Copy secrets |
| 73 | + shell: bash |
| 74 | + run: | |
| 75 | + mkdir ~/.scalr-labs |
| 76 | + gsutil cp gs://drone_bucket/prod/private.d/.secrets.yaml fatmouse/tacobell/.secrets.yaml |
| 77 | + gsutil cp gs://drone_bucket/prod/private.d/github.json ~/.scalr-labs/github.json |
| 78 | + - name: Configure docker |
| 79 | + shell: bash |
| 80 | + run: gcloud auth configure-docker eu.gcr.io |
| 81 | + - name: Pull python builder |
| 82 | + shell: bash |
| 83 | + run: | |
| 84 | + echo "::group::Pull python builder image" |
| 85 | + docker pull eu.gcr.io/development-156220/fatmouse/python-builder:master |
| 86 | + docker tag eu.gcr.io/development-156220/fatmouse/python-builder:master fatmouse/python-builder:master |
| 87 | + echo "::endgroup::" |
| 88 | + - name: Get current job log URL |
| 89 | + uses: Tiryoh/gha-jobid-action@v0 |
| 90 | + id: get-job-id |
| 91 | + with: |
| 92 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 93 | + job_name: ${{ github.job }} |
| 94 | + - name: Generate run tag |
| 95 | + shell: bash |
| 96 | + run: | |
| 97 | + if [ ${{ github.run_attempt }} = 1 ]; then |
| 98 | + RERUN_SUFFIX="" |
| 99 | + else |
| 100 | + RERUN_SUFFIX=$(echo -${{ github.run_attempt }}) |
| 101 | + fi |
| 102 | + echo "RUN_TAG=e2e-${{ github.workflow }}-${{ github.job }}-${{ github.run_number }}${RERUN_SUFFIX}" >> $GITHUB_ENV |
| 103 | + - name: Create container |
| 104 | + id: create |
| 105 | + shell: bash |
| 106 | + run: | |
| 107 | + FATMOUSE_BRANCH="--fatmouse-branch ${{ inputs.pr_branch }}" |
| 108 | + SCALR_BRANCH="--scalr-branch ${{ inputs.pr_branch }}" |
| 109 | +
|
| 110 | + TEV2_BRANCH=${{ inputs.pr_branch }} |
| 111 | + NORMALIZED_BRANCH=$(echo $TEV2_BRANCH | tr / - | tr '[:upper:]' '[:lower:]') |
| 112 | + if docker manifest inspect eu.gcr.io/development-156220/fatmouse/scalr-server-te:${NORMALIZED_BRANCH} ; then |
| 113 | + IMAGE="--scalr-server-image-tag ${NORMALIZED_BRANCH}" |
| 114 | + else |
| 115 | + if [[ "${{ inputs.base_branch }}" == release/* ]]; then |
| 116 | + NORMALIZED_IMAGE=$(echo "${{ inputs.base_branch }}" | tr / - | tr '[:upper:]' '[:lower:]') |
| 117 | + IMAGE="--scalr-server-image-tag ${NORMALIZED_IMAGE}" |
| 118 | + else |
| 119 | + IMAGE="" |
| 120 | + fi |
| 121 | + fi |
| 122 | +
|
| 123 | + docker run --rm \ |
| 124 | + -e GITHUB_WORKSPACE=true \ |
| 125 | + -e GITHUB_OUTPUT=/fatmouse/output \ |
| 126 | + -w /fatmouse \ |
| 127 | + -v $PWD/fatmouse:/fatmouse \ |
| 128 | + -v $GITHUB_OUTPUT:/fatmouse/output \ |
| 129 | + -v ~/.scalr-labs:/etc/scalr-labs \ |
| 130 | + fatmouse/python-builder:master python -u clickfile.py te up \ |
| 131 | + ${FATMOUSE_BRANCH} ${SCALR_BRANCH} ${IMAGE} \ |
| 132 | + --run-url ${{ steps.get-job-id.outputs.html_url }} \ |
| 133 | + --skip-ui-build \ |
| 134 | + --cpu=1 \ |
| 135 | + --ram=2G \ |
| 136 | + ${{ env.RUN_TAG }} |
| 137 | + - name: Run tests |
| 138 | + id: run-tests |
| 139 | + env: |
| 140 | + SCALR_ADDRESS: ${{ steps.create.outputs.host }} |
| 141 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 142 | + TEST_AWS_ACCESS_KEY: ${{ secrets.TEST_AWS_ACCESS_KEY }} |
| 143 | + TEST_AWS_SECRET_KEY: ${{ secrets.TEST_AWS_SECRET_KEY }} |
| 144 | + TEST_AWS_ROLE_ARN: ${{ secrets.TEST_AWS_ROLE_ARN }} |
| 145 | + TEST_AWS_EXTERNAL_ID: ${{ secrets.TEST_AWS_EXTERNAL_ID }} |
| 146 | + TEST_ARM_CLIENT_ID: ${{ secrets.TEST_ARM_CLIENT_ID }} |
| 147 | + TEST_ARM_CLIENT_SECRET: ${{ secrets.TEST_ARM_CLIENT_SECRET }} |
| 148 | + TEST_ARM_TENANT_ID: ${{ secrets.TEST_ARM_TENANT_ID }} |
| 149 | + TEST_ARM_SUBSCRIPTION_ID: ${{ secrets.TEST_ARM_SUBSCRIPTION_ID }} |
| 150 | + run: make test |
| 151 | + - name: Set commit status after tests |
| 152 | + if: ${{ always() && (steps.run-tests.outcome == 'failure' || steps.run-tests.outcome == 'success') }} |
| 153 | + uses: actions/github-script@v3 |
| 154 | + with: |
| 155 | + github-token: ${{ secrets.GH_PAT }} |
| 156 | + script: | |
| 157 | + github.repos.createCommitStatus({ |
| 158 | + owner: 'Scalr', |
| 159 | + repo: '${{ inputs.repo }}', |
| 160 | + sha: '${{ inputs.pr_head_sha }}', |
| 161 | + state: '${{ steps.run-tests.outcome }}', |
| 162 | + description: 'go-scalr tests result: ${{ steps.run-tests.outcome }}', |
| 163 | + context: 'go-scalr', |
| 164 | + target_url: '${{ steps.get-job-id.outputs.html_url }}', |
| 165 | + }) |
| 166 | + - name: Set commit status on interrupted workflow |
| 167 | + if: ${{ always() && steps.run-tests.outcome != 'failure' && steps.run-tests.outcome != 'success' }} |
| 168 | + uses: actions/github-script@v3 |
| 169 | + with: |
| 170 | + github-token: ${{ secrets.GH_TOKEN }} |
| 171 | + script: | |
| 172 | + github.repos.createCommitStatus({ |
| 173 | + owner: 'Scalr', |
| 174 | + repo: '${{ inputs.repo }}', |
| 175 | + sha: '${{ inputs.pr_head_sha }}', |
| 176 | + state: 'error', |
| 177 | + description: 'go-scalr workflow was interrupted', |
| 178 | + context: 'go-scalr', |
| 179 | + target_url: '${{ steps.get-job-id.outputs.html_url }}', |
| 180 | + }) |
| 181 | + - name: Add comment on failed tests |
| 182 | + if: ${{ always() && steps.run-tests.outcome == 'failure' }} |
| 183 | + uses: actions/github-script@v5 |
| 184 | + with: |
| 185 | + script: | |
| 186 | + const issue_number = ${{ inputs.pr_id }}; |
| 187 | + const owner = 'Scalr'; |
| 188 | + const repo = '${{ inputs.repo }}'; |
| 189 | + const message = '**go-scalr tests failed**\nJob url ${{ steps.get-job-id.outputs.html_url }}'; |
| 190 | + await github.rest.issues.createComment({owner, repo, issue_number, body: message}); |
| 191 | + github-token: ${{ secrets.GH_PAT }} |
| 192 | + - name: Delete container |
| 193 | + id: delete |
| 194 | + if: ${{ always() }} |
| 195 | + shell: bash |
| 196 | + run: | |
| 197 | + docker run --rm \ |
| 198 | + -w /fatmouse \ |
| 199 | + -v $PWD/fatmouse:/fatmouse \ |
| 200 | + -v ~/.scalr-labs:/etc/scalr-labs \ |
| 201 | + fatmouse/python-builder:master \ |
| 202 | + python -u clickfile.py te rm \ |
| 203 | + --no-wait ${{ env.RUN_TAG }} |
0 commit comments