@@ -28,32 +28,40 @@ jobs:
28
28
env :
29
29
PKG : ${{ inputs.package }}
30
30
- name : Update package.json
31
+ id : update
31
32
run : node -e "$SCRIPT"
32
33
env :
33
34
PKG : ${{ inputs.package }}
34
35
VERSION : ${{ steps.view.outputs.version }}
35
36
SCRIPT : |
36
- const {PKG, VERSION} = process.env
37
+ const {PKG, VERSION, GITHUB_OUTPUT } = process.env
37
38
if (!PKG) throw new Error("Missing $PKG")
38
39
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")
40
41
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
+ }
43
51
- name : Update package-lock.json
52
+ if : ${{ steps.update.outputs.commit == "y" }}
44
53
run : npm update "$PKG" --lock-file-only
45
54
env :
46
55
PKG : ${{ inputs.package }}
47
56
- name : Commit changes
57
+ if : ${{ steps.update.outputs.commit == "y" }}
48
58
id : commit
49
59
run : |
50
60
set -euo pipefail
51
- echo commit=n > $GITHUB_OUTPUT
52
61
if git add package.json package-lock.json; then
53
62
git config --global user.name "$ACTOR (on behalf of $TRIGGERING_ACTOR)"
54
63
git config --global user.email "$ACTOR@users.noreply.github.com"
55
64
git commit --message "Update $PKG to $VERSION"
56
- echo commit=y > $GITHUB_OUTPUT
57
65
else
58
66
echo '::warning::No changes detected. Skipping push.'
59
67
fi
63
71
ACTOR : ${{ github.actor }}
64
72
TRIGGERING_ACTOR : ${{ github.triggering_actor }}
65
73
- name : Push to branch
74
+ if : ${{ steps.update.outputs.commit == "y" }}
66
75
uses : MithrilJS/push-protected@main
67
76
with :
68
77
token : ${{ secrets.PACKAGE_UPDATE_TOKEN }}
0 commit comments