Skip to content

Commit b7cef81

Browse files
committed
ci: Updated workflows
1 parent 99625e8 commit b7cef81

File tree

11 files changed

+365
-1
lines changed

11 files changed

+365
-1
lines changed

.github/workflows/pr.yml

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
name: PR
2+
3+
# Run on all pull requests
4+
on: [ pull_request ]
5+
6+
env:
7+
NX_BRANCH: ${{ github.event.number }}
8+
NX_RUN_GROUP: ${{ github.run_id }}
9+
10+
jobs:
11+
12+
prepare-env:
13+
runs-on: ubuntu-latest
14+
outputs:
15+
GITHUB_HEAD_REF: ${{ steps.GITHUB_HEAD_REF.outputs.value }}
16+
GITHUB_BASE_REF: ${{ steps.GITHUB_BASE_REF.outputs.value }}
17+
steps:
18+
- uses: nrwl/last-successful-commit-action@v1
19+
id: last_successful_commit
20+
with:
21+
branch: 'master'
22+
workflow_id: 'release.yml'
23+
github_token: ${{ secrets.GITHUB_TOKEN }}
24+
25+
- id: GITHUB_HEAD_REF
26+
run: echo "::set-output name=value::$(echo ${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}})"
27+
28+
- id: GITHUB_BASE_REF
29+
run: echo "::set-output name=value::$(echo ${{ steps.last_successful_commit.outputs.commit_hash }}})"
30+
31+
build:
32+
needs: [ prepare-env ]
33+
runs-on: ubuntu-latest
34+
strategy:
35+
matrix:
36+
node-version: [ 14.x ]
37+
steps:
38+
- uses: actions/checkout@v2
39+
with:
40+
fetch-depth: 0
41+
42+
- name: Cache node modules
43+
id: cache
44+
uses: actions/cache@v2
45+
with:
46+
path: |
47+
**/node_modules
48+
key: ${{ env.DEPENDENCIES_CACHE }}-${{ hashFiles('yarn.lock') }}
49+
50+
- name: Cache Nx
51+
uses: actions/cache@v2
52+
with:
53+
path: node_modules/.cache/nx
54+
key: ${{ env.NX_CACHE }}-${{ hashFiles('yarn.lock') }}-${{ matrix.target }}-${{ matrix.index }}-${{ github.sha }}
55+
restore-keys: |
56+
${{ env.NX_CACHE }}-${{ hashFiles('yarn.lock') }}-${{ matrix.target }}-${{ matrix.index }}-
57+
${{ env.NX_CACHE }}-${{ hashFiles('yarn.lock') }}-
58+
${{ env.NX_CACHE }}-
59+
60+
- name: Use Node.js ${{ matrix.node-version }}
61+
uses: actions/setup-node@v2
62+
with:
63+
node-version: ${{ matrix.node-version }}
64+
65+
- name: yarn install
66+
if: steps.cache.outputs.cache-hit != 'true'
67+
run: yarn install
68+
69+
- name: GIT config
70+
run: |
71+
git config user.name "${GITHUB_ACTOR}"
72+
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
73+
74+
- name: nx affected:version
75+
run: node ./tools/scripts/run-many.js version origin/${{ needs.prepare-env.outputs.GITHUB_HEAD_REF }} ${{ needs.prepare-env.outputs.GITHUB_BASE_REF }}
76+
77+
- name: nx affected:build
78+
run: node ./tools/scripts/run-many.js build origin/${{ needs.prepare-env.outputs.GITHUB_HEAD_REF }} ${{ needs.prepare-env.outputs.GITHUB_BASE_REF }}
79+
80+
unit-test:
81+
needs: [ prepare-env ]
82+
runs-on: ubuntu-latest
83+
strategy:
84+
matrix:
85+
node-version: [ 14.x ]
86+
steps:
87+
- uses: actions/checkout@v2
88+
with:
89+
fetch-depth: 0
90+
91+
- name: Cache node modules
92+
id: cache
93+
uses: actions/cache@v2
94+
with:
95+
path: |
96+
**/node_modules
97+
key: ${{ env.DEPENDENCIES_CACHE }}-${{ hashFiles('yarn.lock') }}
98+
99+
- name: Cache Nx
100+
uses: actions/cache@v2
101+
with:
102+
path: node_modules/.cache/nx
103+
key: ${{ env.NX_CACHE }}-${{ hashFiles('yarn.lock') }}-${{ matrix.target }}-${{ matrix.index }}-${{ github.sha }}
104+
restore-keys: |
105+
${{ env.NX_CACHE }}-${{ hashFiles('yarn.lock') }}-${{ matrix.target }}-${{ matrix.index }}-
106+
${{ env.NX_CACHE }}-${{ hashFiles('yarn.lock') }}-
107+
${{ env.NX_CACHE }}-
108+
109+
- name: Use Node.js ${{ matrix.node-version }}
110+
uses: actions/setup-node@v2
111+
with:
112+
node-version: ${{ matrix.node-version }}
113+
114+
- name: yarn install
115+
if: steps.cache.outputs.cache-hit != 'true'
116+
run: yarn install
117+
118+
- name: nx affected:test
119+
run: node ./tools/scripts/run-many.js test origin/${{ needs.prepare-env.outputs.GITHUB_HEAD_REF }} ${{ needs.prepare-env.outputs.GITHUB_BASE_REF }}
120+
121+
e2e-test:
122+
needs: [ prepare-env ]
123+
runs-on: ubuntu-latest
124+
strategy:
125+
matrix:
126+
node-version: [ 14.x ]
127+
db-type: ['postgres', 'mysql']
128+
steps:
129+
- uses: actions/checkout@v2
130+
with:
131+
fetch-depth: 0
132+
133+
- name: Cache node modules
134+
id: cache
135+
uses: actions/cache@v2
136+
with:
137+
path: |
138+
**/node_modules
139+
key: ${{ env.DEPENDENCIES_CACHE }}-${{ hashFiles('yarn.lock') }}
140+
141+
- name: Cache Nx
142+
uses: actions/cache@v2
143+
with:
144+
path: node_modules/.cache/nx
145+
key: ${{ env.NX_CACHE }}-${{ hashFiles('yarn.lock') }}-${{ matrix.target }}-${{ matrix.index }}-${{ github.sha }}
146+
restore-keys: |
147+
${{ env.NX_CACHE }}-${{ hashFiles('yarn.lock') }}-${{ matrix.target }}-${{ matrix.index }}-
148+
${{ env.NX_CACHE }}-${{ hashFiles('yarn.lock') }}-
149+
${{ env.NX_CACHE }}-
150+
151+
- name: Use Node.js ${{ matrix.node-version }}
152+
uses: actions/setup-node@v2
153+
with:
154+
node-version: ${{ matrix.node-version }}
155+
156+
- name: yarn install
157+
if: steps.cache.outputs.cache-hit != 'true'
158+
run: yarn install
159+
160+
- name: nx affected:e2e
161+
run: node ./tools/scripts/run-many.js e2e origin/${{ needs.prepare-env.outputs.GITHUB_HEAD_REF }} ${{ needs.prepare-env.outputs.GITHUB_BASE_REF }}
162+
env:
163+
NESTJS_QUERY_DB_TYPE: ${{ matrix.db-type }}

.github/workflows/release.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
env:
9+
NX_BRANCH: ${{ github.event.number }}
10+
NX_RUN_GROUP: ${{ github.run_id }}
11+
12+
jobs:
13+
14+
prepare-env:
15+
runs-on: ubuntu-latest
16+
outputs:
17+
GITHUB_HEAD_REF: ${{ steps.script.outputs.headRef }}
18+
GITHUB_BASE_REF: ${{ steps.script.outputs.tagHash }}
19+
steps:
20+
- uses: actions/checkout@v2
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Cache node modules
25+
id: cache
26+
uses: actions/cache@v2
27+
with:
28+
path: |
29+
**/node_modules
30+
key: ${{ env.DEPENDENCIES_CACHE }}-${{ hashFiles('yarn.lock') }}
31+
32+
- name: yarn install
33+
if: steps.cache.outputs.cache-hit != 'true'
34+
run: yarn install --pure-lockfile --prefer-offline
35+
36+
- name: Set correct env vars
37+
id: script
38+
uses: ./tools/actions/set-master-vars

examples/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
]
1414
}
1515
},
16-
"test": {
16+
"e2e": {
1717
"executor": "@nrwl/jest:jest",
1818
"outputs": [
1919
"coverage/examples"

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"typeorm-seeding": "1.6.1"
4949
},
5050
"devDependencies": {
51+
"@actions/core": "^1.8.0",
5152
"@apollo/gateway": "0.42.0",
5253
"@commitlint/cli": "15.0.0",
5354
"@commitlint/config-angular": "15.0.0",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name: 'Log changed projects'
2+
description: 'Logs all changed projects'
3+
author: 'Tycho Bokdam'
4+
runs:
5+
using: 'node12'
6+
main: 'src/index.js'
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const core = require('@actions/core')
2+
const { execSync } = require('child_process')
3+
4+
const { GITHUB_HEAD_REF } = process.env
5+
6+
const latestTag = execSync(`git describe --tags $(git rev-list --tags --max-count=1)`)
7+
.toString('utf8')
8+
.trim()
9+
10+
const tagSha = execSync(`git rev-list -n 1 ${latestTag}`)
11+
.toString('utf8')
12+
.trim()
13+
14+
core.info(`"${latestTag}" is the latest tag with "${tagSha}" sha`)
15+
core.info(`"${GITHUB_HEAD_REF}" is the current head`)
16+
17+
core.info(`Fetching changed projects between https://github.com/tripss/nestjs-query/compare/${latestTag}...${GITHUB_HEAD_REF}`)
18+
19+
const affected = execSync(`npx nx print-affected --target=version --head=origin/${GITHUB_HEAD_REF} --base=${tagSha}`)
20+
.toString('utf8')
21+
.trim()
22+
23+
const affectedProjects = JSON.parse(affected)
24+
.tasks.map((task) => task.target.project)
25+
.sort()
26+
27+
execSync(`npx nx run-many --target=version --projects=${affectedProjects.join(',')} --baseBranch="${latestTag}" --dryRun`, { stdio: 'inherit' })
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: 'Set the correct master variables'
2+
description: 'Sets the correct master environment variables'
3+
author: 'Tycho Bokdam'
4+
runs:
5+
using: 'node12'
6+
main: 'src/index.js'
7+
8+
outputs:
9+
tag:
10+
description: 'The latest tag'
11+
tagHash:
12+
description: 'The hash of the latest tag'
13+
headRef:
14+
description: 'The correct head ref to use'
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const core = require('@actions/core')
2+
const { execSync } = require('child_process')
3+
4+
const { GITHUB_REF } = process.env
5+
6+
core.info('Fetching latest tag...')
7+
const latestTag = execSync(`git describe --tags $(git rev-list --tags --max-count=1)`)
8+
.toString('utf8')
9+
.trim()
10+
11+
const tagSha = execSync(`git rev-list -n 1 ${latestTag}`)
12+
.toString('utf8')
13+
.trim()
14+
15+
const headRef = GITHUB_REF.replace('refs/heads/', '')
16+
17+
core.info(`"${latestTag}" is the latest tag with "${tagSha}" sha`)
18+
core.info(`"${headRef}" is the head ref`)
19+
20+
core.setOutput('tag', latestTag)
21+
core.setOutput('tagHash', tagSha)
22+
core.setOutput('headRef', headRef)

tools/scripts/run-many.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
const { logger } = require('@nrwl/devkit')
2+
const { execSync } = require('child_process')
3+
const core = require('@actions/core')
4+
5+
const target = process.argv[2]
6+
const headRef = process.argv[5]
7+
const baseRef = process.argv[6]
8+
9+
const nxArgs = headRef !== baseRef && baseRef !== 'empty'
10+
? `--head=${headRef} --base=${baseRef}`
11+
: '--all'
12+
13+
const buildAffectedCommand = [
14+
'npx nx print-affected',
15+
`--target=${target !== 'publish' ? target : 'version'}`,
16+
nxArgs
17+
]
18+
19+
const affectedCommand = buildAffectedCommand.join(' ')
20+
21+
logger.info(`Running: ${affectedCommand}`)
22+
23+
const affected = execSync(affectedCommand)
24+
.toString('utf-8')
25+
26+
const affectedProjects = JSON.parse(affected)
27+
.tasks.map((task) => task.target.project)
28+
.slice()
29+
.sort()
30+
31+
if (affectedProjects.length > 0) {
32+
if (target === 'publish') {
33+
while (affectedProjects.length > 0) {
34+
const project = affectedProjects.shift()
35+
36+
// Try to Publish the package
37+
try {
38+
execSync(`npm publish ./dist/packages/${project} --access public`, { stdio: 'inherit' })
39+
40+
} catch (err) {
41+
core.warning(`Error publishing ${project}`, err)
42+
}
43+
}
44+
45+
} else {
46+
const execCommand = [
47+
'npx nx run-many',
48+
`--target=${target}`,
49+
`--projects=${affectedProjects.join(',')}`,
50+
]
51+
52+
if (target === 'version') {
53+
execCommand.push('--baseBranch="master"')
54+
execCommand.push('--changelogHeader=" "')
55+
}
56+
57+
const command = execCommand.join(' ')
58+
59+
logger.info(`Running: ${command}`)
60+
61+
execSync(command, { stdio: 'inherit' })
62+
}
63+
}

tools/tsconfig.tools.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "../tsconfig.base.json",
3+
"compilerOptions": {
4+
"outDir": "../dist/out-tsc/tools",
5+
"rootDir": ".",
6+
"module": "commonjs",
7+
"target": "es5",
8+
"types": ["node"]
9+
},
10+
"include": ["**/*.ts"]
11+
}

0 commit comments

Comments
 (0)