Skip to content

Commit

Permalink
feat: CI workflows (#7)
Browse files Browse the repository at this point in the history
* feat: add ci workflows

* fix: update ci

* fix: test ci

* fix: test ci

* fix: test ci

* test: ci

* test: ci

* test: update path

* fix: ci debug

* test: ci debug

* fix: test ci

* fix: update yaml

* fix: ref

* fix: undefined spinner

* fix: ci

* feat: add release workflow

* fix: toolchain

* fix: config

* fix: ci

* test: ci

* fix: test ci

* fix: add lock file
  • Loading branch information
ClarkXia authored Nov 15, 2023
1 parent 133a9f3 commit fa4b270
Show file tree
Hide file tree
Showing 18 changed files with 7,289 additions and 2,427 deletions.
8 changes: 8 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ rustflags = [

"-Aclippy::default_constructed_unit_structs",
]
# To be able to run unit tests on macOS, support compilation to 'x86_64-apple-darwin'.
[target.'cfg(target_vendor = "apple")']
rustflags = ["-C", "link-args=-Wl,-undefined,dynamic_lookup"]

# To be able to run unit tests on Linux, support compilation to 'x86_64-unknown-linux-gnu'.
[target.'cfg(target_os = "linux")']
Expand All @@ -38,5 +41,10 @@ rustflags = ["-C", "link-args=-Wl,--warn-unresolved-symbols"]
[target.'cfg(target_os = "windows")']
rustflags = ["-C", "link-args=/FORCE"]

[target.x86_64-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static"]
[target.i686-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static"]

[target.x86_64-apple-darwin]
rustflags = ["-C", "link-arg=-undefined", "-C", "link-arg=dynamic_lookup"]
37 changes: 37 additions & 0 deletions .github/actions/clone-crates/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: clone crates

description: clone rspack crates for github

inputs:
repo:
default: 'web-infra-dev/rspack'
required: false
type: string
dest:
default: 'crates/.rspack_crates'
required: false
type: string
ref:
default: 'v0.3.6'
required: false
type: string
temp:
default: 'crates/.rspack_crates/.temp'
required: false
type: string

runs:
using: composite
steps:
- name: Clone Repo
uses: actions/checkout@v4
with:
repository: web-infra-dev/rspack
path: ${{ inputs.temp }}
ref: ${{ inputs.ref }}

- name: Clean up
shell: bash
run: node scripts/clean.mjs
env:
IS_GITHUB: true
58 changes: 58 additions & 0 deletions .github/actions/pnpm-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: pnpm cache

description: Install Node.js with pnpm global cache

inputs:
node-version:
default: '18'
required: false
type: string
save-if:
default: false
required: false
type: boolean

env:
IS_GITHUB_RUNNER: startsWith(runner.name, 'GitHub Actions')

runs:
using: composite
steps:
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
check-latest: true

# https://pnpm.io/continuous-integration#github-actions
# Uses `packageManagement` field from package.json
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
dest: ${{ runner.tool_cache }}/pnpm

- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT

- name: Restore pnpm cache
id: restore
if: ${{ env.IS_GITHUB_RUNNER }}
uses: actions/cache/restore@v3
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: node-cache-${{ runner.os }}-pnpm-${{ hashFiles('pnpm-lock.yaml') }}
restore-keys: |
node-cache-${{ runner.os }}-pnpm-
- name: Install dependencies
shell: bash
run: pnpm install --no-frozen-lockfile

- name: Save pnpm cache
uses: actions/cache/save@v3
if: ${{ env.IS_GITHUB_RUNNER && inputs.save-if == 'true' && steps.restore.outputs.cache-hit != 'true' }}
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: node-cache-${{ runner.os }}-pnpm-${{ hashFiles('pnpm-lock.yaml') }}
86 changes: 86 additions & 0 deletions .github/actions/rustup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# This action installs the minimal Rust profile and configures Swatinem/rust-cache.
#
# It is needed to install as few Rust components as possbile because
# it takes a few minutes to install some of components on Windows and Mac, especially rust-doc.

name: Rustup

description: Install Rust with cache

inputs:
# See https://rust-lang.github.io/rustup/concepts/components.html
clippy:
default: false
required: false
type: boolean
fmt:
default: false
required: false
type: boolean
docs:
default: false
required: false
type: boolean
save-cache:
default: false
required: false
type: boolean
shared-key:
default: 'check'
required: false
type: string

env:
IS_GITHUB_RUNNER: startsWith(runner.name, 'GitHub Actions')

runs:
using: composite
steps:
- name: Print Inputs
shell: bash
run: |
echo 'clippy: ${{ inputs.clippy }}'
echo 'fmt: ${{ inputs.fmt }}'
echo 'docs: ${{ inputs.docs }}'
echo 'save-cache: ${{ inputs.save-cache }}'
echo 'shared-key: ${{ inputs.shared-key }}'
- name: Remove `profile` line on MacOS
shell: bash
if: runner.os == 'macOS'
run: sed -i '' '/profile/d' rust-toolchain.toml

- name: Remove `profile` line on non-MacOS
shell: bash
if: runner.os != 'macOS'
run: sed -i '/profile/d' rust-toolchain.toml

- name: Set minimal
shell: bash
run: rustup set profile minimal

- name: Add Clippy
shell: bash
if: ${{ inputs.clippy == 'true' }}
run: rustup component add clippy

- name: Add Rustfmt
shell: bash
if: ${{ inputs.fmt == 'true' }}
run: rustup component add rustfmt

- name: Add docs
shell: bash
if: ${{ inputs.docs == 'true' }}
run: rustup component add rust-docs

- name: Install
shell: bash
run: rustup show

- name: Cache on ${{ github.ref_name }}
uses: Swatinem/rust-cache@v2
if: ${{ env.IS_GITHUB_RUNNER }}
with:
shared-key: ${{ inputs.shared-key }}
save-if: ${{ inputs.save-cache == 'true' }}
103 changes: 103 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: CI

on:
merge_group:
types: [checks_requested]
workflow_dispatch:
inputs:
debug_enabled:
type: boolean
description: "Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)"
required: false
default: false
pull_request:
types: [opened, synchronize]
paths-ignore:
- "**/*.md"
branches-ignore:
- "release-**"
push:
branches:
- main
paths-ignore:
- "**/*.md"
tags-ignore:
- "**"

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.ref_name != 'main' }}

jobs:
rust_changes:
name: Rust Changes
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.filter.outputs.changed }}
steps:
- uses: actions/checkout@v4

- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
changed:
- '.github/workflows/ci.yml'
- 'crates/**'
- 'Cargo.lock'
- 'Cargo.toml'
- 'rust-toolchain.toml'
# rust_check:
# name: Rust check
# needs: rust_changes
# if: ${{ needs.rust_changes.outputs.changed == 'true' }}
# runs-on: ${{ fromJSON(vars.LINUX_RUNNER_LABELS || '"ubuntu-latest"') }}
# steps:
# - uses: actions/checkout@v4

# - name: Pnpm Cache # Required by some tests
# uses: ./.github/actions/pnpm-cache

# - name: Clone Crates
# uses: ./.github/actions/clone-crates

# - name: Install Rust Toolchain
# uses: ./.github/actions/rustup
# with:
# clippy: true
# fmt: true
# shared-key: check

# - name: Run Cargo Check
# run: cargo check --workspace --all-targets # Not using --release because it uses too much cache, and is also slow.

rust_test:
name: Rust test
needs: rust_changes
if: ${{ needs.rust_changes.outputs.changed == 'true' }}
runs-on: ${{ fromJSON(vars.LINUX_RUNNER_LABELS || '"ubuntu-latest"') }}
steps:
- uses: actions/checkout@v4

- name: Pnpm Cache # Required by some tests
uses: ./.github/actions/pnpm-cache

- name: Clone Crates
uses: ./.github/actions/clone-crates

- name: Install Rust Toolchain
uses: ./.github/actions/rustup
with:
save-cache: ${{ github.ref_name == 'main' }}
shared-key: check

# Compile test without debug info for reducing the CI cache size
- name: Change profile.test
shell: bash
run: |
echo '[profile.test]' >> Cargo.toml
echo 'debug = false' >> Cargo.toml
- name: Run test
run: pnpm test
Loading

0 comments on commit fa4b270

Please sign in to comment.