From 43f9aef2de043f9826a3b7ca5545d003a2585d99 Mon Sep 17 00:00:00 2001 From: Ignacio Aldama Vicente Date: Thu, 2 Nov 2023 17:04:55 +0100 Subject: [PATCH] test: improve E2E CI --- .github/workflows/ci.yml | 77 +++++++++++++++++++++++++++++++++++ .github/workflows/linux.yml | 5 +-- .github/workflows/macos.yml | 7 +--- .github/workflows/windows.yml | 5 +-- 4 files changed, 81 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..afcb4fa --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,77 @@ +name: E2E Tests + +on: + pull_request: + branches: + - '**' + push: + branches: + - '**' + +jobs: + get-team-members: + runs-on: ubuntu-latest + outputs: + team-members: ${{ steps.get-team-members.outputs.team-members }} + steps: + - name: Get team members from GitHub API + id: get-team-members + run: | + TEAM_MEMBERS=$(gh api /orgs/pnpm/teams/collaborators/members --paginate | jq -r '.[].login' | paste -sd, -) + echo "team-members=$TEAM_MEMBERS" >> $GITHUB_OUTPUT + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + check-author: + runs-on: ubuntu-latest + needs: get-team-members + outputs: + is-external: ${{ steps.check-author.outputs.is-external }} + steps: + - name: Check if PR is from a team member + id: check-author + run: | + TEAM_MEMBERS="${{ needs.get-team-members.outputs.team-members }}" + if [ "${{ github.event.pull_request }}" != "" ]; then + if echo "$TEAM_MEMBERS" | grep -q "${{ github.actor }}"; then + echo "PR is from a team member." + echo "is-external=false" >> $GITHUB_OUTPUT + else + echo "PR is from an external contributor." + echo "is-external=true" >> $GITHUB_OUTPUT + fi + else + echo "Not a PR, running the workflow." + echo "is-external=false" >> $GITHUB_OUTPUT + fi + + require-approval: + runs-on: ubuntu-latest + needs: check-author + if: needs.check-author.outputs.is-external == 'true' + steps: + - name: Manual Approval + uses: actions/github-script@v6 + with: + script: | + const prNumber = context.payload.pull_request.number; + const repo = context.repo; + github.rest.pulls.requestReviewers({ + owner: repo.owner, + repo: repo.repo, + pull_number: prNumber, + reviewers: ['nachoaldamav'] + }); + github-token: ${{ secrets.GITHUB_TOKEN }} + + windows-tests: + needs: [require-approval, get-team-members] + uses: ./.github/workflows/windows.yml@${{ github.ref_name }} + + macos-tests: + needs: [require-approval, get-team-members] + uses: ./.github/workflows/macos.yml@${{ github.ref_name }} + + linux-tests: + needs: [require-approval, get-team-members] + uses: ./.github/workflows/linux.yml@${{ github.ref_name }} diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index c2c5231..f3cb659 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -1,10 +1,7 @@ name: E2E Linux (Google Cloud) on: - push: - branches: - - main - workflow_dispatch: + workflow_call: jobs: linux-e2e: diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 3dcee15..ccf15c6 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -1,11 +1,8 @@ name: E2E MacOS (GitHub Actions) on: - push: - branches: - - main - workflow_dispatch: - + workflow_call: + jobs: macos-e2e: runs-on: macos-latest diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 0fbc949..6152304 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -1,10 +1,7 @@ name: E2E Windows (Google Cloud) on: - push: - branches: - - main - workflow_dispatch: + workflow_call: jobs: windows-e2e: