Nuget-Release #4
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: Nuget-Release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'SemVer (e.g., 1.2.3 or 1.2.3-beta.1)' | |
| required: true | |
| type: string | |
| permissions: | |
| contents: write | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| env: | |
| DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} | |
| steps: | |
| - uses: actions/checkout@v6.0.2 | |
| with: | |
| fetch-depth: 0 | |
| ref: ${{ env.DEFAULT_BRANCH }} | |
| - name: Validate version (SemVer) | |
| id: semver | |
| run: | | |
| set -euo pipefail | |
| VERSION="${{ github.event.inputs.version }}" | |
| if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z\.-]+)?$ ]]; then | |
| echo "VERSION=$VERSION" >> "$GITHUB_ENV" | |
| if [[ "$VERSION" == *-* ]]; then | |
| echo "PRERELEASE=true" >> "$GITHUB_ENV" | |
| else | |
| echo "PRERELEASE=false" >> "$GITHUB_ENV" | |
| fi | |
| else | |
| echo "Provided version '$VERSION' is not SemVer." >&2 | |
| exit 1 | |
| fi | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v5.1.0 | |
| with: | |
| dotnet-version: '10.0.x' | |
| - name: Set date | |
| run: | | |
| DATE=$(date +'%Y-%m-%d') | |
| echo "DATE=$DATE" >> $GITHUB_ENV | |
| - name: Update CITATION.cff (version + date) | |
| run: | | |
| # Top-level | |
| sed -i "s/^version:.*/version: \"${VERSION}\"/" CITATION.cff | |
| sed -i "s/^date-released:.*/date-released: \"${DATE}\"/" CITATION.cff | |
| # preferred-citation (two-space indent) | |
| sed -i "s/^ version:.*/ version: \"${VERSION}\"/" CITATION.cff | |
| sed -i "s/^ date-released:.*/ date-released: \"${DATE}\"/" CITATION.cff | |
| - name: Commit CITATION.cff to default branch | |
| run: | | |
| set -euo pipefail | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add CITATION.cff | |
| if ! git diff --cached --quiet; then | |
| git commit -m "chore: release ${VERSION} (update CITATION.cff)" | |
| git push origin HEAD:${DEFAULT_BRANCH} | |
| else | |
| echo "No changes to CITATION.cff." | |
| fi | |
| - name: Install xmlstarlet (for parsing csproj) | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y xmlstarlet | |
| - name: Build RELEASE_NOTES.md from PackageReleaseNotes | |
| run: | | |
| set -euo pipefail | |
| echo "The following items have been fixed in this release:" > RELEASE_NOTES.md | |
| echo "" >> RELEASE_NOTES.md | |
| mapfile -t CSPROJS < <(git ls-files '*.csproj' | sort) | |
| for csproj in "${CSPROJS[@]}"; do | |
| # PackageId (fallback to file name) | |
| pkg_id="$(xmlstarlet sel -t -v '(//Project/PropertyGroup/PackageId)[1]' "$csproj" 2>/dev/null || true)" | |
| if [ -z "$pkg_id" ]; then | |
| pkg_id="$(basename "$csproj" .csproj)" | |
| fi | |
| # Version (fallback to the workflow input) | |
| pkg_version="$(xmlstarlet sel -t -v '(//Project/PropertyGroup/Version)[1]' "$csproj" 2>/dev/null || true)" | |
| if [ -z "$pkg_version" ]; then | |
| pkg_version="${VERSION}" | |
| fi | |
| # Multiline PackageReleaseNotes | |
| notes="$(xmlstarlet sel -t -v '(//Project/PropertyGroup/PackageReleaseNotes)[1]' "$csproj" 2>/dev/null || true)" | |
| notes="$(printf "%s" "$notes" | sed -e 's/\r$//')" | |
| if [ -n "$notes" ]; then | |
| printf "**%s [%s]**\n" "$pkg_id" "$pkg_version" >> RELEASE_NOTES.md | |
| while IFS= read -r line; do | |
| trimmed="$(printf "%s" "$line" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')" | |
| if [ -n "$trimmed" ]; then | |
| cleaned="$(printf "%s" "$trimmed" | sed 's/^- \{0,1\}//')" | |
| printf " - %s\n" "$cleaned" >> RELEASE_NOTES.md | |
| fi | |
| done <<< "$notes" | |
| echo "" >> RELEASE_NOTES.md | |
| fi | |
| done | |
| echo "----- RELEASE_NOTES.md -----" | |
| cat RELEASE_NOTES.md | |
| echo "" >> RELEASE_NOTES.md | |
| echo "Find the generated HTML documentation at https://modeldocs.sysml2.net/" >> RELEASE_NOTES.md | |
| echo "Find the web application at http://viewer.sysml2.net/" >> RELEASE_NOTES.md | |
| - name: Pack | |
| run: dotnet pack -c Release -o ReleaseBuilds SysML2.NET.sln | |
| - name: Push to NuGet | |
| env: | |
| NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} | |
| run: dotnet nuget push ReleaseBuilds/*.nupkg -k "$NUGET_API_KEY" -s https://api.nuget.org/v3/index.json --skip-duplicate | |
| - name: Create annotated tag at this commit | |
| run: | | |
| git tag -a "${VERSION}" -m "Release ${VERSION}" | |
| git push origin "refs/tags/${VERSION}" | |
| - name: Create draft GitHub release (attach EXE) | |
| uses: softprops/action-gh-release@v2.5.0 | |
| with: | |
| draft: true | |
| prerelease: ${{ env.PRERELEASE }} | |
| name: "SysML2.NET ${{ env.VERSION }}" | |
| tag_name: ${{ env.VERSION }} | |
| body_path: RELEASE_NOTES.md | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |