-
Notifications
You must be signed in to change notification settings - Fork 0
132 lines (111 loc) · 3.82 KB
/
Copy pathci.yml
File metadata and controls
132 lines (111 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
name: CI
on:
pull_request:
# Needed for nx-set-shas when run on the main branch
permissions:
actions: read
contents: read
pull-requests: write # for comments
env:
VERSIONS: ''
jobs:
ci:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install pnpm
uses: pnpm/action-setup@v3
with:
version: 8.15.8
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
- name: Restore cached npm dependencies
uses: actions/cache/restore@v3
with:
path: |
node_modules
~/.cache/Cypress # needed for the Cypress binary
key: npm-dependencies-${{ hashFiles('pnpm-lock.yaml') }}
- name: Install dependencies
run: pnpm install
- name: Cache npm dependencies
uses: actions/cache/save@v3
with:
path: |
node_modules
~/.cache/Cypress # needed for the Cypress binary
key: npm-dependencies-${{ hashFiles('pnpm-lock.yaml') }}
# This line enables distribution
# The "--stop-agents-after" is optional, but allows idle agents to shut down once the "e2e-ci" targets have been requested
# - run: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="e2e-ci"
- name: Setup SHAs
uses: nrwl/nx-set-shas@v4
# This line is needed for nx affected to work when CI is running on a PR
- run: git branch --track main origin/main
if: ${{ github.event_name == 'pull_request' }}
- name: Nx report
run: pnpm exec nx report
- name: Nx format
run: pnpm exec nx format:check
- name: Lint
run: pnpm exec nx affected -t lint
- name: Test
run: pnpm exec nx affected -t test
- name: Build
run: pnpm exec nx affected -t build
- name: E2E
run: pnpm exec nx affected -t e2e-ci
- name: Determinate versions
id: versions
if: github.event_name == 'pull_request'
run: |
{
echo 'VERSIONS<<EOF'
pnpm exec nx release --dry-run --skip-publish
echo EOF
} >> "$GITHUB_ENV"
- name: 'Report changes to Pull request'
uses: actions/github-script@v6
if: github.event_name == 'pull_request'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// 1. Retrieve existing bot comments for the PR
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
})
const botComment = comments.find(comment => {
return comment.user.type === 'Bot' && comment.body.includes('Versions')
})
// 2. Prepare format of the comment
const output = `#### Versions 📖
\`\`\`\n
${{ env.VERSIONS }}
\`\`\`
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Workflow: \`${{ github.workflow }}\`*`;
// 3. If we have a comment, update it, otherwise create a new one
if (botComment) {
github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: output
})
} else {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
}