Skip to content
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

ci: Implement the stacked-pr ci optimizer myself #2847

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/ci-optimizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: ci-optimizer

on:
pull_request:
branches-ignore:
- main
- '[0-9][0-9].0[39]'

jobs:
ci-optimizer:
runs-on: ubuntu-latest
steps:
- name: Find the PR that has the current base as its head and add the skip:CI label to it
run: |
PR_NUMBER=$(gh pr list --head ${{ github.event.pull_request.base.ref }} --json number --jq '.[0].number')
IS_BOTTOM_PR=$(gh pr view $PR_NUMBER --json base.ref --jq '.base.ref == "main" or (.base.ref | test("^[0-9][0-9]\\.0[39]$"))')
if [ -n "$PR_NUMBER" ] && [ "$IS_BOTTOM_PR" = "false" ]; then
gh pr edit $PR_NUMBER --add-label "skip:ci"
fi
env:
GH_TOKEN: ${{ secrets.OCTODOG }}
30 changes: 3 additions & 27 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,14 @@ jobs:
outputs:
skip: ${{ steps.check_skip.outputs.SKIP }}
steps:
- name: Optimize CI
if: ${{ github.event_name == 'pull_request' }}
id: graphite-ci-action
uses: withgraphite/graphite-ci-action@main
with:
graphite_token: ${{ secrets.GRAPHITE_CI_OPTIMIZER_TOKEN }}
- name: Check if should skip the CI
id: check_skip
run: |
if [ "${{ steps.graphite-ci-action.outputs.skip }}" == "true" ]; then
echo "SKIP=true" >> $GITHUB_OUTPUT
else
echo "SKIP=false" >> $GITHUB_OUTPUT
fi
- name: labeler
if: github.event.action == 'opened' || github.event.action == 'reopened' || github.event.action == 'syncrhonize'
uses: lablup/auto-labeler@main # actions/labeler, lablup/size-label-action, lablup/auto-label-in-issue


lint:
if: |
!(
contains(github.event.pull_request.labels.*.name, 'skip:ci')
|| needs.optimize-ci.outputs.skip == 'true'
)
!contains(github.event.pull_request.labels.*.name, 'skip:ci')
&& !contains(fromJSON('["flow:merge-queue", "flow:hotfix"]'), github.event.label.name)
&& github.event.pull_request.merged == false
needs: [optimize-ci]
Expand Down Expand Up @@ -131,7 +114,6 @@ jobs:
)
&& !contains(fromJSON('["flow:merge-queue", "flow:hotfix"]'), github.event.label.name)
&& github.event.pull_request.merged == false
&& needs.optimize-ci.outputs.skip == 'false'
needs: [optimize-ci]
runs-on: ubuntu-latest
steps:
Expand All @@ -154,10 +136,7 @@ jobs:

typecheck:
if: |
!(
contains(github.event.pull_request.labels.*.name, 'skip:ci')
|| needs.optimize-ci.outputs.skip == 'true'
)
!contains(github.event.pull_request.labels.*.name, 'skip:ci')
&& !contains(fromJSON('["flow:merge-queue", "flow:hotfix"]'), github.event.label.name)
&& github.event.pull_request.merged == false
needs: [optimize-ci]
Expand Down Expand Up @@ -226,10 +205,7 @@ jobs:

test:
if: |
!(
contains(github.event.pull_request.labels.*.name, 'skip:ci')
|| needs.optimize-ci.outputs.skip == 'true'
)
!contains(github.event.pull_request.labels.*.name, 'skip:ci')
&& !contains(fromJSON('["flow:merge-queue", "flow:hotfix"]'), github.event.label.name)
&& github.event.pull_request.merged == false
needs: [optimize-ci]
Expand Down
Loading