|
| 1 | +name: Bump webhook in rancher/rancher |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + inputs: |
| 5 | + rancher_ref: |
| 6 | + description: "Submit PR against the following rancher/rancher branch (eg: release/v2.8)" |
| 7 | + required: true |
| 8 | + default: "release/v2.8" |
| 9 | + prev_webhook: |
| 10 | + description: "Previous Webhook version (eg: v0.4.0-rc.13)" |
| 11 | + required: true |
| 12 | + default: "" |
| 13 | + new_webhook: |
| 14 | + description: "New Webhook version (eg: v0.4.0-rc.14)" |
| 15 | + required: true |
| 16 | + default: "" |
| 17 | + |
| 18 | +env: |
| 19 | + RANCHER_REF: ${{ github.event.inputs.rancher_ref }} |
| 20 | + WEBHOOK_REF: "${{ github.ref_name }}" |
| 21 | + PREV_WEBHOOK: ${{ github.event.inputs.prev_webhook }} |
| 22 | + NEW_WEBHOOK: ${{ github.event.inputs.new_webhook }} |
| 23 | + |
| 24 | +jobs: |
| 25 | + create-rancher-pr: |
| 26 | + runs-on: ubuntu-latest |
| 27 | + permissions: |
| 28 | + contents: read |
| 29 | + # Required for vault |
| 30 | + id-token: write |
| 31 | + steps: |
| 32 | + - name: Install dependencies |
| 33 | + run: sudo snap install yq --channel=v4/stable |
| 34 | + |
| 35 | + - uses: actions/checkout@v4 |
| 36 | + with: |
| 37 | + ref: "${{ env.WEBHOOK_REF }}" |
| 38 | + path: webhook |
| 39 | + |
| 40 | + - uses: rancher-eio/read-vault-secrets@main |
| 41 | + with: |
| 42 | + secrets: | |
| 43 | + secret/data/github/repo/${{ github.repository }}/github/app-credentials appId | APP_ID ; |
| 44 | + secret/data/github/repo/${{ github.repository }}/github/app-credentials privateKey | PRIVATE_KEY |
| 45 | +
|
| 46 | + # Fetch github token just for the rancher repository |
| 47 | + - uses: actions/create-github-app-token@v1 |
| 48 | + id: app-token |
| 49 | + with: |
| 50 | + app-id: ${{ env.APP_ID }} |
| 51 | + private-key: ${{ env.PRIVATE_KEY }} |
| 52 | + repositories: | |
| 53 | + rancher |
| 54 | +
|
| 55 | + - name: Checkout rancher repository |
| 56 | + uses: actions/checkout@v4 |
| 57 | + with: |
| 58 | + repository: ${{ github.repository_owner }}/rancher |
| 59 | + ref: "${{ env.RANCHER_REF }}" |
| 60 | + token: ${{ steps.app-token.outputs.token }} |
| 61 | + path: rancher |
| 62 | + # Allow making git push request later on |
| 63 | + persist-credentials: true |
| 64 | + |
| 65 | + - name: Find charts branch |
| 66 | + id: find_charts_branch |
| 67 | + run: | |
| 68 | + cd rancher |
| 69 | + # Extract dev-v2.8 out of the following line: |
| 70 | + # ChartDefaultBranch = NewSetting("chart-default-branch", "dev-v2.8") |
| 71 | + charts_branch=$(grep '"chart-default-branch"' pkg/settings/setting.go | cut -d'"' -f4) |
| 72 | + echo "charts_branch=$charts_branch" >> $GITHUB_OUTPUT |
| 73 | +
|
| 74 | + - uses: actions/checkout@v4 |
| 75 | + with: |
| 76 | + repository: ${{ github.repository_owner }}/charts |
| 77 | + ref: "${{ steps.find_charts_branch.outputs.charts_branch }}" |
| 78 | + path: charts |
| 79 | + |
| 80 | + # Prevents the Rancher CI to continuously fail while the webhook RC is not |
| 81 | + # yet added to charts' index.yaml file due to caching. |
| 82 | + - name: Verify RC exists |
| 83 | + env: |
| 84 | + CHARTS_BRANCH: "${{ steps.find_charts_branch.outputs.charts_branch }}" |
| 85 | + run: | |
| 86 | + cd charts |
| 87 | + new_webhook_short=$(echo "$NEW_WEBHOOK" | sed 's|^v||') # e.g. 0.5.2-rc.3 |
| 88 | + # Empty output if the version is not found, otherwise the version will be outputed. |
| 89 | + found=$(yq ".entries.rancher-webhook[].version | select(. == \"*$new_webhook_short\")" index.yaml) |
| 90 | + if [ -z "$found" ]; then |
| 91 | + echo "rancher-webhook RC version $NEW_WEBHOOK not found in charts (branch=$CHARTS_BRANCH). Aborting." |
| 92 | + exit 1 |
| 93 | + fi |
| 94 | +
|
| 95 | + - name: Configure the committer |
| 96 | + run: | |
| 97 | + cd rancher |
| 98 | + user_id=$(gh api "/users/$APP_USER" --jq .id) |
| 99 | + git config --global user.name "$APP_USER" |
| 100 | + git config --global user.email "${user_id}+${APP_USER}@users.noreply.github.com" |
| 101 | + env: |
| 102 | + GH_TOKEN: ${{ steps.app-token.outputs.token }} |
| 103 | + APP_USER: "${{ steps.app-token.outputs.app-slug }}[bot]" |
| 104 | + |
| 105 | + - name: Run release script |
| 106 | + run: | |
| 107 | + cd rancher |
| 108 | + BRANCH="bump-webhook-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}" |
| 109 | + echo "BRANCH=${BRANCH}" >> $GITHUB_ENV |
| 110 | + git checkout -b "$BRANCH" "$RANCHER_REF" |
| 111 | + ../webhook/.github/workflows/scripts/release-against-rancher.sh . "$NEW_WEBHOOK" |
| 112 | +
|
| 113 | + - name: Push and create pull request |
| 114 | + env: |
| 115 | + GH_TOKEN: ${{ steps.app-token.outputs.token }} |
| 116 | + run: | |
| 117 | + cd rancher |
| 118 | + git push origin $BRANCH |
| 119 | +
|
| 120 | + body=$(../webhook/.github/workflows/scripts/release-message.sh "$PREV_WEBHOOK" "$NEW_WEBHOOK") |
| 121 | +
|
| 122 | + gh pr create \ |
| 123 | + --title "[$RANCHER_REF] Bump rancher-webhook to $NEW_WEBHOOK" \ |
| 124 | + --body "$body" \ |
| 125 | + --repo ${{ github.repository_owner }}/rancher \ |
| 126 | + --head "${{ github.repository_owner }}:$BRANCH" \ |
| 127 | + --base "$RANCHER_REF" |
0 commit comments