-
Notifications
You must be signed in to change notification settings - Fork 0
143 lines (119 loc) · 4.02 KB
/
cd.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
name: CD
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened, closed]
branches:
- main
workflow_dispatch: {}
env:
CARGO_TERM_COLOR: always
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup nightly toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
- run: cargo fmt -- --check
- run: cargo clippy -- -D warnings
test:
strategy:
fail-fast: true
matrix:
os: [macos-latest, ubuntu-latest]
rust: [nightly, stable]
runs-on: ${{ matrix.os }}
continue-on-error: false
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true
- name: Cache cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-${{ matrix.rust }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.rust }}-cargo-registry-
- name: Cache cargo index
uses: actions/cache@v3
with:
path: ~/.cargo/git
key: ${{ runner.os }}-${{ matrix.rust }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.rust }}-cargo-index-
- name: Cache cargo build
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-cargo-build-${{ matrix.rust }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-build-${{ matrix.rust }}-
- name: Run integration tests
run: |
cargo build --release
cargo test --release
./tools/test.sh
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
deploy:
needs: [test, lint]
runs-on: ubuntu-latest
continue-on-error: false
steps:
- name: Checkout code
uses: actions/checkout@v3
- run: sudo apt-get install jq
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: Install cargo-bump
run: cargo install cargo-bump
- name: Previous version
id: prev_version
run: echo "::set-output name=version::$(./scripts/current-version)"
shell: bash
- name: Bump version using cargo-bump
run: cargo bump patch
- name: Next version
id: next_version
run: echo "::set-output name=version::$(./scripts/current-version)"
shell: bash
- name: Check that version number was bumped
if: ${{ steps.prev_version.outputs.version == steps.next_version.outputs.version }}
run: exit 1
- name: Update dependencies & ensure version changed
if: ${{ github.event.pull_request.merged == true }}
run: cargo update --aggressive
- name: Commit changes and tag release
run: |
git add Cargo.lock Cargo.toml
git commit -m "Update dependencies for version ${{ steps.next_version.outputs.version }}"
git tag -a "v${{ steps.next_version.outputs.version }}" -m "Release v${{ steps.next_version.outputs.version }}"
- name: Publish to crates.io (Dry Run)
if: ${{ github.event.pull_request.merged != true }}
run: |
echo "Dry run: would publish to crates.io but skipping because this is a dry run."
- name: Push changes to main
if: ${{ github.event.pull_request.merged == true }}
run: |
git push origin main
git push origin "v${{ steps.next_version.outputs.version }}"
- name: Publish to crates.io (Actual Run)
if: ${{ github.event.pull_request.merged == true }}
uses: katyo/publish-crates@v2
with:
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}