mirror of
https://github.com/element-hq/matrix-authentication-service.git
synced 2026-05-30 11:14:45 +00:00
351 lines
9.1 KiB
YAML
351 lines
9.1 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
pull_request:
|
|
branches: [ main ]
|
|
|
|
env:
|
|
CARGO_TERM_COLOR: always
|
|
|
|
jobs:
|
|
fetch-linux:
|
|
name: Fetch Cargo dependencies (Linux)
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout the code
|
|
uses: actions/checkout@v2
|
|
|
|
- name: Install toolchain
|
|
uses: actions-rs/toolchain@v1
|
|
with:
|
|
toolchain: "1.54.0" # MSRV
|
|
target: x86_64-unknown-linux-musl
|
|
profile: minimal
|
|
override: true
|
|
|
|
- name: Setup Cargo cache
|
|
uses: actions/cache@v2.1.6
|
|
with:
|
|
path: |
|
|
~/.cargo/registry/index
|
|
~/.cargo/registry/cache
|
|
~/.cargo/git/db
|
|
key: cargo-deps-msrv-${{ hashFiles('**/Cargo.lock') }}-${{ runner.os }}
|
|
|
|
- name: Fetch dependencies
|
|
id: fetch
|
|
uses: actions-rs/cargo@v1
|
|
continue-on-error: true
|
|
with:
|
|
command: fetch
|
|
args: --locked
|
|
|
|
- name: Fetch dependencies (retry)
|
|
id: fetch-2
|
|
uses: actions-rs/cargo@v1
|
|
if: steps.fetch.outcome == 'failure'
|
|
continue-on-error: true
|
|
with:
|
|
command: fetch
|
|
args: --locked
|
|
|
|
- name: Fetch dependencies (second retry)
|
|
uses: actions-rs/cargo@v1
|
|
if: steps.fetch.outcome == 'failure' && steps.fetch-2.outcome == 'failure'
|
|
with:
|
|
command: fetch
|
|
args: --locked
|
|
|
|
fetch-macos:
|
|
name: Fetch Cargo dependencies (macOS)
|
|
runs-on: macos-latest
|
|
|
|
steps:
|
|
- name: Checkout the code
|
|
uses: actions/checkout@v2
|
|
|
|
- name: Install toolchain
|
|
uses: actions-rs/toolchain@v1
|
|
with:
|
|
toolchain: "1.54.0" # MSRV
|
|
target: x86_64-apple-darwin
|
|
profile: minimal
|
|
override: true
|
|
|
|
- name: Setup Cargo cache
|
|
uses: actions/cache@v2.1.6
|
|
with:
|
|
path: |
|
|
~/.cargo/registry/index
|
|
~/.cargo/registry/cache
|
|
~/.cargo/git/db
|
|
key: cargo-deps-msrv-${{ hashFiles('**/Cargo.lock') }}-${{ runner.os }}
|
|
|
|
- name: Fetch dependencies
|
|
id: fetch
|
|
uses: actions-rs/cargo@v1
|
|
continue-on-error: true
|
|
with:
|
|
command: fetch
|
|
args: --locked
|
|
|
|
- name: Fetch dependencies (retry)
|
|
id: fetch-2
|
|
uses: actions-rs/cargo@v1
|
|
if: steps.fetch.outcome == 'failure'
|
|
continue-on-error: true
|
|
with:
|
|
command: fetch
|
|
args: --locked
|
|
|
|
- name: Fetch dependencies (second retry)
|
|
uses: actions-rs/cargo@v1
|
|
if: steps.fetch.outcome == 'failure' && steps.fetch-2.outcome == 'failure'
|
|
with:
|
|
command: fetch
|
|
args: --locked
|
|
|
|
fetch-windows:
|
|
name: Fetch Cargo dependencies (Windows)
|
|
runs-on: windows-latest
|
|
|
|
steps:
|
|
- name: Checkout the code
|
|
uses: actions/checkout@v2
|
|
|
|
- name: Install toolchain
|
|
uses: actions-rs/toolchain@v1
|
|
with:
|
|
toolchain: "1.54.0" # MSRV
|
|
target: x86_64-pc-windows-msvc
|
|
profile: minimal
|
|
override: true
|
|
|
|
- name: Setup Cargo cache
|
|
uses: actions/cache@v2.1.6
|
|
with:
|
|
path: |
|
|
~/.cargo/registry/index
|
|
~/.cargo/registry/cache
|
|
~/.cargo/git/db
|
|
key: cargo-deps-msrv-${{ hashFiles('**/Cargo.lock') }}-${{ runner.os }}
|
|
|
|
- name: Fetch dependencies
|
|
id: fetch
|
|
uses: actions-rs/cargo@v1
|
|
continue-on-error: true
|
|
with:
|
|
command: fetch
|
|
args: --locked
|
|
|
|
- name: Fetch dependencies (retry)
|
|
id: fetch-2
|
|
uses: actions-rs/cargo@v1
|
|
if: steps.fetch.outcome == 'failure'
|
|
continue-on-error: true
|
|
with:
|
|
command: fetch
|
|
args: --locked
|
|
|
|
- name: Fetch dependencies (second retry)
|
|
uses: actions-rs/cargo@v1
|
|
if: steps.fetch.outcome == 'failure' && steps.fetch-2.outcome == 'failure'
|
|
with:
|
|
command: fetch
|
|
args: --locked
|
|
|
|
|
|
rustfmt:
|
|
name: Check style
|
|
needs: [fetch-linux]
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout the code
|
|
uses: actions/checkout@v2
|
|
|
|
- name: Install toolchain
|
|
id: toolchain
|
|
uses: actions-rs/toolchain@v1
|
|
with:
|
|
toolchain: nightly
|
|
components: rustfmt
|
|
profile: minimal
|
|
override: true
|
|
|
|
- name: Setup Cargo cache
|
|
uses: actions/cache@v2.1.6
|
|
with:
|
|
path: |
|
|
~/.cargo/registry/index
|
|
~/.cargo/registry/cache
|
|
~/.cargo/git/db
|
|
key: cargo-deps-msrv-${{ hashFiles('**/Cargo.lock') }}-${{ runner.os }}
|
|
|
|
- name: Setup build cache
|
|
uses: actions/cache@v2.1.6
|
|
with:
|
|
path: |
|
|
target
|
|
key: cargo-fmt-${{ hashFiles('**/Cargo.lock') }}-${{ steps.toolchain.outputs.rustc_hash }}
|
|
|
|
- name: Check style
|
|
uses: actions-rs/cargo@v1
|
|
with:
|
|
command: fmt
|
|
args: --all -- --check
|
|
|
|
|
|
clippy:
|
|
name: Run Clippy
|
|
needs: [fetch-linux]
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout the code
|
|
uses: actions/checkout@v2
|
|
|
|
- name: Install toolchain
|
|
id: toolchain
|
|
uses: actions-rs/toolchain@v1
|
|
with:
|
|
toolchain: stable
|
|
components: clippy
|
|
profile: minimal
|
|
override: true
|
|
|
|
- name: Setup Cargo cache
|
|
uses: actions/cache@v2.1.6
|
|
with:
|
|
path: |
|
|
~/.cargo/registry/index
|
|
~/.cargo/registry/cache
|
|
~/.cargo/git/db
|
|
key: cargo-deps-msrv-${{ hashFiles('**/Cargo.lock') }}-${{ runner.os }}
|
|
|
|
- name: Setup build cache
|
|
uses: actions/cache@v2.1.6
|
|
with:
|
|
path: |
|
|
target
|
|
key: cargo-clippy-${{ hashFiles('**/Cargo.lock') }}-${{ steps.toolchain.outputs.rustc_hash }}
|
|
|
|
- name: Run Clippy
|
|
uses: actions-rs/clippy-check@v1
|
|
with:
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
|
|
test:
|
|
name: Run test suite on ${{ matrix.os.name }} / ${{ matrix.toolchain }}
|
|
needs: [rustfmt, clippy, fetch-linux, fetch-macos, fetch-windows]
|
|
runs-on: ${{ matrix.os.runner }}
|
|
|
|
continue-on-error: "${{ matrix.toolchain == 'beta' || matrix.toolchain == 'nightly' }}"
|
|
|
|
strategy:
|
|
fail-fast: false # Continue other jobs if one fails to help filling the cache
|
|
matrix:
|
|
os:
|
|
- name: "macOS"
|
|
runner: "macos-latest"
|
|
target: "x86_64-apple-darwin"
|
|
- name: "Windows"
|
|
runner: "windows-latest"
|
|
target: "x86_64-pc-windows-msvc"
|
|
- name: "Linux"
|
|
runner: "ubuntu-latest"
|
|
target: "x86_64-unknown-linux-musl"
|
|
|
|
toolchain:
|
|
- "1.54.0" # MSRV
|
|
- stable
|
|
- beta
|
|
- nightly
|
|
|
|
steps:
|
|
- name: Checkout the code
|
|
uses: actions/checkout@v2
|
|
|
|
- name: Install toolchain
|
|
id: toolchain
|
|
uses: actions-rs/toolchain@v1
|
|
with:
|
|
toolchain: ${{ matrix.toolchain }}
|
|
target: ${{ matrix.os.target }}
|
|
profile: minimal
|
|
override: true
|
|
|
|
- name: Setup Cargo cache
|
|
uses: actions/cache@v2.1.6
|
|
with:
|
|
path: |
|
|
~/.cargo/registry/index
|
|
~/.cargo/registry/cache
|
|
~/.cargo/git/db
|
|
key: cargo-deps-msrv-${{ hashFiles('**/Cargo.lock') }}-${{ runner.os }}
|
|
|
|
- name: Setup build cache
|
|
uses: actions/cache@v2.1.6
|
|
with:
|
|
path: |
|
|
target
|
|
key: cargo-build-${{ hashFiles('**/Cargo.lock') }}-${{ matrix.os.target }}-${{ steps.toolchain.outputs.rustc_hash }}
|
|
|
|
- name: Build
|
|
uses: actions-rs/cargo@v1
|
|
with:
|
|
command: build
|
|
args: --offline
|
|
|
|
- name: Test
|
|
uses: actions-rs/cargo@v1
|
|
with:
|
|
command: test
|
|
args: --offline
|
|
|
|
build-image:
|
|
name: Build and push Docker image
|
|
needs: [rustfmt, clippy]
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout the code
|
|
uses: actions/checkout@v2
|
|
|
|
- name: Docker meta
|
|
id: meta
|
|
uses: docker/metadata-action@v3
|
|
with:
|
|
images: ghcr.io/matrix-org/matrix-authentication-service
|
|
tags: |
|
|
type=ref,event=branch
|
|
type=ref,event=pr
|
|
type=semver,pattern={{version}}
|
|
type=semver,pattern={{major}}.{{minor}}
|
|
type=semver,pattern={{major}}
|
|
type=sha
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v1
|
|
|
|
- name: Login to GitHub Container Registry
|
|
if: github.event_name != 'pull_request'
|
|
uses: docker/login-action@v1
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.repository_owner }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v2
|
|
with:
|
|
context: .
|
|
push: ${{ github.event_name != 'pull_request' }}
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|