From 1c9fd1cf993fe8fde73fa04aad98abdfdf930087 Mon Sep 17 00:00:00 2001 From: Sanne Raymaekers Date: Mon, 27 Sep 2021 13:14:39 +0200 Subject: [PATCH] .github: Use the workflow_run event data in trigger-gitlab This workflow doesn't have access to the original pull request event that resulted in this workflow being triggered. Simply use `head_sha` which will contain the PR sha if it was triggered by a PR's workflow, or the branch sha if it was triggered from a branch's workflow. --- .github/workflows/trigger-gitlab.yml | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/workflows/trigger-gitlab.yml b/.github/workflows/trigger-gitlab.yml index 205fdb98..a2d41691 100644 --- a/.github/workflows/trigger-gitlab.yml +++ b/.github/workflows/trigger-gitlab.yml @@ -14,13 +14,26 @@ jobs: env: SCHUTZBOT_SSH_KEY: ${{ secrets.SCHUTZBOT_SSH_KEY }} steps: + - name: Report status + uses: haya14busa/action-workflow_run-status@v1 + - name: Clone repository uses: actions/checkout@v2 with: - # otherwise we are testing target branch instead of the PR branch (see pull_request_target trigger) - ref: ${{ github.event.pull_request.head.sha }} + ref: ${{ github.event.workflow_run.head_sha }} fetch-depth: 0 + # If the parent workflow belongs to a PR, create a new PR-# branch + - name: Checkout branch (PR) + if: ${{ github.event.workflow_run.pull_requests[0] != null }} + run: | + git checkout -b PR-${{ github.event.workflow_run.pull_requests[0].number }} + + - name: Checkout branch (branch) + if: ${{ github.event.workflow_run.pull_requests[0] == null }} + run: | + git checkout ${{ github.event.workflow_run.head_branch }} + - name: Push to gitlab run: | mkdir -p ~/.ssh @@ -29,7 +42,4 @@ jobs: touch ~/.ssh/known_hosts ssh-keyscan -t rsa gitlab.com >> ~/.ssh/known_hosts git remote add ci git@gitlab.com:osbuild/ci/osbuild.git - if [ ${{ github.event.pull_request.number }} ]; then - git checkout -b PR-${{ github.event.pull_request.number }} - fi git push -f ci