|
| 1 | +name: Update dependencies |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 8 * * 1' # At 08:00 on Monday. https://crontab.guru/#0_8_*_*_1 |
| 6 | + |
| 7 | +jobs: |
| 8 | + build: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + steps: |
| 11 | + - uses: actions/checkout@v2 |
| 12 | + with: |
| 13 | + ref: 'master' |
| 14 | + - uses: actions/setup-node@v1 |
| 15 | + with: |
| 16 | + node-version: '10.x' |
| 17 | + - name: Update dependencies |
| 18 | + run: npx npm-check-updates -u |
| 19 | + - name: Install dependencies |
| 20 | + run: npm install |
| 21 | + - name: Raise pull request |
| 22 | + uses: actions/github-script@0.4.0 |
| 23 | + with: |
| 24 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 25 | + script: | |
| 26 | + const { readFileSync } = require('fs'); |
| 27 | + const { resolve } = require('path'); |
| 28 | +
|
| 29 | + const baseBranch = 'master'; |
| 30 | + const branch = `update-dependencies-${new Date().toISOString().replace(/[T:]/g,'-').split('.')[0]}`; |
| 31 | +
|
| 32 | + const baseBranchRef = await github.git.getRef({ |
| 33 | + ...context.repo, |
| 34 | + ref: `heads/${baseBranch}` |
| 35 | + }); |
| 36 | + const parentSha = baseBranchRef.data.object.sha; |
| 37 | +
|
| 38 | + const tree = await github.git.createTree({ |
| 39 | + ...context.repo, |
| 40 | + base_tree: parentSha, |
| 41 | + tree: ['package.json', 'package-lock.json'].map(path => ({ |
| 42 | + path, |
| 43 | + mode: '100644', |
| 44 | + content: readFileSync(resolve(process.cwd(), path), 'utf8') |
| 45 | + })) |
| 46 | + }); |
| 47 | +
|
| 48 | + const commit = await github.git.createCommit({ |
| 49 | + ...context.repo, |
| 50 | + message: 'Update dependencies', |
| 51 | + tree: tree.data.sha, |
| 52 | + parents: [parentSha] |
| 53 | + }); |
| 54 | +
|
| 55 | + await github.git.createRef({ |
| 56 | + ...context.repo, |
| 57 | + ref: `refs/heads/${branch}`, |
| 58 | + sha: commit.data.sha |
| 59 | + }); |
| 60 | +
|
| 61 | + await github.pulls.create({ |
| 62 | + ...context.repo, |
| 63 | + title: branch.replace(/-/g,' '), |
| 64 | + head: branch, |
| 65 | + base: baseBranch |
| 66 | + }); |
0 commit comments