Skip to content

Update package.json #48

Update package.json

Update package.json #48

Workflow file for this run

name: Add Changes Based on Logic
on:
push:
branches: [ 'test-action-commit' ]
paths:
- 'micro-ui/web/micro-ui-internals/**'
jobs:
auto_increment_version:
runs-on: ubuntu-latest
env:
SOURCE_JSON_FILE: "micro-ui/web/micro-ui-internals/example/package.json"
DESTIN_JSON_FILE: "micro-ui/web/package.json"
TARGET_BRANCH: "test-action"
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Fetch and merge changes from the remote repository
run: |
git fetch origin
git config pull.ff only # fast-forward only
git config merge.--no-ff only
git pull origin "$TARGET_BRANCH"
- name: Install jq
run: sudo apt-get install jq
- name: Debug Information
run: |
git branch -a
git show
git show "$GITHUB_SHA"
- name: Check Dependency Change
id: check_change
run: |
dependency="@egovernments/digit-ui-module-workbench"
# Check if the dependency is present in the package.json file
if jq --arg dep "$dependency" '.devDependencies | has($dep)' "$SOURCE_JSON_FILE" >/dev/null; then
# Get the current version
current_version=$(jq -r --arg dep "$dependency" '.devDependencies[$dep]' "$SOURCE_JSON_FILE")
echo "CURRENT_VERSION=$current_version"
# Get the version from the specified branch for the specific file
branch_version=$(git show "$TARGET_BRANCH":"$DESTIN_JSON_FILE" | jq -r --arg dep "$dependency" '.dependencies[$dep]')
echo "branch_version=$branch_version"
# Check if the versions are different
if [[ "$current_version" != "$branch_version" ]]; then
echo "Dependency version incremented"
echo "VERSION_CHANGED=true" >> $GITHUB_ENV
# Increment the version manually
new_version=$(echo "$current_version" )
# Commit the updated package.json
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
git config pull.ff only # fast-forward only
git checkout -b "$TARGET_BRANCH"
# Update the package.json file with the new version
jq --arg dep "$dependency" --arg new_version "$new_version" '.dependencies[$dep] = $new_version' "$DESTIN_JSON_FILE" > "$DESTIN_JSON_FILE.tmp" && mv "$DESTIN_JSON_FILE.tmp" "$DESTIN_JSON_FILE"
git add "$DESTIN_JSON_FILE"
git commit -m "Auto increment $dependency version to $new_version"
git push origin "$TARGET_BRANCH"
else
echo "Dependency version not incremented"
echo "VERSION_CHANGED=false" >> $GITHUB_ENV
fi
echo "CURRENT_VERSION=$current_version" >> $GITHUB_ENV
else
echo "Dependency not found in $SOURCE_JSON_FILE"
echo "VERSION_CHANGED=false" >> $GITHUB_ENV
fi