Skip to content

Commit 1ef8b26

Browse files
committed
ci: refactor pipelines and add attw step
1 parent 6b5ea47 commit 1ef8b26

14 files changed

+258
-353
lines changed

.editorconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 2
7+
insert_final_newline = true
8+
trim_trailing_whitespace = true

.github/CONTRIBUTING.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,10 @@ To trigger the release workflow, go to the "Actions" tab in the GitHub repositor
4848

4949
GitHub Actions for this repo are configured in [./workflows](./workflows).
5050

51+
- [build-and-test.yml](./workflows/build-and-test.yml) - builds the project and runs tests. It is triggered when a pull request is opened, reopened, edited, or synchronized. It runs tests for different test types: `unit`, `e2e`, and `mitm`.
5152
- [conventional-commits.yml](./workflows/conventional-commits.yml) - checks the title of pull requests to ensure they follow a specified format. It is triggered when a pull request is opened, reopened, edited, or synchronized.
52-
- [e2e-tests.yml](./workflows/e2e-tests.yml) - runs end-to-end tests for the project. It is triggered when a pull request is opened, reopened, edited, or synchronized.
53-
- [lint.yml](./workflows/lint.yml) - checks the code for linting errors. It is triggered when a pull request is opened, reopened, edited, or synchronized.
54-
- [mitm.yml](./workflows/mitm.yml) - sets up a Man-in-the-Middle (MITM) proxy for testing purposes. It is triggered when a pull request is opened, reopened, edited, or synchronized.
5553
- [prepare-release.yml](./workflows/prepare-release.yml) - prepares a release by creating a pull request and a GitHub release. It is triggered manually through a workflow dispatch event. The user needs to specify the next SemVer version as an input when triggering the workflow.
56-
- [prettier.yml](./workflows/prettier.yml) - checks the formatting of the code using Prettier. It is triggered when a pull request is opened, reopened, edited, or synchronized.
5754
- [publish.yml](./workflows/publish.yml) - used to publish and release a new version of the project. It is triggered when a pull request is closed and merged into the main branch, and the pull request's head branch starts with `release/`.
58-
- [size-limit.yml](./workflows/size-limit.yml) - uses the `andresz1/size-limit-action` action to calculate the size of the project.
59-
- [unit-tests.yml](./workflows/unit-tests.yml) - runs unit tests for the project. It is triggered when a pull request is opened, reopened, edited, or synchronized.
6055

6156
## Reviewing
6257

@@ -68,7 +63,7 @@ All commits in the master branch should come from squashed GitHub Pull Requests,
6863

6964
# Release new version and Publish it to NPM
7065

71-
> [!IMPORTANT]
66+
> [!IMPORTANT]
7267
> The 5-line script shared below should give you an overview of what you need to do to execute the process, however, it is **not recommended** to actually run it this way, because the script will approve and merge the PR - something you should do manually!
7368
>
7469
> ```
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
name: Build and Test
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
build:
8+
name: build:required
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v4
13+
14+
- name: Setup PNPM
15+
uses: dfinity/ci-tools/actions/setup-pnpm@main
16+
with:
17+
node_version_file: '.nvmrc'
18+
19+
- name: Build
20+
run: pnpm build
21+
22+
- name: Upload Build Artifacts
23+
uses: actions/upload-artifact@v4
24+
with:
25+
name: build-artifact
26+
path: ./packages/*/lib/
27+
28+
tests:
29+
name: tests:required
30+
runs-on: ubuntu-latest
31+
needs: build
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
test_type: [unit, e2e, mitm]
36+
node:
37+
- 20.18 # without require(esm)
38+
- 20.19 # with require(esm), see https://nodejs.org/en/blog/release/v20.19.0/#requireesm-is-now-enabled-by-default
39+
- 22
40+
steps:
41+
- name: Checkout code
42+
uses: actions/checkout@v4
43+
44+
- name: Setup PNPM
45+
uses: dfinity/ci-tools/actions/setup-pnpm@main
46+
with:
47+
node_version: ${{ matrix.node }}
48+
49+
- name: Download Build Artifacts
50+
uses: actions/download-artifact@v4
51+
with:
52+
name: build-artifact
53+
path: ./
54+
55+
- name: Setup DFX
56+
if: ${{ matrix.test_type == 'mitm' || matrix.test_type == 'e2e' }}
57+
uses: dfinity/setup-dfx@main
58+
59+
- name: Setup e2e tests
60+
if: ${{ matrix.test_type == 'e2e' }}
61+
run: pnpm run -F @e2e/node setup
62+
63+
- name: Setup mitm tests
64+
if: ${{ matrix.test_type == 'mitm' }}
65+
working-directory: e2e/node
66+
run: |
67+
dfx start --background
68+
dfx deploy counter
69+
70+
- name: Running mitmdump
71+
if: ${{ matrix.test_type == 'mitm' }}
72+
run: |
73+
set -ex
74+
mitmdump -p 8888 --mode reverse:http://localhost:4943 \
75+
--modify-headers '/~s/Transfer-Encoding/' \
76+
--modify-body '/~s/Hello/Hullo' \
77+
&
78+
sleep 20
79+
80+
- name: Run unit tests
81+
if: ${{ matrix.test_type == 'unit' }}
82+
run: pnpm test
83+
84+
- name: Run e2e tests
85+
if: ${{ matrix.test_type == 'e2e' }}
86+
run: pnpm run -F @e2e/node e2e
87+
88+
- name: Run mitm tests
89+
if: ${{ matrix.test_type == 'mitm' }}
90+
run: pnpm run -F @e2e/node mitm
91+
92+
- name: Run Tests
93+
run: |
94+
if [ "${{ matrix.test_type }}" == "unit" ]; then
95+
pnpm test;
96+
elif [ "${{ matrix.test_type }}" == "e2e" ]; then
97+
pnpm run -F @e2e/node e2e;
98+
else
99+
pnpm run -F @e2e/node mitm;
100+
fi
101+
102+
build_docs:
103+
name: build_docs:required
104+
runs-on: ubuntu-latest
105+
needs: build
106+
steps:
107+
- name: Checkout code
108+
uses: actions/checkout@v4
109+
110+
- name: Setup PNPM
111+
uses: dfinity/ci-tools/actions/setup-pnpm@main
112+
with:
113+
node_version_file: '.nvmrc'
114+
115+
- name: Download Build Artifacts
116+
uses: actions/download-artifact@v4
117+
with:
118+
name: build-artifact
119+
path: ./
120+
121+
- name: Generate docs
122+
run: pnpm make:docs
123+
124+
size_limit:
125+
name: size_limit:required
126+
runs-on: ubuntu-latest
127+
needs: build
128+
steps:
129+
- name: Checkout code
130+
uses: actions/checkout@v4
131+
132+
- name: Setup PNPM
133+
uses: dfinity/ci-tools/actions/setup-pnpm@main
134+
with:
135+
node_version_file: '.nvmrc'
136+
137+
- name: Download Build Artifacts
138+
uses: actions/download-artifact@v4
139+
with:
140+
name: build-artifact
141+
path: ./
142+
143+
- uses: andresz1/size-limit-action@v1
144+
with:
145+
github_token: ${{ secrets.GITHUB_TOKEN }}
146+
build_script: bundle
147+
148+
audit:
149+
name: audit:required
150+
runs-on: ubuntu-latest
151+
needs: build
152+
steps:
153+
- name: Checkout code
154+
uses: actions/checkout@v4
155+
156+
- name: Setup PNPM
157+
uses: dfinity/ci-tools/actions/setup-pnpm@main
158+
with:
159+
node_version_file: '.nvmrc'
160+
161+
- name: Run audit
162+
run: pnpm audit
163+
164+
attw:
165+
name: attw:required
166+
runs-on: ubuntu-latest
167+
needs: build
168+
steps:
169+
- name: Checkout code
170+
uses: actions/checkout@v4
171+
172+
- name: Setup PNPM
173+
uses: dfinity/ci-tools/actions/setup-pnpm@main
174+
with:
175+
node_version_file: '.nvmrc'
176+
177+
- name: Download Build Artifacts
178+
uses: actions/download-artifact@v4
179+
with:
180+
name: build-artifact
181+
path: ./
182+
183+
- name: Run attw
184+
run: pnpm attw
185+
186+
format_check:
187+
name: format_check:required
188+
runs-on: ubuntu-latest
189+
steps:
190+
- name: Checkout code
191+
uses: actions/checkout@v4
192+
193+
- name: Setup PNPM
194+
uses: dfinity/ci-tools/actions/setup-pnpm@main
195+
with:
196+
node_version_file: '.nvmrc'
197+
198+
- name: Check formatting
199+
run: pnpm prettier:check
200+
201+
lint:
202+
name: lint:required
203+
runs-on: ubuntu-latest
204+
steps:
205+
- name: Checkout code
206+
uses: actions/checkout@v4
207+
208+
- name: Setup PNPM
209+
uses: dfinity/ci-tools/actions/setup-pnpm@main
210+
with:
211+
node_version_file: '.nvmrc'
212+
213+
- name: Run Lint
214+
run: pnpm lint
215+

.github/workflows/commitizen.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: commitizen
2+
3+
on:
4+
merge_group:
5+
pull_request:
6+
7+
jobs:
8+
check_pr_title:
9+
name: check_pr_title
10+
if: github.event_name == 'pull_request'
11+
uses: dfinity/ci-tools/.github/workflows/check-pr-title.yaml@main
12+
13+
check_commit_messages:
14+
name: check_commit_messages
15+
if: github.event_name == 'merge_group'
16+
uses: dfinity/ci-tools/.github/workflows/check-commit-messages.yaml@main
17+
18+
commitizen:
19+
name: commitizen:required
20+
runs-on: ubuntu-latest
21+
needs: [check_pr_title, check_commit_messages]
22+
if: always()
23+
steps:
24+
- name: Check previous jobs
25+
run: |
26+
if [[ "${{ needs.check_pr_title.result }}" == "success" || "${{ needs.check_pr_title.result }}" == "skipped" ]] &&
27+
[[ "${{ needs.check_commit_messages.result }}" == "success" || "${{ needs.check_commit_messages.result }}" == "skipped" ]]; then
28+
echo "All required jobs passed or were skipped."
29+
else
30+
echo "One or more jobs failed."
31+
exit 1
32+
fi

.github/workflows/conventional-commits.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.

.github/workflows/docs.yml

Lines changed: 0 additions & 35 deletions
This file was deleted.

.github/workflows/e2e-tests.yml

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)