|
| 1 | +name: Pre-Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + new_version: |
| 7 | + description: 'The new release version (e.g., v2.10.0)' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + pull-requests: write |
| 14 | + |
| 15 | +env: |
| 16 | + GO_VERSION: "^1.24.6" |
| 17 | + GOLANGCI_LINT_VERSION: "v2.4.0" |
| 18 | + E2E_SETUP_KIND: yes |
| 19 | + E2E_SETUP_KUBECTL: yes |
| 20 | + |
| 21 | +jobs: |
| 22 | + release: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + - name: 'Validate version format' |
| 26 | + run: | |
| 27 | + if [[ ! "${{ inputs.new_version }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 28 | + echo "Error: Version format is incorrect. It must be in the format 'vX.Y.Z'." |
| 29 | + exit 1 |
| 30 | + fi |
| 31 | + echo "Version format is valid." |
| 32 | + - name: Checkout into the corresponding release branch |
| 33 | + uses: actions/checkout@v4 |
| 34 | + - name: Create VCS sandbox |
| 35 | + run: | |
| 36 | + git checkout -b release-prep-${{ inputs.new_version }} |
| 37 | + MAJOR_MINOR_VERSION=$(echo "${{ inputs.new_version }}" | sed 's/^v//' | cut -d. -f1,2) |
| 38 | + if git show-ref --verify --quiet refs/remotes/origin/release-$MAJOR_MINOR_VERSION; then |
| 39 | + echo "Release branch release-$MAJOR_MINOR_VERSION already exists, switching to it" |
| 40 | + git checkout -b release-$MAJOR_MINOR_VERSION origin/release-$MAJOR_MINOR_VERSION |
| 41 | + else |
| 42 | + echo "Creating new release branch release-$MAJOR_MINOR_VERSION" |
| 43 | + git checkout -b release-$MAJOR_MINOR_VERSION |
| 44 | + git push origin release-$MAJOR_MINOR_VERSION |
| 45 | + fi |
| 46 | + git checkout release-prep-${{ inputs.new_version }} |
| 47 | + - name: Set up the Go@${{ env.GO_VERSION }} environment |
| 48 | + uses: actions/setup-go@v5 |
| 49 | + with: |
| 50 | + go-version: ${{ env.GO_VERSION }} |
| 51 | + - name: Update the VERSION manifest |
| 52 | + run: echo "${{ inputs.new_version }}" | sed 's/^v//' > VERSION |
| 53 | + - name: update data.yaml |
| 54 | + run: | |
| 55 | + chmod +x scripts/update-data-yaml.sh |
| 56 | + ./scripts/update-data-yaml.sh "${{ inputs.new_version }}" |
| 57 | + - name: Update the compatibility matrix (README.md) |
| 58 | + run: make generate |
| 59 | + - name: Generate the release date for unreleased (CHANGELOG.md) |
| 60 | + run: | |
| 61 | + chmod +x scripts/generate-release-date.sh |
| 62 | + ./scripts/generate-release-date.sh "${{ inputs.new_version }}" |
| 63 | + - name: Lint |
| 64 | + run: | |
| 65 | + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | \ |
| 66 | + sh -s -- -b $(go env GOPATH)/bin ${{ env.GOLANGCI_LINT_VERSION }} |
| 67 | + make lint-fix |
| 68 | + - name: Generate manifests |
| 69 | + run: | |
| 70 | + make clean || true |
| 71 | + VERSION="${{ inputs.new_version }}" make examples |
| 72 | + - name: Run rule tests |
| 73 | + run: PROMTOOL_CLI=./promtool make install-promtool test-rules |
| 74 | + - name: Run unit tests |
| 75 | + run: make test-unit |
| 76 | + - name: Run end-to-end tests |
| 77 | + run: | |
| 78 | + make e2e |
| 79 | + find examples -name "*.yaml" -type f -exec sed -i 's|kube-state-metrics-amd64|kube-state-metrics|g; s|kube-state-metrics-arm64|kube-state-metrics|g' {} \; |
| 80 | + - name: Update the remote and commit the changes |
| 81 | + run: | |
| 82 | + git config --local user.email "ksm-release-bot@mock-k8s.io" |
| 83 | + git config --local user.name "KSM Release Bot" |
| 84 | + git add . |
| 85 | + git commit -m "chore: Cut ${{ inputs.new_version }}" |
| 86 | + MAJOR_MINOR_VERSION=$(echo "${{ inputs.new_version }}" | sed 's/^v//' | cut -d. -f1,2) |
| 87 | + git push origin release-prep-${{ inputs.new_version }} |
| 88 | + - name: 'Run benchmark tests' |
| 89 | + run: | |
| 90 | + BENCHSTAT_OUTPUT_FILE=result.txt ./tests/compare_benchmarks.sh main 2 |
| 91 | + - name: Post results to job summary |
| 92 | + run: | |
| 93 | + echo "### Benchmark Comparison Results" >> "$GITHUB_STEP_SUMMARY" |
| 94 | + echo "\`\`\`" >> "$GITHUB_STEP_SUMMARY" |
| 95 | + cat result.txt >> "$GITHUB_STEP_SUMMARY" |
| 96 | + echo "\`\`\`" >> "$GITHUB_STEP_SUMMARY" |
| 97 | + - name: Validate docs |
| 98 | + run: make doccheck |
| 99 | + - name: Validate manifests |
| 100 | + run: make validate-manifests |
| 101 | + - name: Validate go modules |
| 102 | + run: make validate-modules |
| 103 | + - name: Create a pull request |
| 104 | + run: | |
| 105 | + MAJOR_MINOR_VERSION=$(echo "${{ inputs.new_version }}" | sed 's/^v//' | cut -d. -f1,2) |
| 106 | + |
| 107 | + PREV_TAG=$(git tag --sort=-version:refname | head -n1 || echo "") |
| 108 | + |
| 109 | + if [[ -n "$PREV_TAG" ]]; then |
| 110 | + PREV_TAG_DATE="$(git show -s --format=%cI "$PREV_TAG" 2>/dev/null || true)" |
| 111 | + RANGE="${PREV_TAG}..HEAD" |
| 112 | + else |
| 113 | + PREV_TAG_DATE="1970-01-01T00:00:00Z" |
| 114 | + PREV_REF="$(git rev-list --max-parents=0 HEAD)" |
| 115 | + RANGE="${PREV_REF}..HEAD" |
| 116 | + fi |
| 117 | + |
| 118 | + PREV_DATE_SHORT="$(date -d "$PREV_TAG_DATE" +%Y-%m-%d 2>/dev/null || echo "1970-01-01")" |
| 119 | + TAG_DATE_SHORT="$(date -u +%Y-%m-%d)" |
| 120 | + |
| 121 | + CHANGELOG_SECTION=$(awk '/^## '"${{ inputs.new_version }}"'/{flag=1; next} /^## /{if(flag) exit} flag' CHANGELOG.md | grep -E '^\s*\*\s*\[' | sed 's/^/ /' || echo " No user-facing changes found for this version.") |
| 122 | + |
| 123 | + PR_LINES="$(gh pr list --state merged --search "merged:${PREV_DATE_SHORT}..${TAG_DATE_SHORT}" --json number,title,author --limit 1000 --template '{{range .}}{{.number}}|{{.title}}|{{.author.login}}{{"\n"}}{{end}}')" || true |
| 124 | + |
| 125 | + FULL_CHANGELOG_LINES=() |
| 126 | + if [[ -n "$PR_LINES" ]]; then |
| 127 | + while IFS= read -r line; do |
| 128 | + if [[ -n "$line" ]]; then |
| 129 | + prnum="${line%%|*}" |
| 130 | + rest="${line#*|}" |
| 131 | + title="${rest%%|*}" |
| 132 | + login="${rest##*|}" |
| 133 | + FULL_CHANGELOG_LINES+=(" - ${title} by @${login} in #${prnum}") |
| 134 | + fi |
| 135 | + done <<< "$PR_LINES" |
| 136 | + fi |
| 137 | + |
| 138 | + FULL_CHANGELOG_TEXT="" |
| 139 | + if [[ ${#FULL_CHANGELOG_LINES[@]} -gt 0 ]]; then |
| 140 | + printf -v FULL_CHANGELOG_TEXT "%s\n" "${FULL_CHANGELOG_LINES[@]}" |
| 141 | + else |
| 142 | + FULL_CHANGELOG_TEXT=" (no merged PRs found in this release)" |
| 143 | + fi |
| 144 | + |
| 145 | + # Create PR body file to avoid quote issues |
| 146 | + cat > pr_body.txt << EOF |
| 147 | + This PR was automatically created by the release workflow. |
| 148 | +
|
| 149 | + ## Changelog |
| 150 | +
|
| 151 | + $CHANGELOG_SECTION |
| 152 | +
|
| 153 | + ## Full Changelog |
| 154 | +
|
| 155 | + $FULL_CHANGELOG_TEXT |
| 156 | + EOF |
| 157 | +
|
| 158 | + gh pr create \ |
| 159 | + --title "chore: Cut ${{ inputs.new_version }}" \ |
| 160 | + --body-file pr_body.txt \ |
| 161 | + --base release-$MAJOR_MINOR_VERSION \ |
| 162 | + --head release-prep-${{ inputs.new_version }} \ |
| 163 | + --reviewer @sig-instrumentation-approvers \ |
| 164 | + --assignee @sig-instrumentation-leads |
| 165 | + |
| 166 | + rm pr_body.txt |
| 167 | + env: |
| 168 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments