From db5d0b68b926d43c0ced9b2d80f76cf3c85dcb87 Mon Sep 17 00:00:00 2001 From: konrad Date: Wed, 2 Oct 2024 10:20:54 +0200 Subject: [PATCH] [SYSE-394 master] Fix test code base for Tyk-Analytics PRs (#6583) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### **User description** A PR has been created by to address the PRs on tyk-analytics checking out the wrong base (base branch) when working on a pull-request over the tyk-analytics repo.In this case developers would want to checkout the HEAD of the branch instead of the BASE so they can have their new tests in place for the PR.PR being worked out under QA board: https://github.com/TykTechnologies/gromit/pull/346 ___ ### **PR Type** enhancement, tests ___ ### **Description** - Enhanced the release workflow by adding concurrency control to cancel in-progress workflows for pull requests. - Updated the Docker build-push-action version from v5 to v6 for improved functionality. - Introduced new steps to upload Playwright test reports to S3 and share the report links in the summary. - Modified environment variables and conditions for executing jobs, including changes to the `VARIATION` and `BASE_REF` variables. - Added conditions to ensure that certain jobs only run when the pull request is not a draft. ___ ### **Changes walkthrough** 📝
Relevant files
Enhancement
release.yml
Enhance release workflow with concurrency and reporting improvements

.github/workflows/release.yml
  • Added concurrency control to cancel in-progress workflows for pull
    requests.
  • Changed Docker build-push-action version from v5 to v6.
  • Added steps to upload Playwright test reports to S3 and share report
    links.
  • Modified environment variables and conditions for job execution.
  • +37/-19 
    ___ > 💡 **PR-Agent usage**: Comment `/help "your question"` on any pull request to receive relevant information Co-authored-by: Gromit --- .github/workflows/release.yml | 65 ++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 20 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d6e025b1865..cf7fec94016 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,7 +1,5 @@ # yamllint disable rule:line-length rule:truthy ---- name: Release - # Generated by: gromit policy # Distribution channels covered by this workflow @@ -10,11 +8,9 @@ name: Release # - docker hub # - devenv ECR # - Cloudsmith - concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: ${{ github.event_name == 'pull_request' }} - on: # Trigger release every monday at midnight for master CI images schedule: @@ -28,13 +24,14 @@ on: - 'v*' env: GOPRIVATE: github.com/TykTechnologies - VARIATION: prod + VARIATION: inverted DOCKER_BUILD_SUMMARY: false DOCKER_BUILD_RECORD_UPLOAD: false # startsWith covers pull_request_target too BASE_REF: ${{startsWith(github.event_name, 'pull_request') && github.base_ref || github.ref_name}} jobs: goreleaser: + if: github.event.pull_request.draft == false name: '${{ matrix.golang_cross }}' runs-on: ubuntu-latest-m permissions: @@ -87,9 +84,9 @@ jobs: path: | ~/.cache/go-build ~/go/pkg/mod - key: ${{ runner.os }}-${{ matrix.golang_cross }}-go-${{ hashFiles('**/go.sum') }} + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} restore-keys: | - ${{ runner.os }}-${{ matrix.golang_cross }}-go-${{ hashFiles('**/go.sum') }} + ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - name: Build env: NFPM_PASSPHRASE: ${{ secrets.SIGNING_KEY_PASSPHRASE }} @@ -173,13 +170,12 @@ jobs: latest=false prefix=v tags: | - type=semver,pattern={{major}} type=semver,pattern={{major}}.{{minor}} type=semver,pattern={{version}} labels: "org.opencontainers.image.title=tyk-gateway (distroless) \norg.opencontainers.image.description=Tyk Open Source API Gateway written in Go, supporting REST, GraphQL, TCP and gRPC protocols\norg.opencontainers.image.vendor=tyk.io\norg.opencontainers.image.version=${{ github.ref_name }}\n" - - name: build multiarch image + - name: push image to prod if: ${{ matrix.golang_cross == '1.22-bullseye' }} - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: context: "dist" platforms: linux/amd64,linux/arm64 @@ -191,14 +187,19 @@ jobs: push: ${{ startsWith(github.ref, 'refs/tags') }} tags: ${{ steps.tag_metadata.outputs.tags }} labels: ${{ steps.tag_metadata.outputs.labels }} - - uses: actions/upload-artifact@v4 + - name: save deb + uses: actions/upload-artifact@v4 + if: ${{ matrix.golang_cross == '1.22-bullseye' }} with: name: deb retention-days: 1 path: | dist/*.deb !dist/*PAYG*.deb - - uses: actions/upload-artifact@v4 + !dist/*fips*.deb + - name: save rpm + uses: actions/upload-artifact@v4 + if: ${{ matrix.golang_cross == '1.22-bullseye' }} with: name: rpm retention-days: 1 @@ -207,6 +208,7 @@ jobs: !dist/*PAYG*.rpm !dist/*fips*.rpm test-controller-api: + if: github.event.pull_request.draft == false needs: - goreleaser runs-on: ubuntu-latest @@ -302,21 +304,43 @@ jobs: ./dash-bootstrap.sh http://localhost:3000 docker compose -p auto -f pro-ha.yml -f deps_pro-ha.yml -f ${{ matrix.envfiles.db }}.yml -f ${{ matrix.envfiles.cache }}.yml --env-file versions.env --profile slave-datacenter up --quiet-pull -d echo "$(cat pytest.env | grep USER_API_SECRET)" >> $GITHUB_OUTPUT + echo "ts=$(date +%s%N)" >> $GITHUB_OUTPUT - uses: actions/checkout@v4 with: repository: TykTechnologies/tyk-analytics path: tyk-analytics token: ${{ secrets.ORG_GH_TOKEN }} - fetch-depth: 1 + fetch-depth: 0 sparse-checkout: tests/api - - name: Branch for test code - id: timestamp + - name: Choosing test code branch working-directory: tyk-analytics/tests/api run: | - # Generate report id - git fetch --no-tags --depth 1 origin "refs/heads/${BASE_REF}:refs/remotes/origin/${BASE_REF}" - git switch $BASE_REF - echo "ts=$(date +%s%N)" >> $GITHUB_OUTPUT + if [[ ${{ github.event_name }} == "release" ]]; then + echo "Checking out release tag..." + TAG_NAME=${{ github.event.release.tag_name }} + git checkout "$TAG_NAME" + fi + if [[ ${{ github.event_name }} == "pull_request" ]]; then + PR_BRANCH=${{ github.event.pull_request.head.ref }} + TARGET_BRANCH=${{ github.event.pull_request.base.ref }} + echo "Looking for PR_BRANCH:$PR_BRANCH or TARGET_BRANCH:$TARGET_BRANCH..." + if git rev-parse --verify "origin/$PR_BRANCH" >/dev/null 2>&1; then + echo "PR branch $PR_BRANCH exists. Checking out..." + git checkout "$PR_BRANCH" + elif git rev-parse --verify "origin/$TARGET_BRANCH" >/dev/null 2>&1; then + echo "Target branch $TARGET_BRANCH exists. Checking out..." + git checkout "$TARGET_BRANCH" + fi + fi + if [[ ${{ github.event_name }} == "push" ]]; then + PUSH_BRANCH=${{ github.ref_name }} + echo "Looking for PUSH_BRANCH:$PUSH_BRANCH..." + if git rev-parse --verify "origin/$PUSH_BRANCH" >/dev/null 2>&1; then + echo "Push branch $PUSH_BRANCH exists. Checking out..." + git checkout "$PUSH_BRANCH" + fi + fi + echo "Current commit: $(git rev-parse HEAD)" - uses: actions/setup-python@v5 with: cache: 'pip' @@ -349,7 +373,7 @@ jobs: id: metadata_report if: always() && (steps.test_execution.conclusion != 'skipped') env: - REPORT_NAME: ${{ github.repository }}_${{ github.run_id }}_${{ github.run_attempt }}-${{steps.timestamp.outputs.ts}} + REPORT_NAME: ${{ github.repository }}_${{ github.run_id }}_${{ github.run_attempt }}-${{steps.env_up.outputs.ts}} METADATA_REPORT_PATH: metadata.toml run: | # Generate metadata report @@ -392,6 +416,7 @@ jobs: retention-days: 3 overwrite: true test-controller-distros: + if: github.event.pull_request.draft == false needs: - goreleaser runs-on: ubuntu-latest