Improve exception handling in IsNuGetPluginValid to prevent unnecessa… #22
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: ci | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - 'src/**' | |
| workflow_dispatch: | |
| jobs: | |
| generate-version: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Get last merged PR labels | |
| id: prlabels | |
| run: | | |
| PR=$(gh pr list --state merged --base main --limit 1 --json number --jq '.[0].number') | |
| LABELS=$(gh pr view $PR --json labels --jq '[.labels[].name]') | |
| echo "PR_NUMBER=$PR" >> $GITHUB_ENV | |
| echo "LABELS=$LABELS" >> $GITHUB_ENV | |
| # Fail if both preview and release are set | |
| if [[ "$LABELS" == *"preview"* && "$LABELS" == *"release"* ]]; then | |
| echo "❌ Both 'preview' and 'release' labels present. Only one allowed." | |
| exit 1 | |
| fi | |
| # Fail if neither preview nor release is set | |
| if [[ "$LABELS" != *"preview"* && "$LABELS" != *"release"* && "$LABELS" != *"norelease"* ]]; then | |
| echo "❌ PR must have 'preview', 'release' or 'norelease' label." | |
| exit 1 | |
| fi | |
| # Set PRERELEASE | |
| if [[ "$LABELS" == *"preview"* ]]; then | |
| echo "PRERELEASE=true" >> $GITHUB_ENV | |
| else | |
| echo "PRERELEASE=false" >> $GITHUB_ENV | |
| fi | |
| # Set bump type | |
| if [[ "$LABELS" == *"Semver-Major"* ]]; then | |
| echo "BUMP=major" >> $GITHUB_ENV | |
| elif [[ "$LABELS" == *"Semver-Minor"* ]]; then | |
| echo "BUMP=minor" >> $GITHUB_ENV | |
| else | |
| echo "BUMP=patch" >> $GITHUB_ENV | |
| fi | |
| # 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 (Release) | |
| id: tag_bump_release | |
| if: env.PRERELEASE == 'false' && env.NORELEASE != 'true' | |
| uses: anothrNick/[email protected] | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| INITIAL_VERSION: 1.0.0 | |
| DEFAULT_BUMP: ${{ env.BUMP }} | |
| 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: ${{ env.NORELEASE != 'true' && (steps.tag_bump_release.outputs.new_tag || steps.tag_bump_preview.outputs.new_tag) || '' }} | |
| norelease: ${{ env.NORELEASE }} | |
| publish-types: | |
| if: needs.generate-version.outputs.norelease != 'true' | |
| uses: ./.github/workflows/reusable-publish.yml | |
| with: | |
| project_path: src/Blake.Types/Blake.Types.csproj | |
| version: ${{ needs.generate-version.outputs.new_version }} | |
| secrets: inherit | |
| needs: generate-version | |
| publish-markdownparser: | |
| if: needs.generate-version.outputs.norelease != 'true' | |
| uses: ./.github/workflows/reusable-publish.yml | |
| with: | |
| project_path: src/Blake.MarkdownParser/Blake.MarkdownParser.csproj | |
| version: ${{ needs.generate-version.outputs.new_version }} | |
| wait_for_package_id: Blake.Types | |
| wait_for_package_version: ${{ needs.generate-version.outputs.new_version }} | |
| secrets: inherit | |
| needs: [publish-types, generate-version] | |
| publish-buildtools: | |
| if: needs.generate-version.outputs.norelease != 'true' | |
| uses: ./.github/workflows/reusable-publish.yml | |
| with: | |
| project_path: src/Blake.BuildTools/Blake.BuildTools.csproj | |
| version: ${{ needs.generate-version.outputs.new_version }} | |
| wait_for_package_id: Blake.MarkdownParser | |
| wait_for_package_version: ${{ needs.generate-version.outputs.new_version }} | |
| secrets: inherit | |
| needs: [publish-markdownparser, generate-version] | |
| publish-cli: | |
| if: needs.generate-version.outputs.norelease != 'true' | |
| uses: ./.github/workflows/reusable-publish.yml | |
| with: | |
| project_path: src/Blake.CLI/Blake.CLI.csproj | |
| version: ${{ needs.generate-version.outputs.new_version }} | |
| wait_for_package_id: Blake.BuildTools | |
| wait_for_package_version: ${{ needs.generate-version.outputs.new_version }} | |
| secrets: inherit | |
| needs: [publish-buildtools, generate-version] |