Skip to content

Commit

Permalink
fix(ci): Ensure that automated tests are run against pull requests
Browse files Browse the repository at this point in the history
  • Loading branch information
vinsonchuong committed Apr 10, 2023
1 parent 7f75ef3 commit 654a6e3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/bin/create-npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
main,
test,
ciAction,
prAction,
dependabotAction,
dependabot,
} from '../templates/index.js'
Expand Down Expand Up @@ -60,6 +61,7 @@ await writeTemplate(projectDirectory, npmignore({}))
await writeTemplate(projectDirectory, main({}))
await writeTemplate(projectDirectory, test({}))
await writeTemplate(projectDirectory, ciAction({branchName}))
await writeTemplate(projectDirectory, prAction())
await writeTemplate(projectDirectory, dependabotAction({}))
await writeTemplate(projectDirectory, dependabot({}))

Expand Down
8 changes: 5 additions & 3 deletions src/templates/ci-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ export default function ({branchName}) {
path: '.github/workflows/ci.yml',
content: `
name: CI
on: [push, pull_request]
on:
push:
branches:
- ${branchName}
jobs:
ci:
runs-on: ubuntu-latest
Expand All @@ -15,8 +18,7 @@ export default function ({branchName}) {
cache: yarn
- run: yarn
- run: yarn test
- if: github.ref == 'refs/heads/${branchName}'
run: yarn release
- run: yarn release
env:
GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: \${{ secrets.NPM_TOKEN }}
Expand Down
13 changes: 11 additions & 2 deletions src/templates/dependabot-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,19 @@ export default function () {
on: pull_request_target
jobs:
dependabot:
if: \${{ github.event.pull_request.user.login == 'dependabot[bot]' }}
runs-on: ubuntu-latest
steps:
- if: \${{ github.event.pull_request.user.login == 'dependabot[bot]' }}
run: gh pr merge --auto --rebase \${{ github.event.pull_request.html_url }}
- uses: actions/checkout@v3
with:
ref: \${{ github.event.pull_request.head.sha }}
- uses: actions/setup-node@v3
with:
node-version: latest
cache: yarn
- run: yarn
- run: yarn test
- run: gh pr merge --auto --rebase \${{ github.event.pull_request.html_url }}
env:
GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
`,
Expand Down
1 change: 1 addition & 0 deletions src/templates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export {default as packagejson} from './packagejson.js'
export {default as readme} from './readme.js'
export {default as test} from './test.js'
export {default as ciAction} from './ci-action.js'
export {default as prAction} from './pr-action.js'
export {default as dependabotAction} from './dependabot-action.js'
export {default as dependabot} from './dependabot.js'
21 changes: 21 additions & 0 deletions src/templates/pr-action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export default function () {
return {
path: '.github/workflows/pr.yml',
content: `
name: PR
on: pull_request
jobs:
pr:
if: \${{ github.event.pull_request.user.login != 'dependabot[bot]' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: latest
cache: yarn
- run: yarn
- run: yarn test
`,
}
}

0 comments on commit 654a6e3

Please sign in to comment.