Release Please #152
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: Release Please | |
| on: | |
| push: | |
| branches: | |
| - main | |
| schedule: | |
| - cron: "0 3 * * *" | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| update-dependencies: | |
| if: ${{ github.event_name != 'push' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Check whether 30 days have passed since the latest tag | |
| id: cadence | |
| shell: bash | |
| run: | | |
| if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
| echo "should_run=true" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| latest_tag="$(git tag --sort=-creatordate | head -n 1)" | |
| if [[ -z "$latest_tag" ]]; then | |
| echo "should_run=true" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| now_epoch="$(date -u +%s)" | |
| last_tag_epoch="$(git log -1 --format=%ct "$latest_tag")" | |
| thirty_days=$((30 * 24 * 60 * 60)) | |
| if (( now_epoch - last_tag_epoch >= thirty_days )); then | |
| echo "should_run=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "should_run=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Setup .NET | |
| if: ${{ steps.cadence.outputs.should_run == 'true' }} | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: | | |
| 8.0.x | |
| 9.0.x | |
| 10.0.x | |
| - name: Update NuGet dependencies | |
| if: ${{ steps.cadence.outputs.should_run == 'true' }} | |
| run: dotnet package update --project ./collection-merger.sln | |
| - name: Restore dependencies | |
| if: ${{ steps.cadence.outputs.should_run == 'true' }} | |
| run: dotnet restore ./collection-merger.sln | |
| - name: Verify code formatting | |
| if: ${{ steps.cadence.outputs.should_run == 'true' }} | |
| run: dotnet format ./collection-merger.sln --verify-no-changes --verbosity diagnostic | |
| - name: Build | |
| if: ${{ steps.cadence.outputs.should_run == 'true' }} | |
| run: dotnet build ./collection-merger.sln --configuration Release --no-restore | |
| - name: Run tests | |
| if: ${{ steps.cadence.outputs.should_run == 'true' }} | |
| run: dotnet test ./collection-merger.sln --configuration Release --no-build --verbosity normal | |
| - name: Create pull request | |
| if: ${{ steps.cadence.outputs.should_run == 'true' }} | |
| uses: peter-evans/create-pull-request@v7 | |
| with: | |
| branch: automation/monthly-dependency-updates | |
| delete-branch: true | |
| commit-message: "fix(deps): update dependencies" | |
| title: "fix(deps): update dependencies" | |
| body: | | |
| ## Summary | |
| - update NuGet dependencies used by the solution | |
| - verify formatting, build, and tests before opening the PR | |
| ## Notes | |
| - merging this PR will allow the existing release workflow to publish the next package version | |
| release-please: | |
| if: ${{ github.event_name == 'push' }} | |
| runs-on: ubuntu-latest | |
| outputs: | |
| release_created: ${{ steps.release.outputs.release_created }} | |
| tag_name: ${{ steps.release.outputs.tag_name }} | |
| body: ${{ steps.release.outputs.body }} | |
| steps: | |
| - uses: googleapis/release-please-action@v4 | |
| id: release | |
| with: | |
| config-file: release-please-config.json | |
| manifest-file: .release-please-manifest.json | |
| publish-nuget: | |
| needs: release-please | |
| if: ${{ needs.release-please.outputs.release_created }} | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| packages: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: | | |
| 8.0.x | |
| 9.0.x | |
| 10.0.x | |
| - name: Install dotnet-format | |
| shell: bash | |
| run: | | |
| dotnet tool update --global dotnet-format || dotnet tool install --global dotnet-format | |
| echo "$HOME/.dotnet/tools" >> "$GITHUB_PATH" | |
| - name: Restore dependencies | |
| run: dotnet restore ./collection-merger.sln | |
| - name: Verify code formatting | |
| run: dotnet format ./collection-merger.sln --verify-no-changes --verbosity diagnostic | |
| - name: Build | |
| run: dotnet build ./collection-merger.sln --configuration Release --no-restore | |
| - name: Run tests | |
| run: dotnet test ./collection-merger.sln --configuration Release --no-build --verbosity normal | |
| - name: Pack NuGet package | |
| shell: bash | |
| run: | | |
| RELEASE_NOTES="${{ needs.release-please.outputs.body }}" | |
| dotnet pack ./src/CollectionMerger/CollectionMerger.csproj \ | |
| --configuration Release \ | |
| --no-build \ | |
| --output ./packages \ | |
| /p:PackageReleaseNotes="$RELEASE_NOTES" | |
| - name: Publish to NuGet.org | |
| env: | |
| NUGET_TOKEN: ${{ secrets.NUGET_API_KEY || secrets.NUGET_TOKEN }} | |
| run: dotnet nuget push ./packages/*.nupkg --api-key ${{ env.NUGET_TOKEN }} --source https://api.nuget.org/v3/index.json --skip-duplicate | |
| - name: Upload package to GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: ${{ needs.release-please.outputs.tag_name }} | |
| files: ./packages/*.nupkg | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |