GitHub Actions with Conditional Job Running Based on Commit Message (#266)

* .

* testing...

* testing ...

* [test] ...

* .

* ..

* testing

* [testing]

* testing

* [cli] this should only run cli

* [CLI] how about this

* [mysql] only

* [postgres] only

* [examples] only

* [issues] only

* [sqlite] only

* Run by default

* Always run example [cli]

* ...

* Run by default (again)

* Docs

* Remove unused

* ...

* [cli] [issues] only
This commit is contained in:
Billy Chan 2021-10-23 15:50:33 +08:00 committed by Chris Tsang
parent 183ed5faa3
commit 128352092d

View File

@ -1,3 +1,53 @@
# GitHub Actions with Conditional Job Running Based on Commit Message
#
# --------------------------------------------------------------------------------
#
# Following jobs will always run
#
# - `clippy`
# - `test`
# - `examples`
#
# Following jobs will be run when no keywords were found in commit message)
#
# - `compile-sqlite`
# - `sqlite`
# - `compile-mysql`
# - `mysql`
# - `mariadb`
# - `compile-postgres`
# - `postgres`
#
# Following jobs will be run if keywords `[issues]` were found in commit message
#
# - Jobs that will always run
# - `issues`
#
# Following jobs will be run if keywords `[cli]` were found in commit message
#
# - Jobs that will always run
# - `cli`
#
# Following jobs will be run if keywords `[sqlite]` were found in commit message
#
# - Jobs that will always run
# - `compile-sqlite`
# - `sqlite`
#
# Following jobs will be run if keywords `[mysql]` were found in commit message
#
# - Jobs that will always run
# - `compile-mysql`
# - `mysql`
# - `mariadb`
#
# Following jobs will be run if keywords `[postgres]` were found in commit message
#
# - Jobs that will always run
# - `compile-postgres`
# - `postgres`
name: tests name: tests
on: on:
@ -11,6 +61,32 @@ env:
CARGO_TERM_COLOR: always CARGO_TERM_COLOR: always
jobs: jobs:
init:
name: Init
runs-on: ubuntu-20.04
outputs:
run-sqlite: ${{ contains(steps.git-log.outputs.message, '[sqlite]') }}
run-mysql: ${{ contains(steps.git-log.outputs.message, '[mysql]') }}
run-postgres: ${{ contains(steps.git-log.outputs.message, '[postgres]') }}
run-cli: ${{ contains(steps.git-log.outputs.message, '[cli]') }}
run-issues: ${{ contains(steps.git-log.outputs.message, '[issues]') }}
run-partial: >-
${{
contains(steps.git-log.outputs.message, '[sqlite]') ||
contains(steps.git-log.outputs.message, '[mysql]') ||
contains(steps.git-log.outputs.message, '[postgres]') ||
contains(steps.git-log.outputs.message, '[cli]') ||
contains(steps.git-log.outputs.message, '[issues]')
}}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- id: git-log
run: echo "::set-output name=message::$(git log --no-merges -1 --oneline)"
clippy-fmt: clippy-fmt:
name: Clippy + Fmt name: Clippy + Fmt
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
@ -39,6 +115,12 @@ jobs:
compile-sqlite: compile-sqlite:
name: Compile SQLite name: Compile SQLite
needs: init
if: >-
${{
needs.init.outputs.run-partial == 'false' ||
(needs.init.outputs.run-partial == 'true' && needs.init.outputs.run-sqlite == 'true')
}}
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
strategy: strategy:
matrix: matrix:
@ -72,6 +154,12 @@ jobs:
compile-mysql: compile-mysql:
name: Compile MySQL name: Compile MySQL
needs: init
if: >-
${{
needs.init.outputs.run-partial == 'false' ||
(needs.init.outputs.run-partial == 'true' && needs.init.outputs.run-mysql == 'true')
}}
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
strategy: strategy:
matrix: matrix:
@ -105,6 +193,12 @@ jobs:
compile-postgres: compile-postgres:
name: Compile PostgreSQL name: Compile PostgreSQL
needs: init
if: >-
${{
needs.init.outputs.run-partial == 'false' ||
(needs.init.outputs.run-partial == 'true' && needs.init.outputs.run-postgres == 'true')
}}
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
strategy: strategy:
matrix: matrix:
@ -168,6 +262,8 @@ jobs:
cli: cli:
name: CLI name: CLI
needs: init
if: ${{ (needs.init.outputs.run-partial == 'true' && needs.init.outputs.run-cli == 'true') }}
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:
matrix: matrix:
@ -212,6 +308,8 @@ jobs:
issues: issues:
name: Issues name: Issues
needs: init
if: ${{ (needs.init.outputs.run-partial == 'true' && needs.init.outputs.run-issues == 'true') }}
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:
matrix: matrix:
@ -219,28 +317,20 @@ jobs:
path: [86, 249, 262] path: [86, 249, 262]
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
with:
fetch-depth: 0
- id: git-log - uses: actions-rs/toolchain@v1
run: echo "::set-output name=message::$(git log --no-merges -1 --oneline)"
- if: "contains(steps.git-log.outputs.message, '[issues]')"
uses: actions-rs/toolchain@v1
with: with:
profile: minimal profile: minimal
toolchain: stable toolchain: stable
override: true override: true
- if: "contains(steps.git-log.outputs.message, '[issues]')" - uses: actions-rs/cargo@v1
uses: actions-rs/cargo@v1
with: with:
command: build command: build
args: > args: >
--manifest-path issues/${{ matrix.path }}/Cargo.toml --manifest-path issues/${{ matrix.path }}/Cargo.toml
- if: "contains(steps.git-log.outputs.message, '[issues]')" - uses: actions-rs/cargo@v1
uses: actions-rs/cargo@v1
with: with:
command: test command: test
args: > args: >
@ -248,8 +338,15 @@ jobs:
sqlite: sqlite:
name: SQLite name: SQLite
needs:
- init
- compile-sqlite
if: >-
${{
needs.init.outputs.run-partial == 'false' ||
(needs.init.outputs.run-partial == 'true' && needs.init.outputs.run-sqlite == 'true')
}}
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
needs: compile-sqlite
env: env:
DATABASE_URL: "sqlite::memory:" DATABASE_URL: "sqlite::memory:"
strategy: strategy:
@ -283,8 +380,15 @@ jobs:
mysql: mysql:
name: MySQL name: MySQL
needs:
- init
- compile-mysql
if: >-
${{
needs.init.outputs.run-partial == 'false' ||
(needs.init.outputs.run-partial == 'true' && needs.init.outputs.run-mysql == 'true')
}}
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
needs: compile-mysql
env: env:
DATABASE_URL: "mysql://root:@localhost" DATABASE_URL: "mysql://root:@localhost"
strategy: strategy:
@ -336,8 +440,15 @@ jobs:
mariadb: mariadb:
name: MariaDB name: MariaDB
needs:
- init
- compile-mysql
if: >-
${{
needs.init.outputs.run-partial == 'false' ||
(needs.init.outputs.run-partial == 'true' && needs.init.outputs.run-mysql == 'true')
}}
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
needs: compile-mysql
env: env:
DATABASE_URL: "mysql://root:@localhost" DATABASE_URL: "mysql://root:@localhost"
strategy: strategy:
@ -389,8 +500,15 @@ jobs:
postgres: postgres:
name: Postgres name: Postgres
needs:
- init
- compile-postgres
if: >-
${{
needs.init.outputs.run-partial == 'false' ||
(needs.init.outputs.run-partial == 'true' && needs.init.outputs.run-postgres == 'true')
}}
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
needs: compile-postgres
env: env:
DATABASE_URL: "postgres://root:root@localhost" DATABASE_URL: "postgres://root:root@localhost"
strategy: strategy: