Skip to content

Package update

Package update #10

name: Package update
on:
workflow_dispatch:
inputs:
package:
description: The package to check for updates for
type: choice
required: true
options:
- mithril
permissions:
contents: write
pull-requests: write
jobs:
update:
name: Update ${{ inputs.package }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Get current package version
id: view
run: echo "version=$(npm view "$PKG"@latest version)" | tee $GITHUB_OUTPUT
env:
PKG: ${{ inputs.package }}
- name: Update package.json
run: node -e "$SCRIPT"
env:
PKG: ${{ inputs.package }}
VERSION: ${{ steps.view.outputs.version }}
SCRIPT: |
const {PKG, VERSION} = process.env
if (!PKG) throw new Error("Missing $PKG")
if (!VERSION) throw new Error("Missing $VERSION")
const pkg = JSON.parse(fs.readFileSync("package.json"))
console.log(`old version=${pkg.dependencies[PKG]}`)
pkg.dependencies[PKG] = VERSION
fs.writeFileSync("package.json", JSON.stringify(pkg, null, 2)+"\n")
- name: Update package-lock.json
run: npm update "$PKG" --lock-file-only
env:
PKG: ${{ inputs.package }}
- name: Commit and push changes
run: |
set -euo pipefail
if git add package.json package-lock.json; then
git config --global user.name "$ACTOR (on behalf of $TRIGGERING_ACTOR)"
git config --global user.email "$ACTOR@users.noreply.github.com"
git commit --message "Update $PKG to $VERSION"
gh pr create --fill --label automated
else
echo '::warning::No changes detected. Skipping push.'
fi
env:
PKG: ${{ inputs.package }}
VERSION: ${{ steps.view.outputs.version }}
ACTOR: ${{ github.actor }}
TRIGGERING_ACTOR: ${{ github.triggering_actor }}
GH_TOKEN: ${{ github.token }}