forked from slowli/externref
-
Notifications
You must be signed in to change notification settings - Fork 0
168 lines (143 loc) · 4.84 KB
/
ci.yml
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
env:
msrv: 1.66.0
nightly: nightly-2023-03-19
jobs:
build-msrv:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.msrv }}
- name: Cache cargo build
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-msrv-cargo-${{ hashFiles('Cargo.lock') }}
restore-keys: ${{ runner.os }}-msrv-cargo
# The E2E test uses `wasmtime` with frequently changing MSRV, so we don't test it here.
- name: Run tests
run: cargo test -p externref -p externref-macro --all-features --all-targets
- name: Run doc tests
run: cargo test -p externref -p externref-macro --all-features --doc
build:
uses: ./.github/workflows/build-reusable.yml
build-docker:
needs:
- build
- build-msrv
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache Docker build
uses: actions/cache@v3
with:
path: target/docker
key: ${{ runner.os }}-docker-buildkit-${{ hashFiles('Cargo.lock') }}
restore-keys: ${{ runner.os }}-docker-buildkit
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}
- name: Log in to Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
with:
driver-opts: image=moby/buildkit:buildx-stable-1
- name: Identify Buildx container
run: |
CONTAINER_ID=$(docker ps --filter=ancestor=moby/buildkit:buildx-stable-1 --format='{{ .ID }}')
echo "buildx_container=$CONTAINER_ID" | tee -a "$GITHUB_ENV"
- name: Restore cache
run: |
if [[ -f target/docker/cache.db ]]; then
docker cp target/docker/. "$BUILDER:/var/lib/buildkit"
docker restart "$BUILDER"
# Wait until the container is restarted
sleep 5
fi
docker buildx du # Check the restored cache
env:
BUILDER: ${{ env.buildx_container }}
- name: Build image
uses: docker/build-push-action@v3
with:
context: .
file: crates/cli/Dockerfile
load: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# We want to only store cache volumes (type=exec.cachemount) since
# their creation is computationally bound as opposed to other I/O-bound volume types.
- name: Extract image cache
run: |
docker buildx prune --force --filter=type=regular
docker buildx prune --force --filter=type=source.local
rm -rf target/docker && mkdir -p target/docker
docker cp "$BUILDER:/var/lib/buildkit/." target/docker
du -ah -d 1 target/docker
env:
BUILDER: ${{ env.buildx_container }}
- name: Test image (--help)
run: docker run --rm "$IMAGE_TAG" --help
env:
IMAGE_TAG: ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
- name: Test image (transform)
run: |
docker run -i --rm --env RUST_LOG=externref=debug "$IMAGE_TAG" - \
< crates/cli/tests/test.wasm \
> /dev/null
env:
IMAGE_TAG: ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
- name: Publish image
if: github.event_name == 'push'
run: docker push "$IMAGE_TAG"
env:
IMAGE_TAG: ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
document:
if: github.event_name == 'push'
needs:
- build
- build-msrv
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.nightly }}
- name: Cache cargo build
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-document-cargo-${{ hashFiles('Cargo.lock') }}
restore-keys: ${{ runner.os }}-document-cargo
- name: Build docs
run: |
cargo clean --doc && cargo rustdoc -p externref --all-features -- --cfg docsrs \
&& cargo rustdoc -p externref-macro -- --cfg docsrs
- name: Deploy
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages
folder: target/doc
single-commit: true