1.6-pre #12
Workflow file for this run
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: Build and Publish NuGet Package | |
on: | |
release: | |
types: [published] | |
jobs: | |
build-and-publish: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
packages: write | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
PROJECTS: | | |
src/Moss.NET.Sdk/Moss.NET.Sdk.csproj | |
src/Moss.Net.Sdk.Templates/Moss.Net.Sdk.Templates.csproj | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4.1.7 | |
with: | |
fetch-depth: 0 | |
ref: main | |
- name: Set default branch. | |
run: | | |
git fetch origin | |
git remote set-head origin --auto | |
- name: Prepare repository | |
run: git checkout main | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: '8.x' | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: '9.x' | |
- name: Get release version | |
id: get_release | |
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV | |
- name: Init git | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
- name: Update .csproj files | |
run: | | |
RELEASE_VERSION=${{ env.RELEASE_VERSION }} | |
IFS=$'\n' # Set the Internal Field Separator to newline for reading multi-line variable | |
for PROJECT in $PROJECTS; do | |
sed -i "s/<Version>.*<\/Version>/<Version>${RELEASE_VERSION}<\/Version>/" "$PROJECT" | |
git add "$PROJECT" | |
done | |
- name: GIT commit and push overriding conflicts with local changes (verbose) | |
continue-on-error: true | |
run: | | |
git commit -m "Update version to ${{ env.RELEASE_VERSION }}" | |
git fetch origin | |
git rebase --strategy-option=theirs origin/main | |
git push | |
- name: Build and package | |
run: | | |
IFS=$'\n' # Set the Internal Field Separator to newline for reading multi-line variable | |
for PROJECT in $PROJECTS; do | |
dotnet build -c Release -o ./nuget "$PROJECT" | |
done | |
- name: Publish to NuGet | |
uses: actions/upload-artifact@v4 | |
with: | |
name: nuget-package | |
path: ./nuget/*.nupkg | |
- name: Publish package To Nuget | |
run: | | |
dotnet nuget push ./nuget/*.nupkg --api-key "${{ secrets.NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate |