|
1 | | -name: Publish a NuGet package |
| 1 | +name: Publish NuGet package |
2 | 2 | on: |
3 | | -# push: |
4 | | -# branches: [ main ] |
5 | | -# paths: |
6 | | -# - 'src/LEGO.AsyncAPI/**' |
7 | | -# - 'src/LEGO.AsyncAPI.Readers/**' |
8 | | -# - ".github/workflows/release-package.yml" |
9 | | -# - '!**/*.md' |
10 | 3 | workflow_dispatch: |
11 | 4 |
|
12 | 5 | jobs: |
| 6 | + prereleaseCheck: |
| 7 | + runs-on: ubuntu-latest |
| 8 | + environment: AsyncAPI |
| 9 | + name: Check release |
| 10 | + steps: |
| 11 | + - name: Checkout repository |
| 12 | + uses: actions/checkout@v1 |
| 13 | + |
| 14 | + - name: Semantic Release |
| 15 | + uses: cycjimmy/semantic-release-action@v3 |
| 16 | + id: semantic |
| 17 | + with: |
| 18 | + extra_plugins: | |
| 19 | + conventional-changelog-conventionalcommits |
| 20 | + env: |
| 21 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 22 | + |
| 23 | + - name: Get token |
| 24 | + if: steps.semantic.outputs.new_release_published == 'true' |
| 25 | + id: get_token |
| 26 | + uses: peter-murray/[email protected] |
| 27 | + with: |
| 28 | + application_id: ${{ secrets.APPLICATION_ID }} |
| 29 | + application_private_key: ${{ secrets.APPLICATION_PRIVATE_KEY }} |
| 30 | + |
| 31 | + - name: Commit changes |
| 32 | + if: steps.semantic.outputs.new_release_published == 'true' |
| 33 | + env: |
| 34 | + GITHUB_TOKEN: ${{ steps.get_token.outputs.token }} |
| 35 | + FILE_TO_COMMIT: CHANGELOG.md |
| 36 | + DESTINATION_BRANCH: ${{ github.ref }} |
| 37 | + run: | |
| 38 | + export MESSAGE="chore: update $FILE_TO_COMMIT" |
| 39 | + export SHA=$( git rev-parse $DESTINATION_BRANCH:$FILE_TO_COMMIT ) |
| 40 | + export CONTENT=$( base64 -i $FILE_TO_COMMIT ) |
| 41 | + gh api --method PUT /repos/:owner/:repo/contents/$FILE_TO_COMMIT \ |
| 42 | + --field message="$MESSAGE" \ |
| 43 | + --field content="$CONTENT" \ |
| 44 | + --field encoding="base64" \ |
| 45 | + --field branch="$DESTINATION_BRANCH" \ |
| 46 | + --field sha="$SHA" |
| 47 | +
|
| 48 | + outputs: |
| 49 | + trigger_release: ${{ steps.semantic.outputs.new_release_published }} |
| 50 | + version: ${{ steps.semantic.outputs.new_release_published == 'true' && steps.semantic.outputs.new_release_version }} |
| 51 | + |
13 | 52 | release: |
14 | 53 | runs-on: ubuntu-latest |
15 | 54 | name: Publish NuGet packages |
| 55 | + needs: prereleaseCheck |
| 56 | + environment: AsyncAPI |
16 | 57 | strategy: |
17 | 58 | matrix: |
18 | | - package-name: [ "LEGO.AsyncAPI", "LEGO.AsyncAPI.Readers"] |
| 59 | + package-name: [ "LEGO.AsyncAPI", "LEGO.AsyncAPI.Readers" ] |
19 | 60 | steps: |
20 | 61 | - name: Checkout repository |
21 | 62 | uses: actions/checkout@v1 |
22 | 63 |
|
23 | | - - name: Semantic Release |
24 | | - uses: cycjimmy/semantic-release-action@v3 |
25 | | - id: semantic # Need an `id` for output variables |
26 | | - with: |
27 | | - extra_plugins: | |
28 | | - conventional-changelog-conventionalcommits |
29 | | - env: |
30 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
31 | | - |
32 | 64 | - name: Setup .NET Core @ Latest |
| 65 | + if: needs.prereleaseCheck.outputs.trigger_release == 'true' |
33 | 66 | uses: actions/setup-dotnet@v1 |
34 | | - with: |
35 | | - source-url: https://nuget.pkg.github.com/LEGO/index.json |
36 | | - env: |
37 | | - NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} |
38 | 67 |
|
39 | 68 | - name: Build ${{ matrix.package-name }} project and pack NuGet package |
40 | | - if: steps.semantic.outputs.new_release_published == 'true' |
41 | | - run: dotnet pack src/${{ matrix.package-name }}/${{ matrix.package-name }}.csproj -c Release -o out-${{ matrix.package-name }} -p:PackageVersion=${{ steps.semantic.outputs.new_release_version }}-prerelease |
| 69 | + if: needs.prereleaseCheck.outputs.trigger_release == 'true' |
| 70 | + run: dotnet pack src/${{ matrix.package-name }}/${{ matrix.package-name }}.csproj -c Release -o out-${{ matrix.package-name }} -p:PackageVersion=${{ needs.prereleaseCheck.outputs.version }} |
42 | 71 |
|
43 | 72 | - name: Push generated package to GitHub Packages registry |
44 | | - if: steps.semantic.outputs.new_release_published == 'true' |
45 | | - run: dotnet nuget push out-${{ matrix.package-name }}/*.nupkg --skip-duplicate -n --api-key ${{secrets.GITHUB_TOKEN}} |
46 | | - |
47 | | - - name: Create Pull Request |
48 | | - if: steps.semantic.outputs.new_release_published == 'true' |
49 | | - id: pr |
50 | | - uses: peter-evans/create-pull-request@v4 |
51 | | - with: |
52 | | - token: ${{ secrets.GITHUB_TOKEN }} |
53 | | - title: 'chore: update Changelog' |
54 | | - base: main |
55 | | - add-paths: | |
56 | | - CHANGELOG.md |
| 73 | + if: needs.prereleaseCheck.outputs.trigger_release == 'true' |
| 74 | + run: dotnet nuget push out-${{ matrix.package-name }}/*.nupkg -s https://api.nuget.org/v3/index.json --skip-duplicate -n --api-key ${{secrets.NUGET}} |
0 commit comments