Skip to content

Commit

Permalink
Merge pull request #26 from tuhanayim/ci/add
Browse files Browse the repository at this point in the history
Add CI, CD and Release Workflows
  • Loading branch information
catuhana authored Nov 22, 2023
2 parents 7959f1f + 61efc84 commit 4ed7d93
Show file tree
Hide file tree
Showing 3 changed files with 195 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/cd.yaml
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
62 changes: 62 additions & 0 deletions .github/workflows/ci.yaml
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
80 changes: 80 additions & 0 deletions .github/workflows/release.yaml
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
}
});

0 comments on commit 4ed7d93

Please sign in to comment.