diff --git a/.github/workflows/scripts/sync-deps.sh b/.github/workflows/scripts/sync-deps.sh new file mode 100755 index 000000000..15855cd7c --- /dev/null +++ b/.github/workflows/scripts/sync-deps.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +set -e + +RANCHER_REPO_DIR=$1 + +DEPS_TO_SYNC=" + github.com/rancher/wrangler +" + +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') +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 + echo "Rancher Dep $dep $(echo "$rancher_deps" | grep "^$dep@\w*\S")" + echo "Webhook Dep $dep $(echo "$webhook_deps" | grep "^$dep@\w*\S")" + rancher_version=$(echo "$rancher_deps" | grep "^$dep@\w*\S" | head -n 1 | cut -d' ' -f1 | cut -d@ -f2) + webhook_version=$(echo "$webhook_deps" | grep "^$dep@\w*\S" | head -n 1 | cut -d' ' -f1 | cut -d@ -f2) + if [ -z "$webhook_version" ] || [ -z "$rancher_version" ] || [ "$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 diff --git a/.github/workflows/sync-deps.yaml b/.github/workflows/sync-deps.yaml new file mode 100644 index 000000000..6c75abfd1 --- /dev/null +++ b/.github/workflows/sync-deps.yaml @@ -0,0 +1,77 @@ +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 "webhooksyncbot@users.noreply.github.com" + + - 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 <