-
Notifications
You must be signed in to change notification settings - Fork 0
214 lines (184 loc) · 9.61 KB
/
tailwindcss-auto-update.yaml
File metadata and controls
214 lines (184 loc) · 9.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
name: Auto Update TailwindCSS and Publish NuGet
on:
schedule:
# Run every day at 00:00 UTC
- cron: '0 0 * * *'
workflow_dispatch:
jobs:
check-update:
runs-on: ubuntu-latest
outputs:
update_needed: ${{ steps.check_update.outputs.update_needed }}
tailwindcss_version: ${{ steps.get_tailwind_version.outputs.tailwindcss_version }}
tailwindcss_version_clean: ${{ steps.get_tailwind_version.outputs.tailwindcss_version_clean }}
current_tailwind_version: ${{ steps.get_nuget_version.outputs.current_tailwind_version }}
current_revision: ${{ steps.get_nuget_version.outputs.current_revision }}
lib_version: ${{ steps.get_nuget_version.outputs.lib_version }}
new_lib_version: ${{ steps.check_update.outputs.new_lib_version }}
new_version: ${{ steps.check_update.outputs.new_version }}
steps:
- name: Get latest TailwindCSS version
id: get_tailwind_version
run: |
set -e
LATEST_TAILWIND_VERSION=$(curl -s https://api.github.com/repos/tailwindlabs/tailwindcss/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$LATEST_TAILWIND_VERSION" ]; then
echo "Error: Failed to fetch latest TailwindCSS version from GitHub API." >&2
exit 1
fi
echo "Latest TailwindCSS version: $LATEST_TAILWIND_VERSION"
echo "tailwindcss_version=$LATEST_TAILWIND_VERSION" >> $GITHUB_OUTPUT
echo "tailwindcss_version_clean=${LATEST_TAILWIND_VERSION//v/}" >> $GITHUB_OUTPUT
- name: Get current version from NuGet
id: get_nuget_version
run: |
set -e
PACKAGE_NAME="DotnetDevKR.TailwindCSS"
# Fetch all versions from NuGet API
NUGET_RESPONSE=$(curl -s "https://api.nuget.org/v3-flatcontainer/${PACKAGE_NAME,,}/index.json")
if echo "$NUGET_RESPONSE" | grep -q '"versions"'; then
# Get the latest version from NuGet (supports both 3-part and 4-part versions)
# Version format: {TailwindMajor}.{TailwindMinor}.{TailwindPatch}.{Revision}
LIB_VERSION=$(echo "$NUGET_RESPONSE" | grep -oP '"\d+\.\d+\.\d+(\.\d+)?' | tail -1 | tr -d '"')
if [ -z "$LIB_VERSION" ]; then
echo "No version found in NuGet. Using default."
LIB_VERSION="0.0.0.0"
CURRENT_TAILWIND_VERSION="0.0.0"
CURRENT_REVISION="1"
else
echo "Latest NuGet library version: $LIB_VERSION"
# Parse version: could be 3-part (old) or 4-part (new format)
IFS='.' read -ra VERSION_PARTS <<< "$LIB_VERSION"
if [ ${#VERSION_PARTS[@]} -eq 4 ]; then
# New format: TailwindMajor.TailwindMinor.TailwindPatch.Revision
CURRENT_TAILWIND_VERSION="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.${VERSION_PARTS[2]}"
CURRENT_REVISION="${VERSION_PARTS[3]}"
else
# Old format: need to fetch from nuspec
NUSPEC_URL="https://api.nuget.org/v3-flatcontainer/${PACKAGE_NAME,,}/${LIB_VERSION}/${PACKAGE_NAME,,}.nuspec"
echo "Fetching nuspec from: $NUSPEC_URL"
NUSPEC_RESPONSE=$(curl -s "$NUSPEC_URL")
CURRENT_TAILWIND_VERSION=$(echo "$NUSPEC_RESPONSE" | grep -oP 'TailwindCSS[^0-9]*v?\K\d+\.\d+\.\d+' | head -1)
if [ -z "$CURRENT_TAILWIND_VERSION" ]; then
FULL_VERSION=$(echo "$NUSPEC_RESPONSE" | grep -oP '<version>\K[^<]+')
if echo "$FULL_VERSION" | grep -q '+v'; then
CURRENT_TAILWIND_VERSION=$(echo "$FULL_VERSION" | cut -d'+' -f2 | sed 's/v//')
else
CURRENT_TAILWIND_VERSION="0.0.0"
fi
fi
CURRENT_REVISION="1"
fi
fi
echo "lib_version=$LIB_VERSION" >> $GITHUB_OUTPUT
echo "Current TailwindCSS version: $CURRENT_TAILWIND_VERSION"
echo "Current revision: $CURRENT_REVISION"
echo "current_tailwind_version=$CURRENT_TAILWIND_VERSION" >> $GITHUB_OUTPUT
echo "current_revision=$CURRENT_REVISION" >> $GITHUB_OUTPUT
else
echo "Package not found on NuGet. This might be the first publish."
echo "lib_version=0.0.0.0" >> $GITHUB_OUTPUT
echo "current_tailwind_version=0.0.0" >> $GITHUB_OUTPUT
echo "current_revision=1" >> $GITHUB_OUTPUT
fi
- name: Check if update is needed
id: check_update
run: |
CURRENT_TAILWIND_VERSION="${{ steps.get_nuget_version.outputs.current_tailwind_version }}"
TAILWINDCSS_VERSION_CLEAN="${{ steps.get_tailwind_version.outputs.tailwindcss_version_clean }}"
CURRENT_REVISION="${{ steps.get_nuget_version.outputs.current_revision }}"
if [ "$CURRENT_TAILWIND_VERSION" != "$TAILWINDCSS_VERSION_CLEAN" ]; then
echo "Update needed: $CURRENT_TAILWIND_VERSION -> $TAILWINDCSS_VERSION_CLEAN"
echo "update_needed=true" >> $GITHUB_OUTPUT
# New TailwindCSS version, reset revision to 1
# Version format: {TailwindMajor}.{TailwindMinor}.{TailwindPatch}.{Revision}
NEW_REVISION="1"
NEW_LIB_VERSION="$TAILWINDCSS_VERSION_CLEAN.$NEW_REVISION"
echo "New library version: $NEW_LIB_VERSION"
echo "new_lib_version=$NEW_LIB_VERSION" >> $GITHUB_OUTPUT
echo "new_version=$NEW_LIB_VERSION" >> $GITHUB_OUTPUT
else
echo "No update needed. Current version is already up to date."
echo "update_needed=false" >> $GITHUB_OUTPUT
fi
build-and-publish:
needs: check-update
if: needs.check-update.outputs.update_needed == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: "9.x"
- name: Update version in csproj
run: |
sed -i "s|<Version>.*</Version>|<Version>${{ needs.check-update.outputs.new_version }}</Version>|" ./DotnetDevKR.TailwindCSS/DotnetDevKR.TailwindCSS.csproj
echo "Updated csproj to version: ${{ needs.check-update.outputs.new_version }}"
- name: Update version in install.sh
run: |
sed -i "s|VERSION=\${1:-\"v[^\"]*\"}|VERSION=\${1:-\"${{ needs.check-update.outputs.tailwindcss_version }}\"}|" ./DotnetDevKR.TailwindCSS/runtime/install.sh
echo "Updated install.sh to TailwindCSS version: ${{ needs.check-update.outputs.tailwindcss_version }}"
- name: Download TailwindCSS executables
run: |
chmod +x ./DotnetDevKR.TailwindCSS/runtime/install.sh
./DotnetDevKR.TailwindCSS/runtime/install.sh ${{ needs.check-update.outputs.tailwindcss_version }}
- name: Restore dependencies
run: dotnet restore DotnetDevKR.TailwindCSS.sln
- name: Build
run: dotnet build DotnetDevKR.TailwindCSS.sln --configuration Release --no-restore
- name: Pack
run: |
dotnet pack ./DotnetDevKR.TailwindCSS/DotnetDevKR.TailwindCSS.csproj --configuration Release \
--no-build --no-restore \
--output ./artifacts \
/p:Version=${{ needs.check-update.outputs.new_version }}
# - name: Commit and push changes
# run: |
# git config user.name "github-actions[bot]"
# git config user.email "github-actions[bot]@users.noreply.github.com"
# git add -A
# git commit -m "chore: Update TailwindCSS to ${{ needs.check-update.outputs.tailwindcss_version }} and bump version to ${{ needs.check-update.outputs.new_version }}"
# git tag "v${{ needs.check-update.outputs.new_lib_version }}"
# git push origin ${{ github.ref_name }}
# git push origin "v${{ needs.check-update.outputs.new_lib_version }}"
- name: Publish to NuGet.org
run: |
dotnet nuget push ./artifacts/*.nupkg \
--source https://api.nuget.org/v3/index.json \
--api-key ${{ secrets.NUGET_API_KEY }} \
--skip-duplicate
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
- name: Publish to GitHub Packages
run: |
dotnet nuget push ./artifacts/*.nupkg \
--source https://nuget.pkg.github.com/dotnetdev-kr/index.json \
--api-key ${{ secrets.GITHUB_TOKEN }} \
--skip-duplicate
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ needs.check-update.outputs.new_lib_version }}
name: Release v${{ needs.check-update.outputs.new_lib_version }}
body: |
## Updates
- Updated TailwindCSS from v${{ needs.check-update.outputs.current_tailwind_version }} to ${{ needs.check-update.outputs.tailwindcss_version }}
- Package version: ${{ needs.check-update.outputs.new_version }}
## Installation
```bash
dotnet add package DotnetDevKR.TailwindCSS --version ${{ needs.check-update.outputs.new_version }}
```
files: ./artifacts/*.nupkg
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}