Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

Commit

Permalink
[CI] Fix /format (#1658)
Browse files Browse the repository at this point in the history
* [CI] Fix /format

* Don't download PR data twice

* Fix spelling

* Add reminder to trigger buld manually

* Don't enumerate list

* Fix typo
  • Loading branch information
SaschaMann authored Jun 17, 2020
1 parent 57a8cad commit 2b62cd8
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions .github/workflows/format-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@ jobs:
runs-on: ubuntu-latest
if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/format')
steps:
- name: 'Download PR data'
run: |
PR_DATA="/tmp/pr.json"
jq -r ".issue.pull_request.url" "$GITHUB_EVENT_PATH" | \
xargs curl --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' -o "$PR_DATA" --url
- name: 'Check fork status'
id: fork_check
id: fork_status
run: |
IS_FORK="$(jq '.pull_request.head.repo.fork' "$GITHUB_EVENT_PATH")"
IS_FORK="$(jq '.head.repo.fork' "/tmp/pr.json")"
echo "::set-output name=fork::$IS_FORK"
- name: 'Setup SSH deploy key'
if: steps.fork_check.outputs.fork == "false"
if: steps.fork_status.outputs.fork == 'false'
run: |
mkdir ~/.ssh
echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/id_ed25519
Expand All @@ -27,16 +34,13 @@ jobs:
run: |
PR_DATA="/tmp/pr.json"
jq -r ".issue.pull_request.url" "$GITHUB_EVENT_PATH" | \
xargs curl --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' -o "$PR_DATA" --url
HEAD_REF=$(jq -r ".head.ref" "$PR_DATA")
if [ ${{ steps.fork_check.outputs.fork }} == "false" ]; then
# Setup repo using ssh
if [ ${{ steps.fork_status.outputs.fork }} == "false" ]; then
echo "::debug::Setting up repo using SSH"
HEAD_REPO=$(jq -r '.head.repo.ssh_url' "$PR_DATA")
else
# Setup repo using HTTPS
echo "::debug::Setting up repo using HTTPS"
HEAD_REPO=$(jq -r '.head.repo.clone_url | sub("https://"; "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@")' "$PR_DATA")
fi
Expand Down Expand Up @@ -67,3 +71,17 @@ jobs:
git add .
git commit -m "[CI] Format code"
git push
- name: 'Post reminder to trigger build manually'
continue-on-error: true # Never fail the build if this fails
if: steps.fork_status.outputs.fork == 'true'
uses: actions/github-script@6e5ee1dc1cb3740e5e5e76ad668e3f526edbfe45 # 2.0.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'For security reasons, `/format` does not trigger CI builds when the PR has been submitted from a fork. To make the required checks pass, you need to trigger a build through one of the following ways:\n\n- Push an empty commit to this branch: `git commit --allow-empty -m "Trigger builds"`.\n- Close and reopen the PR.\n- Push a regular commit to this branch.'
})

0 comments on commit 2b62cd8

Please sign in to comment.