-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from tuhanayim/ci/add
Add CI, CD and Release Workflows
- Loading branch information
Showing
3 changed files
with
195 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: CD | ||
run-name: ${{ inputs.reason }} | ||
|
||
on: | ||
push: | ||
tags: | ||
- v* | ||
workflow_run: | ||
workflows: | ||
- CI | ||
types: | ||
- completed | ||
workflow_dispatch: | ||
inputs: | ||
reason: | ||
description: Dispatch reason | ||
required: true | ||
type: string | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
||
jobs: | ||
upload-artifact: | ||
name: Build and Upload Binary | ||
strategy: | ||
matrix: | ||
os: | ||
- ubuntu-latest | ||
- macos-latest | ||
- windows-latest | ||
runs-on: ${{ matrix.os }} | ||
if: github.event_name != 'workflow_run' || (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup or update Rust toolchain | ||
run: rustup toolchain install stable --profile default | ||
|
||
- name: Setup Rust cache | ||
uses: Swatinem/rust-cache@v2 | ||
|
||
- name: Build project | ||
run: cargo build --verbose --release | ||
|
||
- name: Upload artifact | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: lure-${{ runner.os }} | ||
path: target/release/lure | ||
|
||
# TODO: add publish container image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
name: CI | ||
run-name: ${{ inputs.reason }} | ||
|
||
on: | ||
push: | ||
paths: | ||
- .github/workflows/ci.yaml | ||
- src/** | ||
- build.rs | ||
- Cargo.* | ||
pull_request: | ||
branches: | ||
- main | ||
paths: | ||
- .github/workflows/ci.yaml | ||
- src/** | ||
- build.rs | ||
- Cargo.* | ||
workflow_dispatch: | ||
inputs: | ||
reason: | ||
description: Dispatch reason | ||
required: true | ||
type: string | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
RUSTFLAGS: -D warnings | ||
|
||
jobs: | ||
ci: | ||
name: Run CI | ||
|
||
strategy: | ||
matrix: | ||
os: | ||
- ubuntu-latest | ||
- macos-latest | ||
- windows-latest | ||
toolchain: | ||
- stable | ||
- nightly | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Rust problem matchers | ||
uses: r7kamura/rust-problem-matchers@main | ||
|
||
- name: Setup or update Rust ${{ matrix.toolchain }} toolchain | ||
run: rustup toolchain install ${{ matrix.toolchain }} --profile default | ||
|
||
- name: Setup Rust cache | ||
uses: Swatinem/rust-cache@v2 | ||
|
||
- name: Check code format | ||
run: cargo +${{ matrix.toolchain }} fmt --verbose --all --check | ||
|
||
- name: Check code lint | ||
if: '!cancelled()' | ||
run: cargo +${{ matrix.toolchain }} clippy --verbose -- -W clippy::nursery |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
name: Release | ||
run-name: ${{ inputs.reason }} | ||
|
||
on: | ||
push: | ||
tags: | ||
- v* | ||
workflow_dispatch: | ||
inputs: | ||
reason: | ||
description: Dispatch reason | ||
required: true | ||
type: string | ||
|
||
jobs: | ||
create-release: | ||
name: Create Release | ||
if: github.event_name == 'push' | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
outputs: | ||
release-upload-url: ${{ steps.create-release.outputs.upload_url }} | ||
steps: | ||
- name: Create release | ||
id: create-release | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const tag = context.ref.split('/').at(-1); | ||
const release = await github.rest.repos.createRelease({ | ||
name: `Release ${tag}`, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
tag_name: tag, | ||
generate_release_notes: true | ||
}); | ||
return release.data.upload_url; | ||
build-and-upload: | ||
name: Build and Upload | ||
needs: create-release | ||
strategy: | ||
matrix: | ||
os: | ||
- ubuntu-latest | ||
- windows-latest | ||
- macos-latest | ||
runs-on: ${{ matrix.os }} | ||
permissions: | ||
contents: write | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup or update Rust toolchain | ||
run: rustup toolchain install stable --profile default | ||
|
||
- name: Setup Rust cache | ||
uses: Swatinem/rust-cache@v2 | ||
|
||
- name: Build project | ||
run: cargo build --verbose --release | ||
|
||
- name: Upload Release Asset | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const asset = await (await import("node:fs")).readFile("target/release/${github.repository.name}"); | ||
await github.rest.repos.uploadReleaseAsset({ | ||
url: ${{ needs.create-release.outputs.release-upload-url }}, | ||
name: "lure-release-${{ runner.os }}", | ||
data: asset, | ||
headers: { | ||
'Content-Type': 'application/octet-stream', | ||
'Content-Length': asset.length | ||
} | ||
}); |