@@ -110,22 +110,21 @@ jobs:
110
110
needs : [build, test]
111
111
if : ${{ github.event_name != 'pull_request' }}
112
112
runs-on : ubuntu-latest
113
- # Add permissions if needed for writing to version.txt and creating releases
114
113
permissions :
115
- contents : write # Needed for committing version.txt and creating releases
114
+ contents : write # To commit version.txt
115
+ pull-requests : read # Needed by gh release view potentially? Better safe than sorry.
116
+ # No specific permission needed for reading public repo releases via gh
116
117
117
118
steps :
118
119
- name : Checkout
119
120
uses : actions/checkout@v3
120
121
with :
121
- # Fetch depth 0 to get all history for version comparison if needed,
122
- # though reading version.txt is simpler here.
123
122
fetch-depth : 0
124
123
125
124
- name : Download artifacts
126
125
uses : actions/download-artifact@v4
127
126
with :
128
- path : artifacts # Download all artifacts to ./artifacts/<artifact-name>
127
+ path : artifacts
129
128
130
129
- name : Unzip sharp-x64 to access package.json
131
130
run : |
@@ -134,97 +133,113 @@ jobs:
134
133
- name : Read previous version from version.txt
135
134
id : previous
136
135
run : |
137
- # Handle case where version.txt might not exist yet
138
136
if [[ -f version.txt ]]; then
139
137
echo "sharpver=$(cat version.txt)" >> $GITHUB_ENV
140
138
else
141
- echo "sharpver=0.0.0" >> $GITHUB_ENV # Default if file doesn't exist
139
+ echo "sharpver=0.0.0" >> $GITHUB_ENV
142
140
fi
143
- # Continue even if version.txt doesn't exist on first run
144
141
continue-on-error : true
145
142
146
143
- name : Get new sharp version from downloaded artifact
147
144
id : version
148
145
uses : notiz-dev/github-action-json-property@release
149
146
with :
150
- # Path to the package.json within the unzipped artifact
151
147
path : ' artifacts/sharp-x64/nodejs/node_modules/sharp/package.json'
152
148
prop_path : ' version'
153
149
154
- - name : Check if new version is a pre-release
155
- id : prerelease # Give the step an ID if you wanted to use outputs instead of env
150
+ # --- NEW: Check GitHub Release status using gh CLI ---
151
+ - name : Check GitHub Release status for v${{ steps.version.outputs.prop }}
152
+ id : gh_release_check
153
+ env :
154
+ # Provide the GITHUB_TOKEN to the gh CLI
155
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
156
+ # Extract the version number for easier use
157
+ SHARP_VERSION : ${{ steps.version.outputs.prop }}
156
158
run : |
157
- SHARP_VERSION="${{ steps.version.outputs.prop }}"
158
- if [[ "$SHARP_VERSION" == *-* ]]; then
159
- echo "Detected pre-release version: $SHARP_VERSION"
159
+ # Construct the tag name (usually 'v' + version)
160
+ TAG_NAME="v$SHARP_VERSION"
161
+ echo "Checking GitHub release status for tag: $TAG_NAME"
162
+
163
+ # Use gh release view to get the isPrerelease field.
164
+ # -q filters the JSON output.
165
+ # We redirect stderr to /dev/null to suppress errors if the release/tag doesn't exist.
166
+ # We add || echo "error" to handle the case where the gh command fails (e.g., tag not found)
167
+ IS_PRERELEASE_STATUS=$(gh release view "$TAG_NAME" --repo lovell/sharp --json isPrerelease -q .isPrerelease 2>/dev/null || echo "error")
168
+
169
+ echo "GitHub API check result: $IS_PRERELEASE_STATUS"
170
+
171
+ if [[ "$IS_PRERELEASE_STATUS" == "true" ]]; then
172
+ echo "GitHub marks release $TAG_NAME as pre-release."
160
173
echo "IS_PRERELEASE=true" >> $GITHUB_ENV
174
+ elif [[ "$IS_PRERELEASE_STATUS" == "false" ]]; then
175
+ echo "GitHub marks release $TAG_NAME as stable (not pre-release)."
176
+ echo "IS_PRERELEASE=false" >> $GITHUB_ENV
161
177
else
162
- echo "Detected stable version: $SHARP_VERSION"
178
+ # Handle error or tag not found case - assume stable? Or fail?
179
+ # Assuming stable if tag not found on GitHub releases is safer
180
+ # as the package *was* successfully installed from npm.
181
+ echo "WARN: Could not determine release status for tag $TAG_NAME from GitHub API (may not exist as a release yet or an error occurred). Assuming stable."
163
182
echo "IS_PRERELEASE=false" >> $GITHUB_ENV
183
+ # Alternatively, you could fail the job here if needed:
184
+ # echo "ERROR: Could not determine release status for tag $TAG_NAME from GitHub API."
185
+ # exit 1
164
186
fi
165
187
166
- # --- Optional: Skip logic based on version comparison ---
167
- # This logic prevents re-releasing the *same* version.
168
- # It also only updates version.txt for *stable* releases.
188
+ # --- Skip check logic (no changes needed here) ---
169
189
- name : Check if release should be skipped
170
190
id : skip_check
171
191
run : |
172
192
echo "Previous version: ${{ env.sharpver }}"
173
193
echo "New version: ${{ steps.version.outputs.prop }}"
174
- echo "Is pre-release: ${{ env.IS_PRERELEASE }}"
194
+ echo "Is pre-release (from GitHub) : ${{ env.IS_PRERELEASE }}"
175
195
if [[ "${{ env.sharpver }}" == "${{ steps.version.outputs.prop }}" ]]; then
176
196
echo "Version hasn't changed (${{ steps.version.outputs.prop }}). Skipping release."
197
+ # Use set-output for cross-platform compatibility if needed, but GITHUB_ENV works here
177
198
echo "SKIP_RELEASE=true" >> $GITHUB_ENV
178
199
else
179
200
echo "Version changed or first run. Proceeding with release checks."
180
201
echo "SKIP_RELEASE=false" >> $GITHUB_ENV
181
202
fi
182
203
183
- # --- Update version.txt only for new STABLE releases ---
204
+ # --- Update version.txt logic (no changes needed here) ---
184
205
- name : Update version.txt for new stable release
185
- # Run only if it's NOT a pre-release AND the version has changed
186
206
if : steps.skip_check.outputs.SKIP_RELEASE == 'false' && env.IS_PRERELEASE == 'false'
187
207
run : |
188
208
echo "Updating version.txt to ${{ steps.version.outputs.prop }}"
189
209
echo "${{ steps.version.outputs.prop }}" > version.txt
190
210
191
211
- name : Commit version.txt update
192
- # Run only if version.txt was updated (new stable release)
193
212
if : steps.skip_check.outputs.SKIP_RELEASE == 'false' && env.IS_PRERELEASE == 'false'
194
213
uses : stefanzweifel/git-auto-commit-action@v4
195
214
with :
196
215
commit_message : " Update sharp to ${{ steps.version.outputs.prop }}"
197
216
file_pattern : version.txt
198
- # Add push options if your branch protection requires it
199
- # push_options: '--force'
200
217
201
- # --- Create GitHub Release ---
218
+ # --- Create GitHub Release logic (no changes needed here, uses IS_PRERELEASE env var) ---
202
219
- name : Create GitHub Release
203
- # Run only if the version has actually changed (don't re-release the same version)
204
220
if : steps.skip_check.outputs.SKIP_RELEASE == 'false'
205
221
uses : softprops/action-gh-release@v1
206
222
with :
207
- files : artifacts/**/*.zip # Upload all zip files from the artifacts subdirectories
208
- body : | # Use a multi-line body for better formatting
223
+ files : artifacts/**/*.zip
224
+ body : |
209
225
Sharp version ${{ steps.version.outputs.prop }} Lambda Layer.
226
+ Installed from npm, GitHub release status checked.
210
227
211
228
Architectures included:
212
229
- arm64
213
230
- x64
214
231
- all (combined node_modules for arm64 & x64)
215
- tag_name : v${{ steps.version.outputs.prop }} # Add 'v' prefix to tag, common practice
216
- name : Sharp Layer v${{ steps.version.outputs.prop }} # Release title
217
- # Use the environment variable set in the 'Check if new version is a pre-release' step
232
+ tag_name : v${{ steps.version.outputs.prop }}
233
+ name : Sharp Layer v${{ steps.version.outputs.prop }}
234
+ # Uses the IS_PRERELEASE variable set by the gh_release_check step
218
235
prerelease : ${{ env.IS_PRERELEASE }}
219
236
env :
220
- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} # Explicitly pass the token
237
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
221
238
222
- # --- Notify Discord ---
239
+ # --- Notify Discord logic (no changes needed here) ---
223
240
- name : Notify Discord
224
- # Notify only if a new release was created
225
241
if : steps.skip_check.outputs.SKIP_RELEASE == 'false'
226
242
run : |
227
- # Construct message based on whether it's a pre-release or stable release
228
243
if [[ "${{ env.IS_PRERELEASE }}" == "true" ]]; then
229
244
RELEASE_TYPE="Pre-release"
230
245
else
0 commit comments