-
Notifications
You must be signed in to change notification settings - Fork 0
152 lines (145 loc) · 5.16 KB
/
ci.yaml
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
name: CI/CD
on:
push:
paths-ignore:
- README.md
branches: [main]
tags: [v*.*.*]
pull_request: {}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Test
run: cargo test -F bin,wasm
- name: Lint
run: cargo clippy -F bin,wasm
version:
runs-on: ubuntu-latest
needs: test
outputs:
version: ${{ steps.version.outputs.version }}
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Compute package version
id: version
run: echo "version=${GITHUB_REF##refs/tags/v}" >> $GITHUB_OUTPUT
build-wasm:
runs-on: ubuntu-latest
needs: version
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- name: Install npm packages
run: bun install --frozen-lockfile
- name: Build wasm
run: |
bun run build
cd pkg/
cp ../.npmrc .
npm version --no-git-tag-version '${{ needs.version.outputs.version }}'
- uses: actions/upload-artifact@v4
with:
if-no-files-found: error
name: base-converter-wasm
path: pkg/
build:
needs: version
strategy:
max-parallel: 1
matrix:
os: [ubuntu-latest,
# macos-latest-xlarge
]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Install cross
run: cargo install cross --git https://github.com/cross-rs/cross
- name: Override version
run: |
if "$(uname -s)" = "Darwin"; then
SED="sed -i ''"
else
SED="sed -i"
fi
$SED -E 's/^version = ".+"$/version = "${{ needs.version.outputs.version }}"/' Cargo.toml
- name: Build cross platforms
if: matrix.os == 'ubuntu-latest'
run: |
cross build --release --locked --bin base-converter -F bin --target aarch64-unknown-linux-gnu
cross build --release --locked --bin base-converter -F bin --target aarch64-unknown-linux-musl
cross build --release --locked --bin base-converter -F bin --target x86_64-unknown-linux-gnu
cross build --release --locked --bin base-converter -F bin --target x86_64-unknown-linux-musl
cross build --release --locked --bin base-converter -F bin --target x86_64-pc-windows-gnu
mkdir tmp/
mv ./target/aarch64-unknown-linux-gnu/release/base-converter ./tmp/base-converter-aarch64-unknown-linux-gnu
mv ./target/aarch64-unknown-linux-musl/release/base-converter ./tmp/base-converter-aarch64-unknown-linux-musl
mv ./target/x86_64-unknown-linux-gnu/release/base-converter ./tmp/base-converter-x86_64-unknown-linux-gnu
mv ./target/x86_64-unknown-linux-musl/release/base-converter ./tmp/base-converter-x86_64-unknown-linux-musl
mv ./target/x86_64-pc-windows-gnu/release/base-converter.exe ./tmp/base-converter-x86_64-pc-windows-gnu.exe
- name: Build macos
if: matrix.os == 'macos-latest-xlarge'
run: |
cargo build --release --locked --bin base-converter -F bin
mkdir tmp/
mv ./target/aarch64-apple-darwin/release/base-converter ./tmp/base-converter-aarch64-apple-darwin
- uses: actions/upload-artifact@v4
with:
if-no-files-found: error
name: cli-${{ matrix.os }}
path: tmp/
release:
runs-on: ubuntu-latest
needs: [version, build-wasm, build]
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
path: dist/
- name: Publish on npmjs.com
working-directory: dist/base-converter-wasm
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish
- name: Publish on crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
sed -i -E 's/^version = ".+"$/version = "${{ needs.version.outputs.version }}"/' Cargo.toml
cargo publish --allow-dirty --locked
- name: Github Release
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
fail_on_unmatched_files: true
tag_name: v${{ needs.version.outputs.version }}
files: |
./dist/cli-*/*
body: |
# Rust Doc
https://docs.rs/base-converter/${{ needs.version.outputs.version }}/base_converter/
# NPM Package
https://www.npmjs.com/package/@ctison/base-converter/v/${{ needs.version.outputs.version }}