@@ -110,22 +110,21 @@ jobs:
110110 needs : [build, test]
111111 if : ${{ github.event_name != 'pull_request' }}
112112 runs-on : ubuntu-latest
113- # Add permissions if needed for writing to version.txt and creating releases
114113 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
116117
117118 steps :
118119 - name : Checkout
119120 uses : actions/checkout@v3
120121 with :
121- # Fetch depth 0 to get all history for version comparison if needed,
122- # though reading version.txt is simpler here.
123122 fetch-depth : 0
124123
125124 - name : Download artifacts
126125 uses : actions/download-artifact@v4
127126 with :
128- path : artifacts # Download all artifacts to ./artifacts/<artifact-name>
127+ path : artifacts
129128
130129 - name : Unzip sharp-x64 to access package.json
131130 run : |
@@ -134,97 +133,113 @@ jobs:
134133 - name : Read previous version from version.txt
135134 id : previous
136135 run : |
137- # Handle case where version.txt might not exist yet
138136 if [[ -f version.txt ]]; then
139137 echo "sharpver=$(cat version.txt)" >> $GITHUB_ENV
140138 else
141- echo "sharpver=0.0.0" >> $GITHUB_ENV # Default if file doesn't exist
139+ echo "sharpver=0.0.0" >> $GITHUB_ENV
142140 fi
143- # Continue even if version.txt doesn't exist on first run
144141 continue-on-error : true
145142
146143 - name : Get new sharp version from downloaded artifact
147144 id : version
148145 uses : notiz-dev/github-action-json-property@release
149146 with :
150- # Path to the package.json within the unzipped artifact
151147 path : ' artifacts/sharp-x64/nodejs/node_modules/sharp/package.json'
152148 prop_path : ' version'
153149
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 }}
156158 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."
160173 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
161177 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."
163182 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
164186 fi
165187
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) ---
169189 - name : Check if release should be skipped
170190 id : skip_check
171191 run : |
172192 echo "Previous version: ${{ env.sharpver }}"
173193 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 }}"
175195 if [[ "${{ env.sharpver }}" == "${{ steps.version.outputs.prop }}" ]]; then
176196 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
177198 echo "SKIP_RELEASE=true" >> $GITHUB_ENV
178199 else
179200 echo "Version changed or first run. Proceeding with release checks."
180201 echo "SKIP_RELEASE=false" >> $GITHUB_ENV
181202 fi
182203
183- # --- Update version.txt only for new STABLE releases ---
204+ # --- Update version.txt logic (no changes needed here) ---
184205 - name : Update version.txt for new stable release
185- # Run only if it's NOT a pre-release AND the version has changed
186206 if : steps.skip_check.outputs.SKIP_RELEASE == 'false' && env.IS_PRERELEASE == 'false'
187207 run : |
188208 echo "Updating version.txt to ${{ steps.version.outputs.prop }}"
189209 echo "${{ steps.version.outputs.prop }}" > version.txt
190210
191211 - name : Commit version.txt update
192- # Run only if version.txt was updated (new stable release)
193212 if : steps.skip_check.outputs.SKIP_RELEASE == 'false' && env.IS_PRERELEASE == 'false'
194213 uses : stefanzweifel/git-auto-commit-action@v4
195214 with :
196215 commit_message : " Update sharp to ${{ steps.version.outputs.prop }}"
197216 file_pattern : version.txt
198- # Add push options if your branch protection requires it
199- # push_options: '--force'
200217
201- # --- Create GitHub Release ---
218+ # --- Create GitHub Release logic (no changes needed here, uses IS_PRERELEASE env var) ---
202219 - name : Create GitHub Release
203- # Run only if the version has actually changed (don't re-release the same version)
204220 if : steps.skip_check.outputs.SKIP_RELEASE == 'false'
205221 uses : softprops/action-gh-release@v1
206222 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 : |
209225 Sharp version ${{ steps.version.outputs.prop }} Lambda Layer.
226+ Installed from npm, GitHub release status checked.
210227
211228 Architectures included:
212229 - arm64
213230 - x64
214231 - 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
218235 prerelease : ${{ env.IS_PRERELEASE }}
219236 env :
220- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} # Explicitly pass the token
237+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
221238
222- # --- Notify Discord ---
239+ # --- Notify Discord logic (no changes needed here) ---
223240 - name : Notify Discord
224- # Notify only if a new release was created
225241 if : steps.skip_check.outputs.SKIP_RELEASE == 'false'
226242 run : |
227- # Construct message based on whether it's a pre-release or stable release
228243 if [[ "${{ env.IS_PRERELEASE }}" == "true" ]]; then
229244 RELEASE_TYPE="Pre-release"
230245 else
0 commit comments