Package update #13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| 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 changes | |
| id: commit | |
| run: | | |
| set -euo pipefail | |
| echo commit=n > $GITHUB_OUTPUT | |
| 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" | |
| echo commit=y > $GITHUB_OUTPUT | |
| 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 }} | |
| - name: Push to branch | |
| uses: MithrilJS/push-protected@main | |
| with: | |
| token: ${{ secrets.PACKAGE_UPDATE_TOKEN }} |