@@ -110,66 +110,128 @@ 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
114+ permissions :
115+ contents : write # Needed for committing version.txt and creating releases
116+
113117 steps :
114118 - name : Checkout
115119 uses : actions/checkout@v3
120+ with :
121+ # Fetch depth 0 to get all history for version comparison if needed,
122+ # though reading version.txt is simpler here.
123+ fetch-depth : 0
116124
117125 - name : Download artifacts
118126 uses : actions/download-artifact@v4
119127 with :
120- path : artifacts
128+ path : artifacts # Download all artifacts to ./artifacts/<artifact-name>
121129
122- - name : Unzip sharp-x64
130+ - name : Unzip sharp-x64 to access package.json
123131 run : |
124132 unzip artifacts/sharp-x64/release-x64.zip -d artifacts/sharp-x64
125133
126- - name : Read previous version
134+ - name : Read previous version from version.txt
127135 id : previous
128- run : echo "sharpver=$(cat version.txt)" >> $GITHUB_ENV
136+ run : |
137+ # Handle case where version.txt might not exist yet
138+ if [[ -f version.txt ]]; then
139+ echo "sharpver=$(cat version.txt)" >> $GITHUB_ENV
140+ else
141+ echo "sharpver=0.0.0" >> $GITHUB_ENV # Default if file doesn't exist
142+ fi
143+ # Continue even if version.txt doesn't exist on first run
144+ continue-on-error : true
129145
130- - name : Get new version
146+ - name : Get new sharp version from downloaded artifact
131147 id : version
132148 uses : notiz-dev/github-action-json-property@release
133149 with :
150+ # Path to the package.json within the unzipped artifact
134151 path : ' artifacts/sharp-x64/nodejs/node_modules/sharp/package.json'
135152 prop_path : ' version'
136153
137- - name : Check if version is pre-release
138- id : prerelease
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
139156 run : |
140- if [[ "${{ steps.version.outputs.prop }}" == *-* ]]; then
141- echo "is_prerelease=true" >> $GITHUB_ENV
157+ SHARP_VERSION="${{ steps.version.outputs.prop }}"
158+ if [[ "$SHARP_VERSION" == *-* ]]; then
159+ echo "Detected pre-release version: $SHARP_VERSION"
160+ echo "IS_PRERELEASE=true" >> $GITHUB_ENV
142161 else
143- echo "is_prerelease=false" >> $GITHUB_ENV
162+ echo "Detected stable version: $SHARP_VERSION"
163+ echo "IS_PRERELEASE=false" >> $GITHUB_ENV
144164 fi
145-
146- - name : Skip if no stable version change
147- if : env.is_prerelease == 'false' && env.sharpver == steps.version.outputs.prop
148- run : echo "🧠 No Sharp stable update detected. Skipping release."
149-
150- - name : Update version.txt
151- if : env.is_prerelease == 'false' && env.sharpver != steps.version.outputs.prop
152- run : echo "${{ steps.version.outputs.prop }}" > version.txt
153-
154- - name : Commit version.txt
165+
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.
169+ - name : Check if release should be skipped
170+ id : skip_check
171+ run : |
172+ echo "Previous version: ${{ env.sharpver }}"
173+ echo "New version: ${{ steps.version.outputs.prop }}"
174+ echo "Is pre-release: ${{ env.IS_PRERELEASE }}"
175+ if [[ "${{ env.sharpver }}" == "${{ steps.version.outputs.prop }}" ]]; then
176+ echo "Version hasn't changed (${{ steps.version.outputs.prop }}). Skipping release."
177+ echo "SKIP_RELEASE=true" >> $GITHUB_ENV
178+ else
179+ echo "Version changed or first run. Proceeding with release checks."
180+ echo "SKIP_RELEASE=false" >> $GITHUB_ENV
181+ fi
182+
183+ # --- Update version.txt only for new STABLE releases ---
184+ - name : Update version.txt for new stable release
185+ # Run only if it's NOT a pre-release AND the version has changed
186+ if : steps.skip_check.outputs.SKIP_RELEASE == 'false' && env.IS_PRERELEASE == 'false'
187+ run : |
188+ echo "Updating version.txt to ${{ steps.version.outputs.prop }}"
189+ echo "${{ steps.version.outputs.prop }}" > version.txt
190+
191+ - name : Commit version.txt update
192+ # Run only if version.txt was updated (new stable release)
193+ if : steps.skip_check.outputs.SKIP_RELEASE == 'false' && env.IS_PRERELEASE == 'false'
155194 uses : stefanzweifel/git-auto-commit-action@v4
156- if : env.is_prerelease == 'false' && env.sharpver != steps.version.outputs.prop
157195 with :
158196 commit_message : " Update sharp to ${{ steps.version.outputs.prop }}"
159197 file_pattern : version.txt
198+ # Add push options if your branch protection requires it
199+ # push_options: '--force'
160200
201+ # --- Create GitHub Release ---
161202 - name : Create GitHub Release
203+ # Run only if the version has actually changed (don't re-release the same version)
204+ if : steps.skip_check.outputs.SKIP_RELEASE == 'false'
162205 uses : softprops/action-gh-release@v1
163- if : ${{ env.sharpver != steps.version.outputs.prop }}
164206 with :
165- files : artifacts/**/*.zip
166- body : Sharp version ${{ steps.version.outputs.prop }}
167- tag_name : ${{ steps.version.outputs.prop }}
168- prerelease : ${{ env.is_prerelease }}
169-
207+ files : artifacts/**/*.zip # Upload all zip files from the artifacts subdirectories
208+ body : | # Use a multi-line body for better formatting
209+ Sharp version ${{ steps.version.outputs.prop }} Lambda Layer.
210+
211+ Architectures included:
212+ - arm64
213+ - x64
214+ - 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
218+ prerelease : ${{ env.IS_PRERELEASE }}
219+ env :
220+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} # Explicitly pass the token
221+
222+ # --- Notify Discord ---
170223 - name : Notify Discord
171- if : ${{ env.sharpver != steps.version.outputs.prop }}
224+ # Notify only if a new release was created
225+ if : steps.skip_check.outputs.SKIP_RELEASE == 'false'
172226 run : |
227+ # Construct message based on whether it's a pre-release or stable release
228+ if [[ "${{ env.IS_PRERELEASE }}" == "true" ]]; then
229+ RELEASE_TYPE="Pre-release"
230+ else
231+ RELEASE_TYPE="Stable release"
232+ fi
233+ MESSAGE_CONTENT="🧠 Sharp Lambda Layer updated!\\n${RELEASE_TYPE}: \`${{ steps.version.outputs.prop }}\`\\n<https://github.com/${{ github.repository }}/releases/tag/v${{ steps.version.outputs.prop }}>"
234+
173235 curl -X POST -H "Content-Type: application/json" \
174- -d "{\"content\":\"🧠 Sharp Lambda Layer updated!\nVersion: \`${{ steps.version.outputs.prop }}\`\n<https://github.com/${{ github.repository }}/releases/tag/${{ steps.version.outputs.prop }}> \"}" \
175- "${{ secrets.DISCORD_WEBHOOK_URL }}"
236+ -d "{\"content\":\"${MESSAGE_CONTENT} \"}" \
237+ "${{ secrets.DISCORD_WEBHOOK_URL }}"
0 commit comments