Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Fix version parser #1303

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 68 additions & 33 deletions .github/workflows/deploy-package.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Deploy NuGet package

on:
push:
branches:
- DaveSkender-patch-1

workflow_dispatch:
inputs:
environment:
Expand All @@ -23,19 +27,35 @@ on:
required: true

concurrency:
group: ${{ inputs.environment }}
group: ${{ github.ref_name }}
cancel-in-progress: true

jobs:
build:
package:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version_info.outputs.version }}
pkg_url: ${{ steps.package_info.outputs.pkg_url }}
pkg_name: ${{ steps.package_info.outputs.pkg_name }}
url: ${{ steps.package_info.outputs.url }}
name: ${{ steps.package_info.outputs.name }}
environ: ${{ steps.settings.outputs.environ }}
preview: ${{ steps.settings.outputs.preview }}
dry_run: ${{ steps.settings.outputs.dry_run }}

steps:

- name: Set default inputs for dispatch
id: settings
run: |
if [[ "${{ github.event_name }}" == "worfklow_dispatch" ]]; then
echo "environ=${{ inputs.environment }}" >> $GITHUB_OUTPUT
echo "preview=${{ inputs.preview }}" >> $GITHUB_OUTPUT
echo "dry_run=${{ inputs.dry_run }}" >> $GITHUB_OUTPUT
else
echo "environ=no_env" >> $GITHUB_OUTPUT
echo "preview=true" >> $GITHUB_OUTPUT
echo "dry_run=true" >> $GITHUB_OUTPUT
fi

- name: Checkout source
uses: actions/checkout@v4
with:
Expand All @@ -47,6 +67,12 @@ jobs:
dotnet-version: "9.x"
dotnet-quality: "ga"

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "9.x"
dotnet-quality: "ga"

- name: Setup GitVersion
uses: gittools/actions/gitversion/[email protected]
with:
Expand All @@ -71,10 +97,10 @@ jobs:
base="${{ steps.gitversion.outputs.majorMinorPatch }}"

# determine preview suffix
preview_tag="${{ inputs.preview && '-preview.' || '' }}"
preview_tag="${{ steps.settings.outputs.preview && '-preview.' || '' }}"

# determine preview number
preview_num="${{ inputs.preview && steps.gitversion.outputs.preReleaseNumber || '' }}"
preview_num="${{ steps.settings.outputs.preview && steps.gitversion.outputs.preReleaseNumber || '' }}"

# combine all parts
ver="${base}${preview_tag}${preview_num}"
Expand All @@ -85,12 +111,11 @@ jobs:
id: package_info
run: |
PACKAGE_NAME=$(xmllint --xpath "//PropertyGroup/PackageId/text()" src/Indicators.csproj)
echo "pkg_name=${PACKAGE_NAME}" >> $GITHUB_OUTPUT
if [[ "${{ inputs.environment }}" == "nuget.org" ]]; then
echo "pkg_url=https://www.nuget.org/packages/${PACKAGE_NAME}/${{ steps.version_info.outputs.version }}" >> $GITHUB_OUTPUT
echo "name=${PACKAGE_NAME}" >> $GITHUB_OUTPUT
if [[ "${{ steps.settings.outputs.environ }}" == "nuget.org" ]]; then
echo "url=https://www.nuget.org/packages/${PACKAGE_NAME}/${{ steps.version_info.outputs.version }}" >> $GITHUB_OUTPUT
else
echo "pkg_url=https://github.com/${{ github.repository }}/pkgs/nuget/${PACKAGE_NAME}" >> $GITHUB_OUTPUT
fi
echo "url=https://github.com/${{ github.repository }}/pkgs/nuget/${PACKAGE_NAME}" >> $GITHUB_OUTPUT

- name: Build library
run: >
Expand Down Expand Up @@ -126,10 +151,12 @@ jobs:
echo "| Patch | ${{ steps.gitversion.outputs.patch }} |"
echo "| Base | ${{ steps.gitversion.outputs.majorMinorPatch }} |"
echo "| Composed | ${{ steps.version_info.outputs.version }} |"
echo "| Package | ${{ steps.package_info.outputs.name }} |"
echo "| Package URL | ${{ steps.package_info.outputs.url }} |"
} >> $GITHUB_STEP_SUMMARY

deploy:
needs: build
needs: package
runs-on: ubuntu-latest
if: success()

Expand All @@ -138,8 +165,18 @@ jobs:
packages: write

environment:
name: ${{ !inputs.dry_run && inputs.environment || '' }}
url: ${{ needs.build.outputs.pkg_url }}
name: ${{ needs.package.outputs.environ }}
url: ${{ needs.package.outputs.url }}

env:
version: ${{ needs.package.outputs.version }}
preview: ${{ needs.package.outputs.preview }}
dry_run: ${{ needs.package.outputs.dry_run }}
environ: ${{ needs.package.outputs.environ }}
url: ${{ needs.package.outputs.url }}
name: ${{ needs.package.outputs.name }}
NUGET_PUBLISH_URL: ${{ needs.package.outputs.environ == 'nuget.org' && 'https://api.nuget.org/v3/index.json' || 'https://nuget.pkg.github.com/${{ github.repository }}/index.json' }}
NUGET_API_KEY: ${{ needs.package.outputs.environ == 'nuget.org' && secrets.NUGET_TOKEN || secrets.GITHUB_TOKEN }}

steps:

Expand All @@ -156,33 +193,31 @@ jobs:
path: NuGet

- name: Publish package
if: ${{ !inputs.dry_run }}
env:
API_KEY: ${{ inputs.environment == 'nuget.org' && secrets.NUGET_TOKEN || secrets.GITHUB_TOKEN }}
if: ${{ !env.dry_run }}
run: >
dotnet nuget push NuGet/*.nupkg
--source "${{ vars.NUGET_PUBLISH_URL }}"
--api-key "$API_KEY"
--source "${{ env.NUGET_PUBLISH_URL }}"
--api-key "${{ env.NUGET_API_KEY }}"
--skip-duplicate

- name: Tag and draft release note
uses: ncipollo/release-action@v1
if: ${{ !inputs.dry_run && inputs.environment == 'nuget.org' }}
if: ${{ !env.dry_run && env.environ == 'nuget.org' }}
with:
body: |
## Release ${{ needs.build.outputs.version }}
## Release ${{ env.version }}

📦 Package deployed to [${{ inputs.environment }}](${{ needs.build.outputs.pkg_url }})
📦 Package deployed to [${{ env.environ }}](${{ env.url }})

### Package Details
- **Name**: ${{ needs.build.outputs.pkg_name }}
- **Version**: ${{ needs.build.outputs.version }}
- **Preview**: ${{ inputs.preview && 'Yes' || 'No' }}
- **Name**: ${{ env.name }}
- **Version**: ${{ env.version }}
- **Preview**: ${{ env.preview && 'Yes' || 'No' }}
generateReleaseNotes: true
draft: true
makeLatest: ${{ !inputs.preview }}
prerelease: ${{ inputs.preview }}
tag: v${{ needs.build.outputs.version }}
makeLatest: ${{ !env.preview }}
prerelease: ${{ env.preview }}
tag: v${{ env.version }}
commit: ${{ github.sha }}
token: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -193,10 +228,10 @@ jobs:
echo "## Package Deployment"
echo "| Parameter | Value |"
echo "|:------------|:------|"
echo "| Mode | ${{ inputs.dry_run && '🔍 DRY RUN' || '🚀 DEPLOY' }} |"
echo "| Mode | ${{ env.dry_run && '🔍 DRY RUN' || '🚀 DEPLOY' }} |"
echo "| Status | ${{ job.status == 'success' && '✅ Success' || '❌ Failed' }} |"
echo "| Environment | ${{ inputs.environment }} |"
echo "| Version | ${{ needs.build.outputs.version }} |"
echo "| Package | [${{ needs.build.outputs.pkg_name }}](${{ needs.build.outputs.pkg_url }}) |"
echo "| Preview | ${{ inputs.preview && '✓' || '✗' }} |"
echo "| Environment | ${{ env.environ }} |"
echo "| Version | ${{ env.version }} |"
echo "| Package | [${{ env.name }}](${{ env.url }}) |"
echo "| Preview | ${{ env.preview && '✓' || '✗' }} |"
} >> $GITHUB_STEP_SUMMARY
Loading