-
Notifications
You must be signed in to change notification settings - Fork 83
Add sync deps workflow #552
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| #!/bin/sh | ||
|
|
||
| set -e | ||
|
|
||
| RANCHER_REPO_DIR=$1 | ||
|
|
||
| DEPS_TO_SYNC=" | ||
| github.com/rancher/dynamiclistener | ||
| github.com/rancher/lasso | ||
| github.com/rancher/wrangler | ||
| github.com/rancher/wrangler/v2 | ||
| github.com/rancher/wrangler/v3 | ||
| " | ||
|
|
||
| rancher_deps=$(cd "$RANCHER_REPO_DIR" && go mod graph) | ||
| webhook_deps=$(go mod graph) | ||
|
|
||
| rancher_ref=$(cd "$RANCHER_REPO_DIR" && git rev-parse HEAD) | ||
| rancher_ref_version=$(go mod download -json "github.com/rancher/rancher/pkg/apis@$rancher_ref" | jq -r '.Version') | ||
crobby marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| echo "Syncing github.com/rancher/rancher/pkg/apis" | ||
| go mod edit "-require=github.com/rancher/rancher/pkg/apis@$rancher_ref_version" | ||
|
|
||
| for dep in $DEPS_TO_SYNC; do | ||
| if ! rancher_version=$(echo "$rancher_deps" | grep "^$dep@\w*\S"); then | ||
| continue | ||
| fi | ||
|
|
||
| if ! webhook_version=$(echo "$webhook_deps" | grep "^$dep@\w*\S"); then | ||
| continue | ||
| fi | ||
|
|
||
| rancher_version=$(echo "$rancher_version" | head -n 1 | cut -d' ' -f1 | cut -d@ -f2) | ||
| webhook_version=$(echo "$webhook_version" | head -n 1 | cut -d' ' -f1 | cut -d@ -f2) | ||
| if [ "$rancher_version" = "$webhook_version" ]; then | ||
| continue | ||
| fi | ||
|
|
||
| echo "Version mismatch for $dep (rancher=$rancher_version, webhook=$webhook_version) detected" | ||
| go mod edit -require=$dep@$rancher_version | ||
| done | ||
|
|
||
| echo "Running go mod tidy" | ||
| go mod tidy | ||
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,78 @@ | ||
| name: Sync dependencies | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| rancher_ref: | ||
| description: "Version of rancher/rancher to compare" | ||
| required: true | ||
| default: "main" | ||
| rancher_repository: | ||
| description: "Repository for rancher/rancher" | ||
| required: true | ||
| default: "rancher/rancher" | ||
|
|
||
| env: | ||
| RANCHER_REF: "${{ github.event.inputs.rancher_ref }}" | ||
| WEBHOOK_REF: "${{ github.ref_name }}" | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| sync: | ||
| name: Sync dependencies | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name : Checkout webhook repository | ||
| uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | ||
| with: | ||
| ref: "${{ env.WEBHOOK_REF }}" | ||
| path: webhook | ||
|
|
||
| - name : Checkout rancher repository | ||
| uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | ||
| with: | ||
| repository: "${{ github.event.inputs.rancher_repository }}" | ||
| ref: "${{ env.RANCHER_REF }}" | ||
| path: rancher | ||
|
|
||
| - name: Install dependencies | ||
| run: sudo snap install yq --channel=v4/stable | ||
|
|
||
| - name: Configure the committer | ||
| run: | | ||
| cd webhook | ||
| git config --global user.name "Webhook Sync Bot" | ||
| git config --global user.email "[email protected]" | ||
|
|
||
| - name: Run sync-deps script | ||
| run: | | ||
| cd webhook | ||
| BRANCH="sync-deps-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}" | ||
| echo "BRANCH=${BRANCH}" >> $GITHUB_ENV | ||
| git checkout -b "$BRANCH" | ||
| ./.github/workflows/scripts/sync-deps.sh ../rancher | ||
| git add go.mod go.sum | ||
| git commit -m "Sync dependencies" | ||
| git push origin "$BRANCH" | ||
|
|
||
| - name: Create PR | ||
| run: | | ||
| cd webhook | ||
| body=$(cat <<EOF | ||
| # Sync with Rancher | ||
|
|
||
| The workflow was triggered by $GITHUB_TRIGGERING_ACTOR. | ||
| EOF | ||
| ) | ||
| gh pr create \ | ||
| --title "[$WEBHOOK_REF] Sync webhook dependencies" \ | ||
| --body "$body" \ | ||
| --reviewer "$GITHUB_TRIGGERING_ACTOR" \ | ||
| --repo "${{ github.repository }}" \ | ||
| --head "${{ github.repository_owner }}:$BRANCH" \ | ||
| --base "$WEBHOOK_REF" | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
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.