Skip to content

Commit 370e5bf

Browse files
committed
Add ci and cd
1 parent 841a84d commit 370e5bf

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

.github/workflows/cd.yaml

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Release & Publish
2+
3+
on:
4+
push:
5+
tags:
6+
- "**"
7+
8+
jobs:
9+
release:
10+
name: Create release
11+
runs-on: ubuntu-latest
12+
outputs:
13+
tag: ${{ steps.release-tag.outputs.tag }}
14+
id: ${{ steps.release-id.outputs.id }}
15+
steps:
16+
- name: Determine tag
17+
id: release-tag
18+
run: |
19+
RELEASE_TAG=${GITHUB_REF#refs/tags/}
20+
echo "RELEASE_TAG=${RELEASE_TAG}" >> $GITHUB_ENV
21+
echo "tag=${RELEASE_TAG}" >> $GITHUB_OUTPUT
22+
- name: Create the release
23+
run: |
24+
curl \
25+
-X POST \
26+
-H "Accept: application/vnd.github+json" \
27+
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
28+
https://api.github.com/repos/${{ github.repository }}/releases \
29+
--data '{
30+
"tag_name": "${{ env.RELEASE_TAG }}",
31+
"name": "Release ${{ env.RELEASE_TAG }}",
32+
"generate_release_notes": true
33+
}' \
34+
-o release.json
35+
- name: Determine release id
36+
id: release-id
37+
run: |
38+
RELEASE_ID=$(jq -r '.id' release.json)
39+
echo "id=${RELEASE_ID}" >> $GITHUB_OUTPUT
40+
41+
build-and-publish:
42+
name: Build and publish
43+
runs-on: ${{ matrix.job.os }}
44+
strategy:
45+
matrix:
46+
job:
47+
- os: ubuntu-latest
48+
target: x86_64-unknown-linux-gnu
49+
- os: macos-latest
50+
target: x86_64-apple-darwin
51+
- os: windows-latest
52+
target: x86_64-pc-windows-msvc
53+
needs: release
54+
steps:
55+
- name: Checkout code
56+
uses: actions/checkout@v3
57+
- name: Build binary
58+
run: |
59+
rustup update stable
60+
rustup default stable
61+
rustup target add ${{ matrix.job.target }}
62+
cargo build --release --target ${{ matrix.job.target }}
63+
- name: Create tarball
64+
run: |
65+
TARBALL=sws-${{ needs.release.outputs.tag }}-${{ matrix.job.target }}.tar.gz
66+
tar -zcvf ${TARBALL} -C target/${{ matrix.job.target }}/release sws
67+
echo "TARBALL=${TARBALL}" >> $GITHUB_ENV
68+
- name: Upload tarball to the release
69+
run: |
70+
curl \
71+
-X POST \
72+
-H "Accept: application/vnd.github+json" \
73+
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
74+
-H 'Content-Type: application/octet-stream' \
75+
--upload-file ${{ env.TARBALL }} \
76+
https://uploads.github.com/repos/${{ github.repository }}/releases/${{ needs.release.outputs.id }}/assets?name=${{ env.TARBALL }}

.github/workflows/ci.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Build & Test
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
build-and-test:
14+
name: Build and test
15+
runs-on: ${{ matrix.os }}
16+
strategy:
17+
matrix:
18+
os: [ubuntu-latest, macos-latest, windows-latest]
19+
steps:
20+
- uses: actions/checkout@v3
21+
- run: rustup update
22+
- run: cargo build
23+
- run: cargo fmt --check --all
24+
- run: cargo clippy -- -D warnings
25+
- run: cargo test --verbose

0 commit comments

Comments
 (0)