publish #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: publish | |
| on: | |
| workflow_dispatch: | |
| push: | |
| tags: | |
| - "v*" | |
| permissions: | |
| contents: read | |
| packages: write | |
| jobs: | |
| pack_and_publish: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| id-token: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Determine package version | |
| id: version | |
| shell: bash | |
| run: | | |
| REF="${{ github.ref }}" | |
| EVENT="${{ github.event_name }}" | |
| CSPROJ="src/Kapusch.FacebookApisForAndroidComponents/Kapusch.FacebookApisForAndroidComponents.csproj" | |
| BASE_VERSION=$(grep -oE '<Version>[^<]+' "$CSPROJ" | head -n 1 | sed 's/<Version>//' || echo "0.1.0") | |
| if [[ "$REF" =~ ^refs/tags/v ]]; then | |
| VERSION="${REF#refs/tags/v}" | |
| PUBLISH_TARGET="nuget" | |
| git fetch origin +refs/heads/*:refs/remotes/origin/* | |
| TAGGED_SHA="${{ github.sha }}" | |
| CONTAINING_BRANCHES=$(git for-each-ref --format='%(refname:short)' refs/remotes/origin --contains "$TAGGED_SHA") | |
| ON_MASTER="false" | |
| ON_RELEASE="false" | |
| while IFS= read -r branch; do | |
| [[ "$branch" == "origin/master" ]] && ON_MASTER="true" | |
| [[ "$branch" == origin/release/* ]] && ON_RELEASE="true" | |
| done <<< "$CONTAINING_BRANCHES" | |
| if [[ "$VERSION" == *-* ]]; then | |
| if [[ "$ON_RELEASE" != "true" ]]; then | |
| echo "ERROR: Pre-release tag v$VERSION must point to a commit contained in origin/release/*" | |
| exit 1 | |
| fi | |
| else | |
| if [[ "$ON_MASTER" != "true" ]]; then | |
| echo "ERROR: Stable tag v$VERSION must point to a commit contained in origin/master" | |
| exit 1 | |
| fi | |
| fi | |
| else | |
| COMMIT_SHORT=$(git rev-parse --short HEAD) | |
| RUN_NUMBER="${{ github.run_number }}" | |
| VERSION="${BASE_VERSION}-preview.${RUN_NUMBER}.${COMMIT_SHORT}" | |
| PUBLISH_TARGET="github" | |
| fi | |
| echo "version=${VERSION}" >> "$GITHUB_OUTPUT" | |
| echo "publish_target=${PUBLISH_TARGET}" >> "$GITHUB_OUTPUT" | |
| echo "Package version: ${VERSION}" | |
| echo "Publish target: ${PUBLISH_TARGET}" | |
| - uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: "10.0.x" | |
| - uses: actions/setup-java@v4 | |
| with: | |
| distribution: "microsoft" | |
| java-version: "21" | |
| - name: Setup Android SDK | |
| uses: android-actions/setup-android@v3 | |
| - name: Install Android workload | |
| run: | | |
| dotnet workload install android | |
| - name: Cache NuGet | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.nuget/packages | |
| key: ${{ runner.os }}-nuget-${{ hashFiles('global.json', '**/*.csproj') }} | |
| - name: Build Android wrapper | |
| run: | | |
| bash src/Kapusch.FacebookApisForAndroidComponents/Native/Android/build.sh | |
| - name: Restore pinned Facebook AARs | |
| run: | | |
| bash src/Kapusch.FacebookApisForAndroidComponents/Native/Android/restore-facebook-aars.sh | |
| - name: Pack | |
| run: | | |
| dotnet pack src/Kapusch.FacebookApisForAndroidComponents/Kapusch.FacebookApisForAndroidComponents.csproj \ | |
| -c Release \ | |
| -o artifacts/nuget \ | |
| /p:PackageVersion="${{ steps.version.outputs.version }}" | |
| - name: Push to NuGet.org | |
| if: steps.version.outputs.publish_target == 'nuget' | |
| uses: NuGet/login@v1 | |
| id: nuget_login | |
| with: | |
| user: ${{ secrets.NUGET_USER }} | |
| - name: Push to NuGet.org | |
| if: steps.version.outputs.publish_target == 'nuget' | |
| run: | | |
| dotnet nuget push artifacts/nuget/*.nupkg \ | |
| --api-key "${{ steps.nuget_login.outputs.NUGET_API_KEY }}" \ | |
| --source "https://api.nuget.org/v3/index.json" \ | |
| --skip-duplicate | |
| - name: Push to GitHub Packages | |
| if: steps.version.outputs.publish_target == 'github' | |
| env: | |
| NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| dotnet nuget push artifacts/nuget/*.nupkg \ | |
| --api-key "$NUGET_AUTH_TOKEN" \ | |
| --source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" \ | |
| --skip-duplicate |