|
| 1 | +name: Post Release |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + |
| 5 | +permissions: |
| 6 | + contents: write |
| 7 | + pull-requests: write |
| 8 | + |
| 9 | +jobs: |
| 10 | + promote-image: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Checkout |
| 14 | + uses: actions/checkout@v4 |
| 15 | + |
| 16 | + - name: Set up Go |
| 17 | + uses: actions/setup-go@v5 |
| 18 | + with: |
| 19 | + go-version-file: 'go.mod' |
| 20 | + |
| 21 | + - name: Install kpromo |
| 22 | + run: go install sigs.k8s.io/promo-tools/v4/cmd/kpromo@latest |
| 23 | + |
| 24 | + - name: Get latest pre-release tag |
| 25 | + id: extract_tag |
| 26 | + run: | |
| 27 | + TAG=$(gh release list --limit 1 --json tagName,isPrerelease --jq '.[] | select(.isPrerelease == true) | .tagName') |
| 28 | + if [ -z "$TAG" ]; then |
| 29 | + echo "Error: No pre-release found" |
| 30 | + exit 1 |
| 31 | + fi |
| 32 | + echo "tag=${TAG}" >> $GITHUB_OUTPUT |
| 33 | + echo "Found pre-release tag: ${TAG}" |
| 34 | + env: |
| 35 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 36 | + |
| 37 | + - name: Create image promotion PR |
| 38 | + run: | |
| 39 | + kpromo pr --fork=${{ github.actor }} -i \ |
| 40 | + --project=kube-state-metrics \ |
| 41 | + --tag=${{ steps.extract_tag.outputs.tag }} |
| 42 | + env: |
| 43 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + |
| 45 | + merge-back-to-main: |
| 46 | + runs-on: ubuntu-latest |
| 47 | + steps: |
| 48 | + - name: Checkout |
| 49 | + uses: actions/checkout@v4 |
| 50 | + with: |
| 51 | + fetch-depth: 0 |
| 52 | + |
| 53 | + - name: Get latest pre-release tag |
| 54 | + id: extract_tag |
| 55 | + run: | |
| 56 | + TAG=$(gh release list --limit 1 --json tagName,isPrerelease --jq '.[] | select(.isPrerelease == true) | .tagName') |
| 57 | + if [ -z "$TAG" ]; then |
| 58 | + echo "Error: No pre-release found" |
| 59 | + exit 1 |
| 60 | + fi |
| 61 | + echo "tag=${TAG}" >> $GITHUB_OUTPUT |
| 62 | + echo "Found pre-release tag: ${TAG}" |
| 63 | + env: |
| 64 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 65 | + |
| 66 | + - name: Create PR to merge release changes back to main |
| 67 | + run: | |
| 68 | + # Extract major.minor for branch name |
| 69 | + MAJOR_MINOR=$(echo "${{ steps.extract_tag.outputs.tag }}" | sed 's/v//' | cut -d. -f1,2) |
| 70 | + RELEASE_BRANCH="release-${MAJOR_MINOR}" |
| 71 | + |
| 72 | + # Check if branches exist and have differences |
| 73 | + if ! git rev-parse --verify "origin/${RELEASE_BRANCH}" >/dev/null 2>&1; then |
| 74 | + echo "Error: Branch ${RELEASE_BRANCH} does not exist" |
| 75 | + exit 1 |
| 76 | + fi |
| 77 | + |
| 78 | + # Check if there are commits to merge |
| 79 | + if git merge-base --is-ancestor "origin/${RELEASE_BRANCH}" origin/main; then |
| 80 | + echo "No commits to merge - ${RELEASE_BRANCH} is already merged into main" |
| 81 | + exit 0 |
| 82 | + fi |
| 83 | + |
| 84 | + gh pr create \ |
| 85 | + --title "chore: Merge ${{ steps.extract_tag.outputs.tag }} back to main" \ |
| 86 | + --body "Merge release changes from ${{ steps.extract_tag.outputs.tag }} back to main branch." \ |
| 87 | + --base main \ |
| 88 | + --head $RELEASE_BRANCH \ |
| 89 | + --reviewer @sig-instrumentation-approvers \ |
| 90 | + --assignee @sig-instrumentation-leads |
| 91 | + env: |
| 92 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments