improve #25
This file contains 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, Release, and Publish to NuGet | ||
on: | ||
push: | ||
tags: | ||
- 'v*.*.*' | ||
jobs: | ||
build: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, windows-latest, macos-latest] | ||
include: | ||
- os: ubuntu-latest | ||
zip_command: zip -r aws-service-authenticator-linux.zip ./publish | ||
artifact_name: aws-service-authenticator-linux.zip | ||
- os: windows-latest | ||
zip_command: powershell Compress-Archive -Path ./publish/* -DestinationPath aws-service-authenticator-windows.zip | ||
artifact_name: aws-service-authenticator-windows.zip | ||
- os: macos-latest | ||
zip_command: zip -r aws-service-authenticator-macos.zip ./publish | ||
artifact_name: aws-service-authenticator-macos.zip | ||
env: | ||
SOLUTION_PATH: AwsServiceAuthenticator.sln | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v3 | ||
with: | ||
dotnet-version: '8.0.x' | ||
- name: Install dependencies | ||
run: dotnet restore ${{ env.SOLUTION_PATH }} | ||
- name: Build | ||
run: dotnet build --configuration Release ${{ env.SOLUTION_PATH }} | ||
- name: Publish | ||
run: dotnet publish --configuration Release --output ./publish ${{ env.SOLUTION_PATH }} | ||
- name: Create ZIP file | ||
run: ${{ matrix.zip_command }} | ||
- name: Archive release files | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: ${{ matrix.os }} | ||
path: ${{ matrix.artifact_name }} | ||
create_release: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- name: Download build artifacts (Linux) | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: ubuntu-latest | ||
path: ./downloads | ||
- name: Download build artifacts (Windows) | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: windows-latest | ||
path: ./downloads | ||
- name: Download build artifacts (macOS) | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: macos-latest | ||
path: ./downloads | ||
- name: Create a release | ||
id: create_release | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
files: | | ||
./downloads/aws-service-authenticator-linux.zip | ||
./downloads/aws-service-authenticator-windows.zip | ||
./downloads/aws-service-authenticator-macos.zip | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
publish_nuget: | ||
needs: create_release | ||
runs-on: ubuntu-latest | ||
environment: NugetOrg-Secret | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v3 | ||
with: | ||
dotnet-version: '8.0.x' | ||
- name: Restore dependencies | ||
run: dotnet restore | ||
- name: Build and pack | ||
run: dotnet pack --configuration Release --output ./nupkg | ||
- name: Debug NUGET_API_KEY | ||
run: | | ||
if [ -z "$NUGET_API_KEY" ]; then | ||
echo "NUGET_API_KEY is empty." | ||
exit 1 | ||
else | ||
echo "NUGET_API_KEY is present." | ||
fi | ||
env: | ||
NUGET_API_KEY: ${{ secrets.NugetOrg-Secret.NUGET_ORG_API_KEY }} | ||
- name: Publish to NuGet | ||
env: | ||
NUGET_API_KEY: ${{ secrets.NugetOrg-Secret.NUGET_ORG_API_KEY }} | ||
run: | | ||
dotnet nuget push ./nupkg/*.nupkg \ | ||
--api-key "$NUGET_API_KEY" \ | ||
--source "https://api.nuget.org/v3/index.json" | ||