diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a91db33..21eb227 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,25 +53,72 @@ jobs: echo "BUMP=patch" >> $GITHUB_ENV fi - # Set NORELEASE as output of this step - echo "NORELEASE=${{ env.NORELEASE }}" >> $GITHUB_ENV + # Set NORELEASE + if [[ "$LABELS" == *"norelease"* ]]; then + echo "NORELEASE=true" >> $GITHUB_ENV + else + echo "NORELEASE=false" >> $GITHUB_ENV + fi env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: GitHub Tag Bump - id: tag_bump + - name: GitHub Tag Bump (Release) + id: tag_bump_release + if: env.PRERELEASE == 'false' && env.NORELEASE != 'true' uses: anothrNick/github-tag-action@1.73.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} INITIAL_VERSION: 1.0.0 DEFAULT_BUMP: ${{ env.BUMP }} - PRERELEASE: ${{ env.PRERELEASE }} - PRERELEASE_SUFFIX: 'preview' + PRERELEASE: false + + - name: Get Latest Tag + id: get_latest_tag + if: env.PRERELEASE == 'true' && env.NORELEASE != 'true' + run: | + LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "1.0.0") + echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT + + - name: Calculate Preview Version + id: calc_preview_version + if: env.PRERELEASE == 'true' && env.NORELEASE != 'true' + run: | + LATEST_TAG="${{ steps.get_latest_tag.outputs.latest_tag }}" + # Remove 'v' prefix if present + LATEST_TAG=${LATEST_TAG#v} + + # Split version into parts + IFS='.' read -r MAJOR MINOR PATCH <<< "$LATEST_TAG" + + # Bump version based on BUMP type + if [[ "${{ env.BUMP }}" == "major" ]]; then + MAJOR=$((MAJOR + 1)) + MINOR=0 + PATCH=0 + elif [[ "${{ env.BUMP }}" == "minor" ]]; then + MINOR=$((MINOR + 1)) + PATCH=0 + else + PATCH=$((PATCH + 1)) + fi + + # Create preview version + NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}-preview" + echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT + + - name: Create Preview Tag + id: tag_bump_preview + if: env.PRERELEASE == 'true' && env.NORELEASE != 'true' + run: | + NEW_VERSION="${{ steps.calc_preview_version.outputs.new_version }}" + git tag "$NEW_VERSION" + git push origin "$NEW_VERSION" + echo "new_tag=$NEW_VERSION" >> $GITHUB_OUTPUT outputs: - new_version: ${{ steps.tag_bump.outputs.new_tag }} - norelease: ${{ steps.tag_bump.outputs.norelease }} + new_version: ${{ env.NORELEASE != 'true' && (steps.tag_bump_release.outputs.new_tag || steps.tag_bump_preview.outputs.new_tag) || '' }} + norelease: ${{ env.NORELEASE }} publish-types: