From 55af3e19b414d10762072c2f46107137791faa79 Mon Sep 17 00:00:00 2001 From: merwanehamadi Date: Tue, 16 May 2023 19:49:12 -0700 Subject: [PATCH] CI Pipeline: create cassettes in fork (#4257) Co-authored-by: Nicholas Tindle --- .github/workflows/add-cassettes.yml | 49 ----------------------------- .github/workflows/ci.yml | 38 +++++++++++++++++++--- 2 files changed, 33 insertions(+), 54 deletions(-) delete mode 100644 .github/workflows/add-cassettes.yml diff --git a/.github/workflows/add-cassettes.yml b/.github/workflows/add-cassettes.yml deleted file mode 100644 index 9bf5b1b8..00000000 --- a/.github/workflows/add-cassettes.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: Merge and Commit Cassettes - -on: - pull_request_target: - types: - - closed - -jobs: - update-cassettes: - if: github.event.pull_request.merged == true - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v3 - with: - fetch-depth: 0 # This is necessary to fetch all branches and tags - - - name: Fetch all branches - run: git fetch --all - - - name: Reset branch - run: | - git checkout ${{ github.event.pull_request.base.ref }} - git reset --hard origin/cassette-diff-${{ github.event.pull_request.head.sha }} - - - name: Create PR - id: create_pr - uses: peter-evans/create-pull-request@v5 - with: - commit-message: Update cassettes - signoff: false - branch: cassette-diff-${{ github.event.pull_request.head.sha }} - delete-branch: false - title: "Update cassettes" - body: "This PR updates the cassettes." - draft: false - - - name: Check PR - run: | - echo "Pull Request Number - ${{ steps.create_pr.outputs.pull-request-number }}" - echo "Pull Request URL - ${{ steps.create_pr.outputs.pull-request-url }}" - - - name: Comment PR URL in the current PR - uses: thollander/actions-comment-pull-request@v2 - with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - message: | - New pull request created for cassettes: [HERE](${{ steps.create_pr.outputs.pull-request-url }}). Please merge it asap. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b36b45e8..cb20cfe6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -94,14 +94,42 @@ jobs: uses: codecov/codecov-action@v3 - name: Stage new files and commit + id: stage_files run: | - COMMIT_SHA=$(git rev-parse HEAD) # take the sha before committing the cassette git add tests git diff --cached --quiet && echo "No changes to commit" && exit 0 git config user.email "github-actions@github.com" git config user.name "GitHub Actions" git commit -m "Add new cassettes" - - git checkout -b cassette-diff-${COMMIT_SHA} - git remote add target https://${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.event.pull_request.base.repo.full_name }} - git push -f target cassette-diff-${COMMIT_SHA} + TIMESTAMP_COMMIT=$(date +%Y%m%d%H%M%S) # generate a timestamp + echo "TIMESTAMP_COMMIT=TIMESTAMP_COMMIT" >> $GITHUB_ENV + + + - name: Create PR + id: create_pr + if: ${{ env.TIMESTAMP_COMMIT != null }} + uses: peter-evans/create-pull-request@v5 + with: + commit-message: Update cassettes + branch: cassette-diff-PR-${{ github.event.pull_request.number }}-${{ env.TIMESTAMP_COMMIT }} + title: "Update cassette-diff-PR${{ github.event.pull_request.number }}-${{ env.TIMESTAMP_COMMIT }}" + body: "This PR updates the cassettes. Please merge it." + + + - name: Check PR + if: ${{ env.TIMESTAMP_COMMIT != null }} + run: | + echo "Pull Request Number - ${{ steps.create_pr.outputs.pull-request-number }}" + echo "Pull Request URL - ${{ steps.create_pr.outputs.pull-request-url }}" + + - name: Comment PR URL in the current PR + if: ${{ env.TIMESTAMP_COMMIT != null }} + uses: thollander/actions-comment-pull-request@v2 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + message: | + Please click [HERE](${{ steps.create_pr.outputs.pull-request-url }}) and merge this PR to update the cassettes. + + - name: Fail if new PR created + if: ${{ env.TIMESTAMP_COMMIT != null }} + run: exit 1