Skip to content

Commit

Permalink
feat: run reusable ci workflow on post dependabot
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Feb 16, 2023
1 parent 2d98a04 commit b3cd790
Show file tree
Hide file tree
Showing 31 changed files with 678 additions and 334 deletions.
2 changes: 1 addition & 1 deletion .github/actions/audit/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: Audit
inputs:
shell:
description: shell to run on
default: bash
default: 'bash'

runs:
using: composite
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/create-check/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ inputs:
required: true
job-status:
description: Status of the check being created
default: in_progress
default: 'in_progress'

outputs:
check-id:
Expand Down
5 changes: 3 additions & 2 deletions .github/actions/deps/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ name: Dependencies
inputs:
command:
description: command to run for the dependencies step
default: install --ignore-scripts --no-audit --no-fund
default: 'install --ignore-scripts --no-audit --no-fund'
flags:
description: extra flags to pass to the dependencies step
default: ''
shell:
description: shell to run on
default: bash
default: 'bash'

runs:
using: composite
Expand Down
3 changes: 2 additions & 1 deletion .github/actions/lint/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ name: Lint
inputs:
flags:
description: flags to pass to the commands
default: ''
shell:
description: shell to run on
default: bash
default: 'bash'

runs:
using: composite
Expand Down
10 changes: 5 additions & 5 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ description: Setup a repo with standard tools
inputs:
node-version:
description: node version to use
default: 18.x
default: '18.x'
npm-version:
description: npm version to use
default: latest
default: 'latest'
cache:
description: whether to cache npm install or not
default: false
default: 'false'
shell:
description: shell to run on
default: bash
default: 'bash'
deps:
description: whether to run the deps step
default: 'true'
deps-command:
description: command to run for the dependencies step
default: install --ignore-scripts --no-audit --no-fund
default: 'install --ignore-scripts --no-audit --no-fund'
deps-flags:
description: extra flags to pass to the dependencies step

Expand Down
3 changes: 2 additions & 1 deletion .github/actions/test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ name: Test
inputs:
flags:
description: flags to pass to the commands
default: ''
shell:
description: shell to run on
default: bash
default: 'bash'

runs:
using: composite
Expand Down
6 changes: 4 additions & 2 deletions .github/actions/upsert-comment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ inputs:
required: true
login:
description: Login name of user to look for comments from
default: github-actions[bot]
default: 'github-actions[bot]'
required: true
body:
description: Body of the comment, the first line will be used to match to an existing comment
required: true
find:
description: string to find in body
replace:
Expand Down Expand Up @@ -54,8 +56,8 @@ runs:
const comments = await github.paginate(github.rest.issues.listComments, { owner, repo, issue_number })
.then(comments => comments.map(c => ({ id: c.id, login: c.user.login, body: c.body })))
console.log(`Found comments: ${JSON.stringify(comments, null, 2)}`)
console.log(`Looking for comment with: ${JSON.stringify({ LOGIN, TITLE, INCLUDES }, null, 2)}`)
console.log(`Found comments: ${JSON.stringify(comments, null, 2)}`)
const comment = comments.find(c =>
c.login === LOGIN &&
Expand Down
26 changes: 8 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,22 @@ name: CI
on:
workflow_dispatch:
inputs:
ref:
required: true
type: string
check-sha:
type: string
all:
default: true
type: boolean
workflow_call:
inputs:
ref:
required: true
type: string
force:
type: boolean
check-sha:
required: true
type: string
all:
default: true
type: boolean
pull_request:
branches:
- main
- latest
push:
branches:
- main
Expand All @@ -36,7 +32,7 @@ on:
jobs:
lint:
name: Lint
if: github.repository_owner == 'npm'
if: github.repository_owner == 'npm' && !(github.event_name == 'pull_request' && startsWith(github.head_ref, 'dependabot/') && contains(github.head_ref, '/npm-cli/template-oss') && !inputs.force)
runs-on: ubuntu-latest
defaults:
run:
Expand All @@ -58,20 +54,17 @@ jobs:

- name: Setup
id: setup
continue-on-error: ${{ !!steps.check.outputs.check-id }}
uses: ./.github/actions/setup

- name: Get Changed Workspaces
id: workspaces
continue-on-error: ${{ !!steps.check.outputs.check-id }}
uses: ./.github/actions/changed-workspaces
with:
token: ${{ secrets.GITHUB_TOKEN }}
files: ${{ (inputs.all && '--all') || '' }}

- name: Lint
uses: ./.github/actions/lint
continue-on-error: ${{ !!steps.check.outputs.check-id }}
with:
flags: ${{ steps.workspaces.outputs.flags }}

Expand All @@ -85,7 +78,7 @@ jobs:

test:
name: Test - ${{ matrix.platform.name }} - ${{ matrix.node-version }}
if: github.repository_owner == 'npm'
if: github.repository_owner == 'npm' && !(github.event_name == 'pull_request' && startsWith(github.head_ref, 'dependabot/') && contains(github.head_ref, '/npm-cli/template-oss') && !inputs.force)
runs-on: ${{ matrix.platform.os }}
defaults:
run:
Expand Down Expand Up @@ -116,7 +109,7 @@ jobs:
shell: bash
run: |
if [[ "${{ matrix.node-version }}" == "14.17.0" || "${{ inputs.all }}" == "true" ]]; then
echo "result=true" >> $GITHUB_OUTPUT
echo "result=true" >> $GITHUB_OUTPUT
fi
- name: Checkout
Expand All @@ -138,15 +131,13 @@ jobs:
if: steps.continue-matrix.outputs.result
uses: ./.github/actions/setup
id: setup
continue-on-error: ${{ !!steps.check.outputs.check-id }}
with:
node-version: ${{ matrix.node-version }}
shell: ${{ matrix.platform.shell }}

- name: Get Changed Workspaces
if: steps.continue-matrix.outputs.result
id: workspaces
continue-on-error: ${{ !!steps.check.outputs.check-id }}
uses: ./.github/actions/changed-workspaces
with:
token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -155,7 +146,6 @@ jobs:
- name: Test
if: steps.continue-matrix.outputs.result
uses: ./.github/actions/test
continue-on-error: ${{ !!steps.check.outputs.check-id }}
with:
flags: ${{ steps.workspaces.outputs.flags }}
shell: ${{ matrix.platform.shell }}
Expand Down
31 changes: 30 additions & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
name: CodeQL

on:
workflow_dispatch:
workflow_call:
inputs:
ref:
type: string
force:
type: boolean
check-sha:
type: string
push:
branches:
- main
Expand All @@ -18,7 +27,7 @@ on:
jobs:
analyze:
name: Analyze
if: github.repository_owner == 'npm'
if: github.repository_owner == 'npm' && !(github.event_name == 'pull_request' && startsWith(github.head_ref, 'dependabot/') && contains(github.head_ref, '/npm-cli/template-oss') && !inputs.force)
runs-on: ubuntu-latest
defaults:
run:
Expand All @@ -27,9 +36,21 @@ jobs:
actions: read
contents: read
security-events: write
checks: write
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ inputs.ref }}

- name: Create Check
uses: ./.github/actions/create-check
if: inputs.check-sha
id: check
with:
sha: ${{ inputs.check-sha }}
token: ${{ secrets.GITHUB_TOKEN }}
job-name: Analyze

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
Expand All @@ -38,3 +59,11 @@ jobs:

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2

- name: Conclude Check
uses: ./.github/actions/conclude-check
if: steps.check.outputs.check-id && (success() || failure())
with:
token: ${{ secrets.GITHUB_TOKEN }}
conclusion: ${{ job.status }}
check-id: ${{ steps.check.outputs.check-id }}

0 comments on commit b3cd790

Please sign in to comment.