Skip to content

Update Packages

Update Packages #1939

name: Update Packages
on:
schedule:
- cron: '0 */6 * * *'
workflow_dispatch: {}
permissions:
contents: write
jobs:
update-packages:
name: Update Packages
runs-on: ubuntu-latest
steps:
- name: Node
uses: actions/setup-node@v4
with:
node-version: 'latest'
- name: Checkout
uses: actions/checkout@v4
- name: Update
id: update
env:
GITHUB_TOKEN: ${{ secrets.UPDATE_PACKAGE }}
run: |
npm i
declare -i STATUS=0
UPDATES=()
PACKAGES=$(jq -r '.dependencies | to_entries[] | "\(.key)@\(.value)"' package.json)
for package in ${PACKAGES}; do
packageName="${package%@*}"
v1="${package##*@}"
v1="${v1##*^}"
v2="$(npm view "${packageName}" version)"
if [ "${v1}" != "${v2}" ]; then
npm i -s --no-package-lock "${packageName}"
LABEL="${packageName} (${v1} -> ${v2})"
echo "${LABEL}"
echo "${LABEL}" >> $GITHUB_STEP_SUMMARY
UPDATES+=("${LABEL}")
STATUS+=1
fi
done
if [ ${STATUS} -eq 0 ]; then
echo "Packages are up to date" >> $GITHUB_STEP_SUMMARY
fi
echo "updated=${STATUS}" >> $GITHUB_OUTPUT
- name: Configure
id: configure
if: steps.update.outputs.updated > 0
run: |
sudo apt-get update && sudo apt-get install -y gnupg
git config --global user.name "Mikl Wolfe"
git config --global user.email "wolfemikl@gmail.com"
- name: GPG
id: gpg
if: steps.configure.outcome == 'success'
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPG_KEY_ID }}
passphrase: ${{ secrets.GPG_PASS }}
git_user_signingkey: true
git_commit_gpgsign: true
- name: Push
if: steps.gpg.outcome == 'success'
env:
GITHUB_TOKEN: ${{ secrets.UPDATE_PACKAGE }}
run: |
DATE=$(date +%Y-%m-%d)
MESSAGE="chore(deps#${{ github.run_number }}): bump (${{ steps.update.outputs.updated }})"
BODY=$(printf "%s\n" "${UPDATES}")
git checkout -b "${DATE}"
git add package.json
git commit -S -am "${MESSAGE}" --gpg-sign
git push -f origin "${DATE}"
gh pr create -l dependencies -t "${MESSAGE}" -b "${BODY}"