Files
ImgBBApi/.github/workflows/publish.yml
T

99 lines
2.7 KiB
YAML

name: Publish NuGet package
on:
push:
tags:
- '*'
workflow_dispatch:
permissions:
contents: read
packages: write
id-token: write
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Verify publishing credentials
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NUGET_USER: ${{ secrets.NUGET_USER }}
run: |
if [[ -z "$GITHUB_TOKEN" ]]; then
echo "GitHub Packages token is not available."
exit 1
fi
if [[ -z "$NUGET_USER" ]]; then
echo "The NUGET_USER secret is missing or empty."
exit 1
fi
- name: Set up .NET SDKs
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
5.0.x
6.0.x
7.0.x
8.0.x
10.0.x
- name: Restore dependencies
run: dotnet restore ImgBBApi.csproj
- name: Create NuGet package
shell: bash
run: |
PACKAGE_VERSION_ARGS=()
if [[ "$GITHUB_REF_TYPE" == "tag" ]]; then
PACKAGE_VERSION_ARGS=(-p:PackageVersion="${GITHUB_REF_NAME#v}")
fi
dotnet pack ImgBBApi.csproj \
--configuration Release \
--no-restore \
--output ./artifacts \
"${PACKAGE_VERSION_ARGS[@]}"
- name: Upload package artifact
uses: actions/upload-artifact@v4
with:
name: ImgBBApi-nuget-package
path: ./artifacts/*.nupkg
if-no-files-found: error
- name: Publish to GitHub Packages
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
run: |
for package in ./artifacts/*.nupkg; do
dotnet nuget push "$package" \
--source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" \
--api-key "${{ secrets.GITHUB_TOKEN }}" \
--skip-duplicate
done
- name: NuGet login
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
uses: NuGet/login@v1
id: nuget-login
with:
user: ${{ secrets.NUGET_USER }}
- name: Publish to NuGet.org
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
run: |
for package in ./artifacts/*.nupkg; do
dotnet nuget push "$package" \
--source "https://api.nuget.org/v3/index.json" \
--api-key "${{ steps.nuget-login.outputs.NUGET_API_KEY }}" \
--skip-duplicate
done