From 1193af906d0a8e6ed9df7eac407ffafa21355d2a Mon Sep 17 00:00:00 2001 From: KlaasWhite Date: Sat, 24 Oct 2026 17:09:02 +0200 Subject: [PATCH] Change release system to be tag based --- .github/workflows/pr-build.yml | 2 +- .github/workflows/pr-version.yml | 74 ------------------- .github/workflows/rc-build.yml | 2 +- .github/workflows/redirect-external-pr.yml | 16 ++-- .github/workflows/release.yml | 85 +++++++++------------- README.md | 5 ++ 6 files changed, 50 insertions(+), 134 deletions(-) delete mode 100644 .github/workflows/pr-version.yml diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml index 81d898b..8674770 100644 --- a/.github/workflows/pr-build.yml +++ b/.github/workflows/pr-build.yml @@ -4,7 +4,7 @@ on: pull_request: # Re-run the version calculation when labels are added or when new commits are pushed types: [opened, synchronize, labeled, reopened, edited] - branches: [main, dev] + branches: [main] permissions: pull-requests: write diff --git a/.github/workflows/pr-version.yml b/.github/workflows/pr-version.yml deleted file mode 100644 index dcafbee..0000000 --- a/.github/workflows/pr-version.yml +++ /dev/null @@ -1,74 +0,0 @@ -name: PR Version Preview - -on: - pull_request: - # Re-run the version calculation when labels are added or when new commits are pushed - types: [opened, synchronize, labeled, reopened, edited] - branches: [main] - -permissions: - pull-requests: write - contents: read - -jobs: - preview-version: - # Only run for local PRs - if: github.event.pull_request.head.repo.full_name == github.repository - runs-on: ubuntu-latest - - steps: - # Checkout full history and all tags - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - fetch-tags: true - - # Get latest tag and calculate next version - - name: Get latest tag and bump type - id: version - run: | - # Be defensive and robust: use awk to split version numbers and always quote $GITHUB_OUTPUT - git fetch --tags || true - current=$(git describe --tags --abbrev=0 2>/dev/null || true) - if [ -z "$current" ]; then - echo "No tags found, defaulting to 0.0.0" - current="0.0.0" - fi - - # Remove leading 'v' then extract parts using awk - ver=${current#v} - major=$(printf "%s" "$ver" | awk -F. '{print $1+0}') - minor=$(printf "%s" "$ver" | awk -F. '{print $2+0}') - patch=$(printf "%s" "$ver" | awk -F. '{print $3+0}') - - # Determine bump type from PR labels (safe interpolation) - LABELS="${{ join(github.event.pull_request.labels.*.name, ' ') }}" - if printf "%s" "$LABELS" | grep -q "major"; then - major=$((major+1)); minor=0; patch=0; type="major" - elif printf "%s" "$LABELS" | grep -q "minor"; then - minor=$((minor+1)); patch=0; type="minor" - else - patch=$((patch+1)); type="patch" - fi - - next="${major}.${minor}.${patch}" - - # Safely write outputs - if [ -n "$GITHUB_OUTPUT" ]; then - # Write all outputs in one redirect to avoid multiple open/close - { - printf '%s\n' "current=$current" "next=$next" "type=$type" - } >> "$GITHUB_OUTPUT" - else - # Fallback to printing if GITHUB_OUTPUT not available (for local debugging) - echo "current=$current" - echo "next=$next" - echo "type=$type" - fi - - - name: Comment version preview - uses: peter-evans/create-or-update-comment@v4 - with: - issue-number: ${{ github.event.pull_request.number }} - body: | - **Next version:** **${{ steps.version.outputs.next }}** diff --git a/.github/workflows/rc-build.yml b/.github/workflows/rc-build.yml index 8b0ec6c..4160645 100644 --- a/.github/workflows/rc-build.yml +++ b/.github/workflows/rc-build.yml @@ -2,7 +2,7 @@ name: Release new RC release on: push: - branches: [dev] + branches: [main] env: DOTNET_VERSION: 10.0 diff --git a/.github/workflows/redirect-external-pr.yml b/.github/workflows/redirect-external-pr.yml index c6762d0..17cf136 100644 --- a/.github/workflows/redirect-external-pr.yml +++ b/.github/workflows/redirect-external-pr.yml @@ -3,7 +3,7 @@ name: Redirect external PRs on: pull_request_target: types: [opened, reopened] - branches: [main, dev] + branches: [main] permissions: contents: write @@ -16,15 +16,15 @@ jobs: runs-on: ubuntu-latest steps: - - name: Resolve dev branch SHA - id: devsha + - name: Resolve main branch SHA + id: mainsha env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - DEV_SHA=$(gh api repos/${{ github.repository }}/git/ref/heads/dev --jq '.object.sha') - echo "sha=$DEV_SHA" >> $GITHUB_OUTPUT + MAIN_SHA=$(gh api repos/${{ github.repository }}/git/ref/heads/main --jq '.object.sha') + echo "sha=$MAIN_SHA" >> $GITHUB_OUTPUT - - name: Create internal feature branch from dev + - name: Create internal feature branch from main env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | @@ -34,11 +34,11 @@ jobs: SAFE_SOURCE_BRANCH=$(echo "$SOURCE_BRANCH" | tr '/' '-') NEW_BRANCH="feature/external/pr-${PR_NUMBER}-${SAFE_SOURCE_BRANCH}" - echo "Creating branch $NEW_BRANCH from dev" + echo "Creating branch $NEW_BRANCH from main" gh api repos/${{ github.repository }}/git/refs \ -f ref="refs/heads/$NEW_BRANCH" \ - -f sha="${{ steps.devsha.outputs.sha }}" + -f sha="${{ steps.mainsha.outputs.sha }}" - name: Retarget PR to new branch env: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 87e73fe..c82de69 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,9 +1,12 @@ -name: Release new version +name: Release from version tag on: - pull_request: - types: [closed] - branches: [main] + push: + tags: + - '[0-9]*.[0-9]*.[0-9]*' + +permissions: + contents: write env: DOTNET_VERSION: 10.0 @@ -19,7 +22,7 @@ jobs: outputs: new_version: ${{ steps.version.outputs.new_version }} prev_version: ${{ steps.version.outputs.prev_version }} - hash_version: ${{ steps.version.outputs.hash_version }} + release_tag: ${{ steps.version.outputs.release_tag }} api_changed: ${{ steps.api_check.outputs.api_changed }} steps: - uses: actions/checkout@v4 @@ -31,49 +34,31 @@ jobs: with: dotnet-version: ${{ env.DOTNET_VERSION }} - - name: Determine version bump + - name: Read version from release tag id: version + env: + RELEASE_TAG: ${{ github.ref_name }} run: | - # Be defensive and robust: use awk to split version numbers and always quote $GITHUB_OUTPUT - git fetch --tags || true - current=$(git describe --tags --abbrev=0 2>/dev/null || true) - if [ -z "$current" ]; then - echo "No tags found, defaulting to 0.0.0" - current="0.0.0" + if [[ ! "$RELEASE_TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "::error::Release tags must use semantic version format X.Y.Z (for example, 1.2.3)." + exit 1 fi - # Remove leading 'v' then extract parts using awk - ver=${current#v} - major=$(printf "%s" "$ver" | awk -F. '{print $1+0}') - minor=$(printf "%s" "$ver" | awk -F. '{print $2+0}') - patch=$(printf "%s" "$ver" | awk -F. '{print $3+0}') - - # Determine bump type from PR labels (safe interpolation) - LABELS="${{ join(github.event.pull_request.labels.*.name, ' ') }}" - if printf "%s" "$LABELS" | grep -q "major"; then - major=$((major+1)); minor=0; patch=0; type="major" - elif printf "%s" "$LABELS" | grep -q "minor"; then - minor=$((minor+1)); patch=0; type="minor" - else - patch=$((patch+1)); type="patch" + previous_tag="" + if git rev-parse --verify "${GITHUB_SHA}^" >/dev/null 2>&1; then + previous_tag=$(git tag --merged "${GITHUB_SHA}^" --format='%(refname:short)' \ + | awk '/^[0-9]+\.[0-9]+\.[0-9]+$/ { print }' \ + | sort -V \ + | tail -n 1) fi - new_version="${major}.${minor}.${patch}" - - echo "Next version: $new_version" - echo "RC version: $hash_version" - - echo "prev_version=$current" >> $GITHUB_OUTPUT - echo "new_version=$new_version" >> $GITHUB_OUTPUT - - - name: Tag and push new version - run: | - git config user.name "github-actions" - git config user.email "actions@github.com" - - NEW_VERSION="${{ steps.version.outputs.new_version }}" - git tag "$NEW_VERSION" - git push origin "$NEW_VERSION" + echo "Release version: $RELEASE_TAG" + echo "Previous release tag: ${previous_tag:-none}" + { + echo "release_tag=$RELEASE_TAG" + echo "new_version=$RELEASE_TAG" + echo "prev_version=$previous_tag" + } >> "$GITHUB_OUTPUT" - name: Setup NuGet source run: | @@ -107,7 +92,7 @@ jobs: - name: Check whether StarMap.API changed since previous tag id: api_check run: | - current="${{ steps.version.outputs.new_version }}" + current_commit="${GITHUB_SHA}" prev="${{ steps.version.outputs.prev_version }}" echo "previous_tag=$prev" >> $GITHUB_OUTPUT @@ -118,9 +103,9 @@ jobs: fi echo "Previous tag: $prev" - echo "Current commit: $current" + echo "Current commit: $current_commit" - diff=$(git diff --name-only "$prev" "$current") + diff=$(git diff --name-only "$prev" "$current_commit") { echo "diff_files<