Skip to content

Commit 3b2aa3a

Browse files
Kitt3120Murasko
authored andcommitted
add: CI/CD from lum-rs/template_rust
1 parent b0b6a8b commit 3b2aa3a

File tree

4 files changed

+161
-0
lines changed

4 files changed

+161
-0
lines changed

.github/dependabot.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Please see the documentation for all configuration options:
2+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
3+
4+
version: 2
5+
updates:
6+
- package-ecosystem: "github-actions"
7+
directory: "/"
8+
target-branch: main
9+
schedule:
10+
interval: "daily"
11+
- package-ecosystem: "cargo"
12+
directory: "/"
13+
target-branch: main
14+
schedule:
15+
interval: "daily"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Build and test
2+
on:
3+
pull_request:
4+
branches: [main]
5+
workflow_dispatch:
6+
jobs:
7+
build_and_test:
8+
name: Build and test
9+
runs-on: ${{ matrix.os }}
10+
strategy:
11+
matrix:
12+
env: [ubuntu-64, macos-64, windows-64]
13+
include:
14+
- env: ubuntu-64
15+
os: ubuntu-latest
16+
- env: macos-64
17+
os: macos-latest
18+
- env: windows-64
19+
os: windows-latest
20+
permissions:
21+
contents: read
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
25+
- name: Setup Rust toolchain for ${{ matrix.os }}
26+
uses: actions-rust-lang/setup-rust-toolchain@fb51252c7ba57d633bc668f941da052e410add48
27+
- name: Test for ${{ matrix.os }}
28+
uses: actions-rs/cargo@844f36862e911db73fe0815f00a4a2602c279505
29+
with:
30+
command: test
31+
args: --release --all-features
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Publish pre-release
2+
on:
3+
push:
4+
branches: [main]
5+
jobs:
6+
github:
7+
name: Publish GitHub
8+
environment: GITHUB_PRE_RELEASE
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: write
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
15+
- name: Setup Rust toolchain for ubuntu-latest
16+
uses: actions-rust-lang/setup-rust-toolchain@fb51252c7ba57d633bc668f941da052e410add48
17+
- name: Package
18+
uses: actions-rs/cargo@844f36862e911db73fe0815f00a4a2602c279505
19+
with:
20+
command: package
21+
args: --all-features
22+
- name: Read crate name
23+
id: crate_name
24+
run: echo "crate_name=$(cargo read-manifest | jq -r .name)" >> $GITHUB_OUTPUT
25+
- name: Read version
26+
id: version
27+
run: echo "version=$(cargo read-manifest | jq -r .version)" >> $GITHUB_OUTPUT
28+
- name: Read git commit hash
29+
id: commit_hash
30+
run: echo "commit_hash=$(git rev-parse --short "$GITHUB_SHA")" >> $GITHUB_OUTPUT
31+
- name: Create release
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Provided by GitHub Actions
34+
run: gh release create "${{ steps.commit_hash.outputs.commit_hash }}" --repo="$GITHUB_REPOSITORY" --target main --title="Pre-Release ${{ steps.commit_hash.outputs.commit_hash }} (${{ steps.version.outputs.version }})" --generate-notes --prerelease "./target/package/${{ steps.crate_name.outputs.crate_name }}-${{ steps.version.outputs.version }}.crate"
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Publish release
2+
on:
3+
push:
4+
branches: [release/**]
5+
jobs:
6+
check_version_bump:
7+
name: Check version bump
8+
runs-on: ubuntu-latest
9+
permissions:
10+
contents: read
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
14+
- name: Setup Rust toolchain for ubuntu-latest
15+
uses: actions-rust-lang/setup-rust-toolchain@fb51252c7ba57d633bc668f941da052e410add48
16+
- name: Read source branch version
17+
id: source_version
18+
run: echo "version=$(cargo read-manifest | jq -r .version)" >> $GITHUB_OUTPUT
19+
- name: Update cargo index
20+
run: cargo search
21+
- name: Read crates.io version
22+
id: crates_io_version
23+
run: echo "version=$(cargo search --limit 1 $(cargo read-manifest | jq -r .name) | grep -oP '(?<=")([0-9]+.[0-9]+.[0-9]+)(?=")')" >> $GITHUB_OUTPUT
24+
- name: Parse and compare versions
25+
run: |
26+
source_version="${{ steps.source_version.outputs.version }}"
27+
crates_io_version="${{ steps.crates_io_version.outputs.version }}"
28+
if [ "$(printf '%s\n' "$crates_io_version" "$source_version" | sort -V | head -n1)" != "$source_version" ]; then
29+
echo "Source branch version ($source_version) is higher than crates.io version ($crates_io_version)."
30+
else
31+
echo "Source branch version ($source_version) is not higher than crates.io version ($crates_io_version)."
32+
exit 1
33+
fi
34+
crates_io:
35+
name: Publish crates.io
36+
needs: check_version_bump
37+
environment: CRATES_IO
38+
runs-on: ubuntu-latest
39+
permissions:
40+
contents: read
41+
steps:
42+
- name: Checkout
43+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
44+
- name: Setup Rust toolchain for ubuntu-latest
45+
uses: actions-rust-lang/setup-rust-toolchain@fb51252c7ba57d633bc668f941da052e410add48
46+
- name: Login to crates.io
47+
uses: actions-rs/cargo@844f36862e911db73fe0815f00a4a2602c279505
48+
with:
49+
command: login
50+
args: ${{ secrets.CRATES_IO_TOKEN }}
51+
- name: Publish to crates.io
52+
uses: actions-rs/cargo@844f36862e911db73fe0815f00a4a2602c279505
53+
with:
54+
command: publish
55+
github:
56+
name: Publish GitHub
57+
needs: crates_io
58+
environment: GITHUB_RELEASE
59+
runs-on: ubuntu-latest
60+
permissions:
61+
contents: write
62+
steps:
63+
- name: Checkout
64+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
65+
- name: Setup Rust toolchain for ubuntu-latest
66+
uses: actions-rust-lang/setup-rust-toolchain@fb51252c7ba57d633bc668f941da052e410add48
67+
- name: Package
68+
uses: actions-rs/cargo@844f36862e911db73fe0815f00a4a2602c279505
69+
with:
70+
command: package
71+
args: --all-features
72+
- name: Read crate name
73+
id: crate_name
74+
run: echo "crate_name=$(cargo read-manifest | jq -r .name)" >> $GITHUB_OUTPUT
75+
- name: Read version
76+
id: version
77+
run: echo "version=$(cargo read-manifest | jq -r .version)" >> $GITHUB_OUTPUT
78+
- name: Create release
79+
env:
80+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Provided by GitHub Actions
81+
run: gh release create "${{ steps.version.outputs.version }}" --repo="$GITHUB_REPOSITORY" --title="Release ${{ steps.version.outputs.version }}" --generate-notes --latest "./target/package/${{ steps.crate_name.outputs.crate_name }}-${{ steps.version.outputs.version }}.crate"

0 commit comments

Comments
 (0)