Skip to content

Commit 740032a

Browse files
committed
ci: add gh actions pipeline
1 parent 26b2cbd commit 740032a

File tree

4 files changed

+320
-0
lines changed

4 files changed

+320
-0
lines changed

.github/workflows/ci.yaml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# This is a Github Workflow that runs tests on any push or pull request.
2+
# If the tests pass and this is a push to the master branch it also runs Semantic Release.
3+
name: CI
4+
on: [push, pull_request]
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
- name: Use Node.js 20.x
11+
uses: actions/setup-node@v4
12+
with:
13+
node-version: 20.x
14+
cache: 'npm'
15+
- run: npm ci
16+
- run: npm run build
17+
- uses: actions/upload-artifact@v4
18+
with:
19+
name: build
20+
path: |
21+
target
22+
package.json
23+
jsr.json
24+
retention-days: 1
25+
26+
push:
27+
name: Push ${{ github.ref }}
28+
needs: build
29+
if: github.event_name == 'push'
30+
runs-on: ubuntu-latest
31+
permissions:
32+
checks: read
33+
statuses: write
34+
contents: write
35+
packages: write
36+
id-token: write
37+
steps:
38+
- name: Checkout
39+
uses: actions/checkout@v4
40+
with:
41+
fetch-depth: ${{ github.ref == 'refs/heads/main' && '0' || '1' }}
42+
- name: Setup Node.js
43+
uses: actions/setup-node@v4
44+
with:
45+
node-version: 20
46+
cache: 'npm'
47+
- uses: actions/download-artifact@v4
48+
with:
49+
name: build
50+
- name: Fetch deps
51+
run: npm ci
52+
- name: Run tests
53+
run: npm run test
54+
55+
# - name: Codeclimate
56+
# if: github.ref == 'refs/heads/main'
57+
# uses: paambaati/codeclimate-action@v4.0.0
58+
# env:
59+
# CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
60+
# with:
61+
# coverageLocations: |
62+
# ${{github.workspace}}/target/coverage/lcov.info:lcov
63+
64+
- name: Semantic Release (npm)
65+
if: github.ref == 'refs/heads/main'
66+
env:
67+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
68+
NPM_PROVENANCE: true
69+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
70+
GIT_BRANCH: 'main'
71+
GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }}
72+
GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }}
73+
GIT_COMMITTER_NAME: ${{ secrets.GIT_COMMITTER_NAME }}
74+
GIT_COMMITTER_EMAIL: ${{ secrets.GIT_COMMITTER_EMAIL }}
75+
run: echo 'disabled' && exit 0 # npx zx-semrel
76+
77+
pr:
78+
if: github.event_name == 'pull_request'
79+
needs: build
80+
name: PR (Node v${{ matrix.node-version }}, OS ${{ matrix.os }})
81+
strategy:
82+
matrix:
83+
os: [ ubuntu-latest, windows-latest ]
84+
node-version: [ 22 ]
85+
86+
runs-on: ${{ matrix.os }}
87+
steps:
88+
- name: Checkout
89+
uses: actions/checkout@v4
90+
- name: Setup Node.js
91+
uses: actions/setup-node@v4
92+
with:
93+
node-version: ${{ matrix.node-version }}
94+
cache: 'npm'
95+
- uses: actions/download-artifact@v4
96+
with:
97+
name: build
98+
- name: Fetch deps
99+
run: npm ci
100+
- name: Run all tests
101+
if: matrix.os == 'ubuntu-latest' && matrix.node-version == 22
102+
run: npm run test
103+
timeout-minutes: 1
104+
105+
- name: Run units
106+
if: matrix.os != 'ubuntu-latest' && matrix.node-version != 22
107+
run: npm run test:unit
108+
timeout-minutes: 1

.github/workflows/codeql.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL Advanced"
13+
14+
on:
15+
push:
16+
branches: [ "main" ]
17+
pull_request:
18+
branches: [ "main" ]
19+
schedule:
20+
- cron: '17 20 * * 0'
21+
22+
jobs:
23+
analyze:
24+
name: Analyze (${{ matrix.language }})
25+
# Runner size impacts CodeQL analysis time. To learn more, please see:
26+
# - https://gh.io/recommended-hardware-resources-for-running-codeql
27+
# - https://gh.io/supported-runners-and-hardware-resources
28+
# - https://gh.io/using-larger-runners (GitHub.com only)
29+
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
30+
runs-on: 'ubuntu-latest'
31+
permissions:
32+
# required for all workflows
33+
security-events: write
34+
35+
# required to fetch internal or private CodeQL packs
36+
packages: read
37+
38+
# only required for workflows in private repositories
39+
actions: read
40+
contents: read
41+
42+
strategy:
43+
fail-fast: false
44+
matrix:
45+
include:
46+
- language: javascript-typescript
47+
build-mode: none
48+
# CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
49+
# Use `c-cpp` to analyze code written in C, C++ or both
50+
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
51+
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
52+
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
53+
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
54+
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
55+
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
56+
steps:
57+
- name: Checkout repository
58+
uses: actions/checkout@v4
59+
60+
# Initializes the CodeQL tools for scanning.
61+
- name: Initialize CodeQL
62+
uses: github/codeql-action/init@v3
63+
with:
64+
languages: ${{ matrix.language }}
65+
build-mode: ${{ matrix.build-mode }}
66+
# If you wish to specify custom queries, you can do so here or in a config file.
67+
# By default, queries listed here will override any specified in a config file.
68+
# Prefix the list here with "+" to use these queries and those in the config file.
69+
70+
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
71+
# queries: security-extended,security-and-quality
72+
73+
# If the analyze step fails for one of the languages you are analyzing with
74+
# "We were unable to automatically build your code", modify the matrix above
75+
# to set the build mode to "manual" for that language. Then modify this step
76+
# to build your code.
77+
# ℹ️ Command-line programs to run using the OS shell.
78+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
79+
- if: matrix.build-mode == 'manual'
80+
shell: bash
81+
run: |
82+
echo 'If you are using a "manual" build mode for one or more of the' \
83+
'languages you are analyzing, replace this with the commands to build' \
84+
'your code, for example:'
85+
echo ' make bootstrap'
86+
echo ' make release'
87+
exit 1
88+
89+
- name: Perform CodeQL Analysis
90+
uses: github/codeql-action/analyze@v3
91+
with:
92+
category: "/language:${{matrix.language}}"
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: npm publish from PR
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
repo:
7+
description: 'source gh repo, like `google/zx`'
8+
required: true
9+
commit:
10+
description: 'commit id'
11+
required: true
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Use Node.js 22
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: 22
21+
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
with:
25+
repository: ${{ github.event.inputs.repo }}
26+
ref: ${{ github.event.inputs.commit }}
27+
28+
- name: Build
29+
run: |
30+
npm ci
31+
npm run build
32+
33+
- uses: actions/upload-artifact@v4
34+
with:
35+
name: build-pr-${{ github.run_id }}
36+
path: |
37+
target
38+
package.json
39+
README.md
40+
jsr.json
41+
retention-days: 1
42+
43+
publish:
44+
needs: build
45+
runs-on: ubuntu-latest
46+
permissions:
47+
checks: read
48+
statuses: write
49+
contents: write
50+
packages: write
51+
id-token: write
52+
steps:
53+
- uses: actions/setup-node@v4
54+
with:
55+
node-version: 22
56+
- uses: actions/download-artifact@v4
57+
with:
58+
name: build-pr-${{ github.run_id }}
59+
60+
- run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> .npmrc
61+
env:
62+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
63+
64+
- name: Notice
65+
if: github.event.inputs.repo != github.repository
66+
run: node -e "const fs = require('fs'); fs.writeFileSync('./README.md', process.env.NOTICE + fs.readFileSync('./README.md'))"
67+
env:
68+
NOTICE: "> ⚠<fe0f> **This snapshot was built from the external source** \n> repo: ${{ github.event.inputs.repo }} \n> commit: ${{ github.event.inputs.commit }}\n"
69+
70+
- run: |
71+
npm version $(node --eval="process.stdout.write(require('./package.json').version)")-pr.${{ github.run_id }} --no-git-tag-version
72+
npm publish --provenance --access=public --no-git-tag-version --tag pr

.github/workflows/osv-scanner.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
# A sample workflow which sets up periodic OSV-Scanner scanning for vulnerabilities,
7+
# in addition to a PR check which fails if new vulnerabilities are introduced.
8+
#
9+
# For more examples and options, including how to ignore specific vulnerabilities,
10+
# see https://google.github.io/osv-scanner/github-action/
11+
12+
name: OSV-Scanner
13+
14+
on:
15+
pull_request:
16+
branches: [ "main" ]
17+
merge_group:
18+
branches: [ "main" ]
19+
schedule:
20+
- cron: '29 14 * * 1'
21+
push:
22+
branches: [ "main" ]
23+
24+
permissions:
25+
# Require writing security events to upload SARIF file to security tab
26+
security-events: write
27+
# Read commit contents
28+
contents: read
29+
30+
jobs:
31+
scan-scheduled:
32+
if: ${{ github.event_name == 'push' || github.event_name == 'schedule' }}
33+
uses: "google/osv-scanner-action/.github/workflows/osv-scanner-reusable.yml@1f1242919d8a60496dd1874b24b62b2370ed4c78" # v1.7.1
34+
with:
35+
# Example of specifying custom arguments
36+
scan-args: |-
37+
-r
38+
--skip-git
39+
./
40+
scan-pr:
41+
if: ${{ github.event_name == 'pull_request' || github.event_name == 'merge_group' }}
42+
uses: "google/osv-scanner-action/.github/workflows/osv-scanner-reusable-pr.yml@1f1242919d8a60496dd1874b24b62b2370ed4c78" # v1.7.1
43+
with:
44+
# Example of specifying custom arguments
45+
scan-args: |-
46+
-r
47+
--skip-git
48+
./

0 commit comments

Comments
 (0)