Update knowlenge #10
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
| name: Create Release Tags | |
| # This workflow creates and pushes release tags for every commit to main, | |
| # and also supports manual tagging via workflow_dispatch. | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version number (e.g., 1.0.0). Leave empty to auto-generate.' | |
| required: false | |
| type: string | |
| create_release: | |
| description: 'Create GitHub Release' | |
| required: false | |
| type: boolean | |
| default: true | |
| jobs: | |
| create-tags: | |
| if: github.actor != 'github-actions[bot]' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Validate version format | |
| run: | | |
| INPUT_VERSION="${{ github.event.inputs.version }}" | |
| if [ -n "${INPUT_VERSION:-}" ]; then | |
| VERSION="$INPUT_VERSION" | |
| else | |
| VERSION="1.0.${{ github.run_number }}" | |
| fi | |
| if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
| echo "Error: Version must be in semver format (e.g., 1.0.0)" | |
| exit 1 | |
| fi | |
| echo "VERSION=$VERSION" >> $GITHUB_ENV | |
| - name: Extract major version | |
| run: | | |
| MAJOR_VERSION="v${VERSION%%.*}" | |
| FULL_VERSION="v${VERSION}" | |
| echo "MAJOR_VERSION=$MAJOR_VERSION" >> $GITHUB_ENV | |
| echo "FULL_VERSION=$FULL_VERSION" >> $GITHUB_ENV | |
| - name: Configure Git | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| - name: Update README with latest release | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| python - <<'PY' | |
| import os | |
| import re | |
| from pathlib import Path | |
| full_version = os.environ["FULL_VERSION"] | |
| usage_pattern = re.compile( | |
| r"^(?P<prefix>\s*-?\s*uses:\s*ProverCoderAI/action-release@)" | |
| r"v\d+(?:\.\d+){0,2}\b", | |
| flags=re.M, | |
| ) | |
| def update_readme(text: str) -> str: | |
| line = f"Latest release: `{full_version}` (auto-updated)" | |
| if re.search(r"^Latest release:.*$", text, flags=re.M): | |
| text = re.sub(r"^Latest release:.*$", line, text, flags=re.M) | |
| else: | |
| lines = text.splitlines() | |
| if lines: | |
| lines.insert(1, "") | |
| lines.insert(2, line) | |
| text = "\n".join(lines) + "\n" | |
| else: | |
| text = f"{line}\n" | |
| text = usage_pattern.sub(rf"\g<prefix>{full_version}", text) | |
| if not text.endswith("\n"): | |
| text += "\n" | |
| return text | |
| def update_usage_examples(text: str) -> str: | |
| text = usage_pattern.sub(rf"\g<prefix>{full_version}", text) | |
| if not text.endswith("\n"): | |
| text += "\n" | |
| return text | |
| readme_path = Path("README.md") | |
| readme_text = readme_path.read_text(encoding="utf-8") | |
| readme_path.write_text(update_readme(readme_text), encoding="utf-8") | |
| setup_path = Path("SETUP.md") | |
| if setup_path.exists(): | |
| setup_text = setup_path.read_text(encoding="utf-8") | |
| setup_path.write_text(update_usage_examples(setup_text), encoding="utf-8") | |
| PY | |
| - name: Commit README update | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| if git diff --quiet README.md SETUP.md; then | |
| echo "Docs are already up to date." | |
| exit 0 | |
| fi | |
| git add README.md SETUP.md | |
| git commit -m "chore(release): update docs for ${FULL_VERSION}" | |
| git fetch origin main | |
| git rebase origin/main | |
| git push origin "HEAD:main" | |
| - name: Create semantic version tag | |
| run: | | |
| echo "Creating tag ${FULL_VERSION}..." | |
| if git rev-parse "$FULL_VERSION" >/dev/null 2>&1; then | |
| echo "Tag ${FULL_VERSION} already exists; skipping." | |
| exit 0 | |
| fi | |
| git tag -a "$FULL_VERSION" -m "${FULL_VERSION} - Release of ProverCoderAI Release Action" | |
| git push origin "$FULL_VERSION" | |
| - name: Update major version tag | |
| run: | | |
| echo "Updating major version tag ${MAJOR_VERSION}..." | |
| if git rev-parse "$MAJOR_VERSION" >/dev/null 2>&1; then | |
| git tag -fa "$MAJOR_VERSION" -m "${MAJOR_VERSION} - Points to latest ${MAJOR_VERSION}.x.x release (${FULL_VERSION})" | |
| else | |
| git tag -a "$MAJOR_VERSION" -m "${MAJOR_VERSION} - Points to latest ${MAJOR_VERSION}.x.x release (${FULL_VERSION})" | |
| fi | |
| git push origin "$MAJOR_VERSION" --force | |
| - name: Verify tags | |
| run: | | |
| echo "Tags created successfully:" | |
| git tag -n1 | grep -E "^${FULL_VERSION}|^${MAJOR_VERSION}" | |
| echo "" | |
| echo "Action can now be used with:" | |
| echo " - uses: ProverCoderAI/action-release@${MAJOR_VERSION}" | |
| echo " - uses: ProverCoderAI/action-release@${FULL_VERSION}" | |
| - name: Create GitHub Release | |
| if: github.event_name == 'workflow_dispatch' && github.event.inputs.create_release == 'true' | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ env.FULL_VERSION }} | |
| name: ${{ env.FULL_VERSION }} | |
| generate_release_notes: true | |
| draft: false | |
| prerelease: false |