-
Notifications
You must be signed in to change notification settings - Fork 0
43 lines (38 loc) · 1.76 KB
/
update_package_json_version.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
name: Update Package Version
on:
workflow_call:
inputs:
version:
required: true
type: string
secrets:
token:
required: true
env:
CARGO_TERM_COLOR: always
jobs:
update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.token }}
- name: Update package.json version
run: |
package_json=$(cat package.json)
# Update the version and optional dependencies
new_version="${{ inputs.version }}"
updated_package_json=$(echo "$package_json" | jq --arg new_version "$new_version" '.version = $new_version | .optionalDependencies."@govcraft/paseto_cli-linux-x64" = $new_version | .optionalDependencies."@govcraft/paseto_cli-darwin-x64" = $new_version | .optionalDependencies."@govcraft/paseto_cli-darwin-aarch64" = $new_version | .optionalDependencies."@govcraft/paseto_cli-win32-x64" = $new_version | .scripts.postinstall = "cross-env BINARY_DISTRIBUTION_VERSION=\($new_version) node ./install.js"')
# Save the updated package.json content
echo "$updated_package_json" > package.json
# Check if changes were made and commit them
if ! git diff --quiet; then
echo "Version updated to $new_version and optional dependencies updated" >> $GITHUB_STEP_SUMMARY
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git commit -a -m "chore: workflow update package.json version to $new_version"
git push
else
echo "Package.json version is already $new_version, no update needed" >> $GITHUB_STEP_SUMMARY
fi
shell: bash