Skip to content

Commit f3b41f0

Browse files
committed
setup caching
1 parent 138758a commit f3b41f0

File tree

8 files changed

+280
-132
lines changed

8 files changed

+280
-132
lines changed

.github/workflows/tests.yml

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
name: CI
1+
name: Tests and lints
22

33
on:
44
pull_request:
5-
workflow_dispatch:
65

76
jobs:
87
ci:
@@ -13,8 +12,35 @@ jobs:
1312
- name: Check out code
1413
uses: actions/checkout@v4
1514

15+
- name: Install dagger
16+
run: curl -fsSL https://dl.dagger.io/dagger/install.sh | BIN_DIR=$HOME/.local/bin sh
17+
18+
- uses: actions/cache/restore@v4
19+
with:
20+
path: ./cache
21+
key: dagger-cache-${{ github.run_id }}
22+
restore-keys:
23+
dagger-cache-
24+
25+
- name: make sure cache directory exists.
26+
run: mkdir -p ./cache/target
27+
1628
- name: Run tests
17-
uses: dagger/dagger-for-github@v8.1.0
29+
id: tests
30+
run: dagger run cargo run -p dagger_pipeline --features ci -- tests --export
31+
continue-on-error: true
32+
33+
- uses: actions/cache/save@v4
34+
with:
35+
path: ./cache
36+
key: dagger-cache-${{ github.run_id }}
37+
38+
- name: Upload report
39+
uses: actions/upload-artifact@v4
1840
with:
19-
verb: run
20-
args: cargo run -p dagger_pipeline -- tests --tui
41+
name: test-report
42+
path: ./allure_report
43+
44+
- name: Fail Workflow
45+
if: steps.tests.outcome == 'failure'
46+
run: exit 1
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Upload test results
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Tests and lints"]
6+
types: [completed]
7+
8+
permissions:
9+
contents: read
10+
pull-requests: write
11+
12+
jobs:
13+
upload:
14+
if: github.event.workflow_run.conclusion != 'cancelled'
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Resolve PR number
18+
id: pr
19+
uses: actions/github-script@v7
20+
with:
21+
script: |
22+
const run = context.payload.workflow_run;
23+
// Prefer PR info embedded in the workflow_run payload
24+
if (run.pull_requests && run.pull_requests.length > 0) {
25+
core.setOutput('number', String(run.pull_requests[0].number));
26+
} else {
27+
// Fallback: find PR by commit SHA
28+
const {owner, repo} = context.repo;
29+
const {data} = await github.rest.repos.listPullRequestsAssociatedWithCommit({
30+
owner, repo, commit_sha: run.head_sha
31+
});
32+
core.setOutput('number', data[0]?.number ? String(data[0].number) : '');
33+
}
34+
35+
- name: Download report artifact
36+
if: steps.pr.outputs.number != ''
37+
uses: dawidd6/action-download-artifact@v3
38+
with:
39+
run_id: ${{ github.event.workflow_run.id }}
40+
name: test-report
41+
path: ./report
42+
43+
- name: Deploy preview to Cloudflare Pages
44+
if: steps.pr.outputs.number != ''
45+
id: pages
46+
uses: cloudflare/pages-action@v1
47+
with:
48+
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
49+
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
50+
projectName: natrix-test-result
51+
directory: ./report
52+
branch: pr-${{ steps.pr.outputs.number }}-${{ github.event.workflow_run.head_sha }}
53+
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
54+
55+
- name: Comment on PR with preview URL
56+
if: steps.pr.outputs.number != '' && steps.pages.outputs.url != ''
57+
uses: marocchino/sticky-pull-request-comment@v2
58+
with:
59+
header: test-report-preview
60+
number: ${{ steps.pr.outputs.number }}
61+
message: |
62+
Test report: ${{ steps.pages.outputs.url }}
63+
64+
- name: Add to job summary
65+
if: steps.pages.outputs.url != ''
66+
run: |
67+
echo 'Test report preview: ${{ steps.pages.outputs.url }}' >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)