Skip to content

Commit

Permalink
Save the PR number during build and use it for the approval action if…
Browse files Browse the repository at this point in the history
… dependabot is making a PR
  • Loading branch information
nblagoev committed Mar 17, 2021
1 parent 5d6fe88 commit 4d80caf
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 87 deletions.
38 changes: 25 additions & 13 deletions .github/workflows/build-pr.yml
Expand Up @@ -10,16 +10,28 @@ jobs:
matrix:
node-version: [12.x, 14.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: install and build
run: |
yarn install --frozen-lockfile
yarn run coverage
yarn run build
env:
CI: true
- run: ./node_modules/.bin/codecov -f coverage/*.json
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: install and build
run: |
yarn install --frozen-lockfile
yarn run coverage
yarn run build
env:
CI: true
- run: ./node_modules/.bin/codecov -f coverage/*.json
save-pr:
runs-on: ubuntu-latest
steps:
- name: Save PR number
run: |
mkdir -p ./pr
echo ${{ github.event.number }} > ./pr/number
- uses: actions/upload-artifact@v2
with:
name: pr
path: pr/
26 changes: 13 additions & 13 deletions .github/workflows/build.yml
Expand Up @@ -12,16 +12,16 @@ jobs:
matrix:
node-version: [12.x, 14.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: install and build
run: |
yarn install --frozen-lockfile
yarn run coverage
yarn run build
env:
CI: true
- run: ./node_modules/.bin/codecov -f coverage/*.json
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: install and build
run: |
yarn install --frozen-lockfile
yarn run coverage
yarn run build
env:
CI: true
- run: ./node_modules/.bin/codecov -f coverage/*.json
70 changes: 39 additions & 31 deletions .github/workflows/dependabot-pr.yml
@@ -1,7 +1,7 @@
name: dependabot-pr
on:
workflow_run:
workflows: ["build-pr", "lint-pr"]
workflows: ["build-pr"]
types:
- completed
jobs:
Expand All @@ -13,41 +13,49 @@ jobs:
github.event.workflow_run.conclusion == 'success' &&
github.actor == 'dependabot[bot]' }}
steps:
- name: Approve
uses: actions/github-script@v2
- name: 'Download artifact'
uses: actions/github-script@v3
with:
script: |
var artifacts = await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
var matchArtifact = artifacts.data.artifacts.filter(artifact => artifact.name == "pr")[0];
var download = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data));
- run: unzip pr.zip

- name: Approve and Merge PR
uses: actions/github-script@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { pull_request: pr, repository: repo } = context.payload
var fs = require('fs');
var pr_number = Number(fs.readFileSync('./number'));
core.debug(`Creating APPROVE review for pull request #${pr.number}`)
core.debug(`Creating APPROVE review for pull request #${pr_number}`)
await github.pulls.createReview({
owner: repo.owner.login,
repo: repo.name,
pull_number: pr.number,
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr_number,
event: "APPROVE"
})
core.debug(`Approved pull request #${pr.number}`)
# Handled by GitHub's auto-merge feature
#
# automerge:
# name: Merge pull request
# runs-on: ubuntu-latest
# needs: autoapprove
# if: github.base_ref == 'master' && github.actor == 'dependabot[bot]'
# steps:
# - name: Merge
# uses: actions/github-script@v2
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
# script: |
# const { pull_request: pr, repository: repo } = context.payload
core.debug(`Approved pull request #${pr_number}`)
# core.debug(`Merging pull request #${pr.number}`)
# await github.pulls.merge({
# owner: repo.owner.login,
# repo: repo.name,
# pull_number: pr.number
# })
# core.debug(`Merged pull request #${pr.number}`)
core.debug(`Merging pull request #${pr_number}`)
await github.pulls.merge({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr_number,
})
core.debug(`Merged pull request #${pr_number}`)
24 changes: 12 additions & 12 deletions .github/workflows/draft-release.yml
Expand Up @@ -60,20 +60,20 @@ jobs:
matrix:
node-version: [12.x, 14.x]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: install and build
run: |
yarn install --frozen-lockfile
yarn run coverage
yarn run build
env:
CI: true
- name: install and build
run: |
yarn install --frozen-lockfile
yarn run coverage
yarn run build
env:
CI: true

release:
name: Create release
Expand Down
36 changes: 18 additions & 18 deletions .github/workflows/publish.yml
Expand Up @@ -7,26 +7,26 @@ jobs:
name: Publish to NPM
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '12.x'
registry-url: 'https://registry.npmjs.org'
- run: yarn install --frozen-lockfile
- run: yarn publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '12.x'
registry-url: 'https://registry.npmjs.org'
- run: yarn install --frozen-lockfile
- run: yarn publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

publish-ghp:
name: Publish to GitHub Packages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '12.x'
registry-url: 'https://npm.pkg.github.com'
- run: yarn install --frozen-lockfile
- run: yarn publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '12.x'
registry-url: 'https://npm.pkg.github.com'
- run: yarn install --frozen-lockfile
- run: yarn publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 4d80caf

Please sign in to comment.