|
| 1 | +on: |
| 2 | + workflow_dispatch: |
| 3 | + inputs: |
| 4 | + package: |
| 5 | + description: The package to check for updates for |
| 6 | + type: choice |
| 7 | + required: true |
| 8 | + options: |
| 9 | + - mithril |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + |
| 14 | +jobs: |
| 15 | + update: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + - uses: actions/setup-node@v4 |
| 20 | + with: |
| 21 | + node-version: 20 |
| 22 | + - name: Get current package version |
| 23 | + id: view |
| 24 | + run: echo "version=$(npm view "$PKG"@latest version)" | tee $GITHUB_OUTPUT |
| 25 | + env: |
| 26 | + PKG: ${{ inputs.package }} |
| 27 | + - name: Update package.json |
| 28 | + run: > |
| 29 | + set -euo pipefail |
| 30 | + updated="(jq --indent 2 \ |
| 31 | + --arg pkg "$PKG" --arg version "$VERSION" \ |
| 32 | + '.dependencies[$pkg] = $version' \ |
| 33 | + < package.json)" |
| 34 | + printf '%s' "$updated" > package.json |
| 35 | + env: |
| 36 | + PKG: ${{ inputs.package }} |
| 37 | + VERSION: ${{ steps.view.version }} |
| 38 | + - name: Update package-lock.json |
| 39 | + run: npm update "$PKG" --lock-file-only |
| 40 | + env: |
| 41 | + PKG: ${{ inputs.package }} |
| 42 | + - name: Commit and push changes |
| 43 | + run: > |
| 44 | + set -euo pipefail |
| 45 | + if git diff-index --quiet --cached HEAD; then |
| 46 | + echo '::warning::No changes detected. Skipping push.' |
| 47 | + else |
| 48 | + git config --global user.name "$ACTOR (on behalf of $TRIGGERING_ACTOR)" |
| 49 | + git config --global user.email "$ACTOR@users.noreply.github.com" |
| 50 | + git commit --all --message "Update $PKG to $VERSION" |
| 51 | + git push |
| 52 | + fi |
| 53 | + env: |
| 54 | + PKG: ${{ inputs.package }} |
| 55 | + VERSION: ${{ steps.view.version }} |
| 56 | + ACTOR: ${{ github.actor }} |
| 57 | + TRIGGERING_ACTOR: ${{ github.triggering_actor }} |
0 commit comments