Repository navigation
chore(ci): improve GitHub Actions #392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rlorenzo
wants to merge
3
commits into
main
Choose a base branch
from
chore/github-actions-improvements
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| name: Changed stacks | ||
| description: > | ||
| Report whether a pull request touches the C# or Vue stack, so workflows can | ||
| skip jobs for the stack it leaves alone. Non-PR events report both as changed. | ||
| Needs a checkout with fetch-depth 0. | ||
|
|
||
| inputs: | ||
| own-paths: | ||
| description: The calling workflow's own files or folders, space-separated; a change to any runs both stacks. | ||
| required: true | ||
|
|
||
| outputs: | ||
| csharp: | ||
| description: "'true' when C# code or its build/tooling changed" | ||
| value: ${{ steps.filter.outputs.csharp }} | ||
| vue: | ||
| description: "'true' when Vue code or its build/tooling changed" | ||
| value: ${{ steps.filter.outputs.vue }} | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - id: filter | ||
| shell: bash | ||
| env: | ||
| BASE_REF: ${{ github.base_ref }} | ||
| OWN_PATHS: ${{ inputs.own-paths }} | ||
| run: | | ||
| if [ -z "$BASE_REF" ]; then | ||
| echo "csharp=true" >> "$GITHUB_OUTPUT" | ||
| echo "vue=true" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| fi | ||
|
|
||
| files=$(git diff --no-renames --name-only "origin/$BASE_REF...HEAD") | ||
| echo "Changed files:" | ||
| echo "$files" | ||
|
|
||
| # Shared tooling runs both stacks; other workflow files run neither | ||
| shared="^(package(-lock)?\.json$|scripts/|\.editorconfig$|\.jscpd\.json$|\.npmrc$|\.github/actions/changed-stacks/)" | ||
| dot='\.' | ||
| for p in $OWN_PATHS; do shared="$shared|^${p//./$dot}"; done | ||
| csharp="$shared|^(web/|test/|Viper\.sln|Directory\.Build\.props$|global\.json$|\.globalconfig$|\.config/)" | ||
| vue="$shared|^(VueApp/|eslint\.config\.mjs$|\.oxlintrc\.json$|stylelint\.config\.mjs$|\.env)" | ||
|
|
||
| for stack in csharp vue; do | ||
| if grep -qE "${!stack}" <<< "$files"; then | ||
| echo "$stack=true" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "$stack=false" >> "$GITHUB_OUTPUT" | ||
| fi | ||
| done | ||
| cat "$GITHUB_OUTPUT" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| name: CodeRabbit Gate | ||
|
|
||
| # Passes when CodeRabbit's check run succeeded on the head commit and none of | ||
| # its threads are unresolved. A clean incremental review posts no PR review at | ||
| # all, so the job waits for CodeRabbit's check run instead of a review event. | ||
| # A declined finding passes once its thread is resolved and this check is re-run. | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, reopened, synchronize, ready_for_review] | ||
| pull_request_review: | ||
| types: [submitted, dismissed] | ||
| # Catches a CodeRabbit review that finishes after the gate stopped polling. | ||
| # check_run only fires from the default branch's copy of this workflow. | ||
| check_run: | ||
| types: [completed] | ||
|
|
||
| permissions: | ||
| pull-requests: read # read CodeRabbit's review threads | ||
| checks: read # read CodeRabbit's check run on the head commit | ||
|
|
||
| concurrency: | ||
| # check_run fires for every check, so its runs must not cancel each other | ||
| group: coderabbit-gate-${{ github.event.pull_request.number || github.run_id }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| coderabbit-gate: | ||
| name: CodeRabbit approval | ||
| # CodeRabbit skips drafts and Dependabot PRs, so there is no verdict to wait for | ||
| if: ${{ github.event_name != 'check_run' && !github.event.pull_request.draft && github.event.pull_request.user.login != 'dependabot[bot]' }} | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 25 | ||
| steps: | ||
| - name: Check CodeRabbit's review of the head commit | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| PR: ${{ github.event.pull_request.number }} | ||
| HEAD_SHA: ${{ github.event.pull_request.head.sha }} | ||
| run: | | ||
| set -o pipefail | ||
| for _ in $(seq 40); do | ||
| run=$(gh api "repos/$GITHUB_REPOSITORY/commits/$HEAD_SHA/check-runs?check_name=CodeRabbit" \ | ||
| --jq '.check_runs | sort_by(.id) | last | select(.) | "\(.status) \(.conclusion)"') | ||
| [[ "$run" == completed* ]] && break | ||
| sleep 30 | ||
|
rlorenzo marked this conversation as resolved.
Resolved
|
||
| done | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| if [ "$run" != "completed success" ]; then | ||
| echo "::error::CodeRabbit has not reviewed the latest commit (${run:-no run}). If it was rate limited or skipped, comment '@coderabbitai review'." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Findings outside the diff have no thread, so only threaded findings block | ||
| unresolved=$(gh api graphql --paginate --slurp -F pr="$PR" -f owner="${GITHUB_REPOSITORY%/*}" -f repo="${GITHUB_REPOSITORY#*/}" -f query=' | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| query($owner:String!, $repo:String!, $pr:Int!, $endCursor:String) { | ||
| repository(owner:$owner, name:$repo) { pullRequest(number:$pr) { | ||
| reviewThreads(first:100, after:$endCursor) { | ||
| pageInfo { hasNextPage endCursor } | ||
| nodes { isResolved comments(first:1) { nodes { author { login } } } } | ||
| } | ||
| } } | ||
| }' | jq '[.[].data.repository.pullRequest.reviewThreads.nodes[] | ||
| | select(.isResolved == false and .comments.nodes[0].author.login == "coderabbitai")] | length') | ||
| if [ "$unresolved" -gt 0 ]; then | ||
| echo "::error::$unresolved CodeRabbit thread(s) unresolved. Address or resolve them, then re-run this check." | ||
| exit 1 | ||
| fi | ||
| echo "CodeRabbit's review of the latest commit is clean." | ||
|
|
||
| rerun-after-coderabbit: | ||
| name: Re-run gate after CodeRabbit finishes | ||
| if: ${{ github.event_name == 'check_run' && github.event.check_run.name == 'CodeRabbit' }} | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| actions: write # list and re-run this workflow's gate runs | ||
| steps: | ||
| - name: Re-run the commit's failed gate run | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| HEAD_SHA: ${{ github.event.check_run.head_sha }} | ||
| # This run reports on the default branch, so re-run the PR's own gate run instead | ||
| run: | | ||
| run=$(gh run list -R "$GITHUB_REPOSITORY" --workflow coderabbit-gate.yml --commit "$HEAD_SHA" -L 20 \ | ||
| --json databaseId,event,status,conclusion \ | ||
| --jq '[.[] | select(.event != "check_run")][0] | select(.status == "completed" and .conclusion == "failure") | .databaseId') | ||
| if [ -n "$run" ]; then | ||
| gh run rerun "$run" -R "$GITHUB_REPOSITORY" | ||
|
rlorenzo marked this conversation as resolved.
Resolved
|
||
| else | ||
| echo "No failed gate run to refresh for $HEAD_SHA." | ||
| fi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.