|
| 1 | +name: Publish NuGet on Tag |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + |
| 8 | +jobs: |
| 9 | + publish: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + contents: write |
| 13 | + packages: write |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout repository |
| 17 | + uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + fetch-depth: 0 |
| 20 | + |
| 21 | + - name: Extract version from tag |
| 22 | + id: version |
| 23 | + run: | |
| 24 | + TAG_NAME="${GITHUB_REF#refs/tags/}" |
| 25 | + VERSION="${TAG_NAME#v}" |
| 26 | + echo "tag=$TAG_NAME" >> $GITHUB_OUTPUT |
| 27 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 28 | + echo "Extracted version: $VERSION from tag: $TAG_NAME" |
| 29 | +
|
| 30 | + - name: Verify csproj version matches tag |
| 31 | + run: | |
| 32 | + CSPROJ_VERSION=$(grep -oP '<Version>\K[^<]+' ./DotnetDevKR.TailwindCSS/DotnetDevKR.TailwindCSS.csproj) |
| 33 | + TAG_VERSION="${{ steps.version.outputs.version }}" |
| 34 | +
|
| 35 | + if [ "$CSPROJ_VERSION" != "$TAG_VERSION" ]; then |
| 36 | + echo "Warning: csproj version ($CSPROJ_VERSION) doesn't match tag version ($TAG_VERSION)" |
| 37 | + echo "Updating csproj to match tag version..." |
| 38 | + sed -i "s|<Version>.*</Version>|<Version>$TAG_VERSION</Version>|" ./DotnetDevKR.TailwindCSS/DotnetDevKR.TailwindCSS.csproj |
| 39 | + else |
| 40 | + echo "Version match confirmed: $CSPROJ_VERSION" |
| 41 | + fi |
| 42 | +
|
| 43 | + - name: Setup .NET SDK |
| 44 | + uses: actions/setup-dotnet@v4 |
| 45 | + with: |
| 46 | + dotnet-version: "9.x" |
| 47 | + |
| 48 | + - name: Restore dependencies |
| 49 | + run: dotnet restore DotnetDevKR.TailwindCSS.sln |
| 50 | + |
| 51 | + - name: Build |
| 52 | + run: dotnet build DotnetDevKR.TailwindCSS.sln --configuration Release --no-restore |
| 53 | + |
| 54 | + - name: Pack |
| 55 | + run: | |
| 56 | + dotnet pack ./DotnetDevKR.TailwindCSS/DotnetDevKR.TailwindCSS.csproj --configuration Release \ |
| 57 | + --no-build --no-restore \ |
| 58 | + --output ./artifacts \ |
| 59 | + /p:Version=${{ steps.version.outputs.version }} |
| 60 | +
|
| 61 | + - name: Publish to NuGet.org |
| 62 | + run: | |
| 63 | + dotnet nuget push ./artifacts/*.nupkg \ |
| 64 | + --source https://api.nuget.org/v3/index.json \ |
| 65 | + --api-key ${{ secrets.NUGET_API_KEY }} \ |
| 66 | + --skip-duplicate |
| 67 | + env: |
| 68 | + NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} |
| 69 | + |
| 70 | + - name: Publish to GitHub Packages |
| 71 | + run: | |
| 72 | + dotnet nuget push ./artifacts/*.nupkg \ |
| 73 | + --source https://nuget.pkg.github.com/dotnetdev-kr/index.json \ |
| 74 | + --api-key ${{ secrets.GITHUB_TOKEN }} \ |
| 75 | + --skip-duplicate |
| 76 | + env: |
| 77 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 78 | + |
| 79 | + - name: Create GitHub Release |
| 80 | + uses: softprops/action-gh-release@v1 |
| 81 | + with: |
| 82 | + tag_name: ${{ steps.version.outputs.tag }} |
| 83 | + name: Release ${{ steps.version.outputs.tag }} |
| 84 | + body: | |
| 85 | + ## DotnetDevKR.TailwindCSS ${{ steps.version.outputs.tag }} |
| 86 | +
|
| 87 | + ### Installation |
| 88 | + ```bash |
| 89 | + dotnet add package DotnetDevKR.TailwindCSS --version ${{ steps.version.outputs.version }} |
| 90 | + ``` |
| 91 | +
|
| 92 | + ### Changes |
| 93 | + See [commit history](https://github.com/dotnetdev-kr/DotnetDevKR.TailwindCSS/commits/${{ steps.version.outputs.tag }}) for details. |
| 94 | + files: ./artifacts/*.nupkg |
| 95 | + draft: false |
| 96 | + prerelease: false |
| 97 | + env: |
| 98 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments