Skip to content

Commit 1a5ce06

Browse files
authored
Update package-update.yml
1 parent 9b8e1ba commit 1a5ce06

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

.github/workflows/package-update.yml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,40 @@ jobs:
2828
env:
2929
PKG: ${{ inputs.package }}
3030
- name: Update package.json
31+
id: update
3132
run: node -e "$SCRIPT"
3233
env:
3334
PKG: ${{ inputs.package }}
3435
VERSION: ${{ steps.view.outputs.version }}
3536
SCRIPT: |
36-
const {PKG, VERSION} = process.env
37+
const {PKG, VERSION, GITHUB_OUTPUT} = process.env
3738
if (!PKG) throw new Error("Missing $PKG")
3839
if (!VERSION) throw new Error("Missing $VERSION")
39-
const pkg = JSON.parse(fs.readFileSync("package.json"))
40+
const pkg = JSON.parse(fs.readFileSync("package.json")
4041
console.log(`old version=${pkg.dependencies[PKG]}`)
41-
pkg.dependencies[PKG] = VERSION
42-
fs.writeFileSync("package.json", JSON.stringify(pkg, null, 2)+"\n")
42+
if (pkg.dependencies[PKG] === VERSION) {
43+
fs.writeFileSync(GITHUB_OUTPUT, "commit=n")
44+
console.log("Package version not changed. Skipping push.")
45+
} else {
46+
pkg.dependencies[PKG] = VERSION
47+
fs.writeFileSync("package.json", JSON.stringify(pkg, null, 2)+"\n")
48+
fs.writeFileSync(GITHUB_OUTPUT, "commit=y")
49+
console.log("Package version updated.")
50+
}
4351
- name: Update package-lock.json
52+
if: ${{ steps.update.outputs.commit == "y" }}
4453
run: npm update "$PKG" --lock-file-only
4554
env:
4655
PKG: ${{ inputs.package }}
4756
- name: Commit changes
57+
if: ${{ steps.update.outputs.commit == "y" }}
4858
id: commit
4959
run: |
5060
set -euo pipefail
51-
echo commit=n > $GITHUB_OUTPUT
5261
if git add package.json package-lock.json; then
5362
git config --global user.name "$ACTOR (on behalf of $TRIGGERING_ACTOR)"
5463
git config --global user.email "$ACTOR@users.noreply.github.com"
5564
git commit --message "Update $PKG to $VERSION"
56-
echo commit=y > $GITHUB_OUTPUT
5765
else
5866
echo '::warning::No changes detected. Skipping push.'
5967
fi
@@ -63,6 +71,7 @@ jobs:
6371
ACTOR: ${{ github.actor }}
6472
TRIGGERING_ACTOR: ${{ github.triggering_actor }}
6573
- name: Push to branch
74+
if: ${{ steps.update.outputs.commit == "y" }}
6675
uses: MithrilJS/push-protected@main
6776
with:
6877
token: ${{ secrets.PACKAGE_UPDATE_TOKEN }}

0 commit comments

Comments
 (0)