Run go-scalr tests on pr in any other repo #3315
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Run go-scalr tests on pr in any other repo | |
on: | |
workflow_dispatch: | |
inputs: | |
repo: | |
description: The repository with pull request | |
required: true | |
pr_id: | |
description: The number of the pull request | |
required: true | |
pr_head_sha: | |
description: The head sha of the pull request | |
required: true | |
pr_branch: | |
description: Pull request branch | |
base_branch: | |
description: Base branch of pull request | |
jobs: | |
tests: | |
name: Tests | |
runs-on: ubuntu-latest | |
concurrency: | |
group: ${{ github.workflow }}-${{ inputs.pr_id }} | |
cancel-in-progress: true | |
env: | |
SCALR_TOKEN: ${{ secrets.SCALR_TOKEN }} | |
UPSTREAM_ID: ${{ github.run_number }} | |
steps: | |
- name: Sudo GitHub Token | |
id: generate_token | |
uses: tibdex/github-app-token@v1 | |
with: | |
app_id: ${{vars.SUDO_GHA_APP_ID}} | |
installation_id: ${{vars.SUDO_GHA_APP_INSTALLATION_ID}} | |
private_key: ${{secrets.SUDO_GHA_APP_PRIVATE_KEY}} | |
- uses: actions/checkout@v4 | |
- name: Log PR Link | |
run: | | |
echo ":taco: Pull request: https://github.com/Scalr/${{ inputs.repo }}/pull/${{ inputs.pr_id }} " >> $GITHUB_STEP_SUMMARY | |
- name: Get Current Job Log URL | |
uses: Tiryoh/gha-jobid-action@v1 | |
id: get-job-id | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
job_name: Tests | |
- name: Set Pending Status | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{steps.generate_token.outputs.token}} | |
script: | | |
github.rest.repos.createCommitStatus({ | |
owner: 'Scalr', | |
repo: '${{ inputs.repo }}', | |
sha: '${{ inputs.pr_head_sha }}', | |
state: 'pending', | |
description: 'Starting go-scalr tests', | |
context: 'go-scalr', | |
target_url: '${{ steps.get-job-id.outputs.html_url }}', | |
}) | |
- uses: actions/setup-go@v5 | |
with: | |
go-version: "1.18" | |
- name: Clone Fatmouse Repository | |
uses: actions/checkout@v4 | |
with: | |
repository: Scalr/fatmouse | |
path: fatmouse | |
ref: ${{ inputs.pr_branch }} | |
token: ${{steps.generate_token.outputs.token}} | |
- name: Get PR Labels | |
id: pr-labels | |
uses: ./fatmouse/.github/actions/pr-labels | |
with: | |
github_token: ${{steps.generate_token.outputs.token}} | |
owner: Scalr | |
repo: fatmouse | |
pr_id: ${{ inputs.pr_id }} | |
- uses: ./fatmouse/.github/actions/preview-env | |
name: Create preview environment | |
id: create-preview-env | |
env: | |
JOB_NAME: Tests | |
with: | |
ref: ${{ inputs.pr_branch }} | |
github_token: ${{ steps.generate_token.outputs.token }} | |
google_cloud_credentials: ${{ secrets.GCP_SA_KEY }} | |
run_prefix: e2e-go-scalr-pr | |
deployment_type: saas | |
prepare_runner: true | |
wait_for_env: true | |
no_segment: true | |
agent_pool_id: ${{ !contains(steps.pr-labels.outputs.labels, ' e2e:tev2_on_server ') && vars.TACO_APOOL_ID || '' }} | |
working_directory: fatmouse | |
secrets_bucket: tacobell-secrets | |
- name: Get Scalr Hostname | |
shell: bash | |
run: | | |
SCALR_HOST=${{ steps.create-preview-env.outputs.host }} | |
echo "SCALR_ADDRESS=https://mainiacp.${SCALR_HOST/https:\/\//}" >> $GITHUB_ENV | |
- name: Run Tests | |
id: run-tests | |
env: | |
SCALR_ADDRESS: ${{ env.SCALR_ADDRESS }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
TEST_AWS_ACCESS_KEY: ${{ secrets.TEST_AWS_ACCESS_KEY }} | |
TEST_AWS_SECRET_KEY: ${{ secrets.TEST_AWS_SECRET_KEY }} | |
TEST_AWS_ROLE_ARN: ${{ secrets.TEST_AWS_ROLE_ARN }} | |
TEST_AWS_EXTERNAL_ID: ${{ secrets.TEST_AWS_EXTERNAL_ID }} | |
TEST_ARM_CLIENT_ID: ${{ secrets.TEST_ARM_CLIENT_ID }} | |
TEST_ARM_CLIENT_SECRET: ${{ secrets.TEST_ARM_CLIENT_SECRET }} | |
TEST_ARM_TENANT_ID: ${{ secrets.TEST_ARM_TENANT_ID }} | |
TEST_ARM_SUBSCRIPTION_ID: ${{ secrets.TEST_ARM_SUBSCRIPTION_ID }} | |
run: make test | |
- name: Set Commit Status After Tests | |
if: ${{ always() && (steps.run-tests.outcome == 'failure' || steps.run-tests.outcome == 'success') }} | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{steps.generate_token.outputs.token}} | |
script: | | |
github.rest.repos.createCommitStatus({ | |
owner: 'Scalr', | |
repo: '${{ inputs.repo }}', | |
sha: '${{ inputs.pr_head_sha }}', | |
state: '${{ steps.run-tests.outcome }}', | |
description: 'go-scalr tests result: ${{ steps.run-tests.outcome }}', | |
context: 'go-scalr', | |
target_url: '${{ steps.get-job-id.outputs.html_url }}', | |
}) | |
- name: Set Commit Status on Interrupted Workflow | |
if: ${{ always() && steps.run-tests.outcome != 'failure' && steps.run-tests.outcome != 'success' }} | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{steps.generate_token.outputs.token}} | |
script: | | |
github.rest.repos.createCommitStatus({ | |
owner: 'Scalr', | |
repo: '${{ inputs.repo }}', | |
sha: '${{ inputs.pr_head_sha }}', | |
state: 'error', | |
description: 'go-scalr workflow was interrupted', | |
context: 'go-scalr', | |
target_url: '${{ steps.get-job-id.outputs.html_url }}', | |
}) | |
- name: Add Comment on Failed Tests | |
if: ${{ always() && steps.run-tests.outcome == 'failure' }} | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const issue_number = ${{ inputs.pr_id }}; | |
const owner = 'Scalr'; | |
const repo = '${{ inputs.repo }}'; | |
const message = '**go-scalr tests failed**\nJob url ${{ steps.get-job-id.outputs.html_url }}'; | |
await github.rest.issues.createComment({owner, repo, issue_number, body: message}); | |
github-token: ${{steps.generate_token.outputs.token}} | |
- name: Delete Container | |
id: delete | |
if: ${{ always() }} | |
working-directory: fatmouse | |
shell: bash | |
run: | | |
python -u clickfile.py te rm --no-wait ${{ steps.create-preview-env.outputs.env_name }} |