diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d2941a61..7bf58b59 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,51 @@ concurrency: cancel-in-progress: true jobs: + test-pr-nr: + if: github.ref == 'refs/heads/main' + runs-on: "ubuntu-latest" + steps: + # Checkout code in order to determine PR number + - uses: actions/checkout@v3.3.0 + with: + fetch-depth: 0 + + # https://stackoverflow.com/a/70102700 + - name: Get Pull Request Number + id: pr + run: echo "::set-output name=pull_request_number::$(gh pr view --json number -q .number || echo "")" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Get PR number + id: pr2 + run: | + commit_sha=$(git rev-parse HEAD) + pr_number=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ + "https://api.github.com/repos/jorisroovers/gitlint/commits/$commit_sha/pulls" | jq -r '.[0].number') + echo "PR_NUMBER=$pr_number" >> $GITHUB_ENV + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - run: echo ${{ env.PR_NUMBER }} + + - run: jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH" + + - run: echo "${{ github.event.pull_request.number }}" + + - run: | + echo "PR number: ${{ steps.pr.outputs.pull_request_number }}" + + - run: gh pr view --json number -q .number + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - run: gh pr view --json + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + tests: + needs: test-pr-nr runs-on: "ubuntu-latest" strategy: matrix: @@ -246,6 +290,18 @@ jobs: if: github.ref == 'refs/heads/main' runs-on: "ubuntu-latest" steps: + # Checkout code in order to determine PR number + - uses: actions/checkout@v3.3.0 + with: + fetch-depth: 0 + + # https://stackoverflow.com/a/70102700 + - name: Get Pull Request Number + id: pr + run: echo "::set-output name=pull_request_number::$(gh pr view --json number -q .number || echo "")" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - uses: actions/github-script@v6 with: script: | @@ -259,7 +315,7 @@ jobs: \`\`\` `; github.rest.issues.createComment({ - issue_number: context.issue.number, + issue_number: ${{ steps.pr.outputs.pull_request_number }}, owner: context.repo.owner, repo: context.repo.repo, body: body