Skip to content

Commit

Permalink
Bootstrap toolchain (#2)
Browse files Browse the repository at this point in the history
- impl project Docker image
- impl CI pipeline
- provide `Makefile` for shotcuting basic operations

Co-authored-by: Kai Ren <tyranron@gmail.com>
  • Loading branch information
xDarksome and tyranron authored Jun 30, 2022
1 parent 1141d5b commit 29ad954
Show file tree
Hide file tree
Showing 14 changed files with 744 additions and 44 deletions.
14 changes: 14 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
*

# Sources and manifest.
!Cargo.toml
!Cargo.lock
!src/
!README.md

# Project sub-crates.
!api/s3/
!lib/

# E2E tests sources and manifest.
!e2e/Cargo.toml
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2
updates:
- package-ecosystem: cargo
directory: /
schedule:
interval: weekly

- package-ecosystem: github-actions
directory: /
schedule:
interval: daily
283 changes: 283 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,283 @@
name: CI

on:
push:
branches: ["main"]
tags: ["v*"]
pull_request:
branches: ["main"]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
CACHE: ${{ (github.event_name == 'push'
|| github.event_name == 'pull_request')
&& github.ref != 'refs/heads/main'
&& !startsWith(github.ref, 'refs/tags/v')
&& !contains(github.event.head_commit.message, '[fresh ci]') }}
RUST_BACKTRACE: 1
RUST_VER: "1.61"

jobs:

################
# Pull Request #
################

pr:
if: ${{ github.event_name == 'pull_request' }}
needs:
- clippy
- docker
- rustdoc
- rustfmt
- test-e2e
- test-unit
runs-on: ubuntu-latest
steps:
- run: true




##########################
# Linting and formatting #
##########################

clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ env.RUST_VER }}
override: true
components: clippy
- uses: Swatinem/rust-cache@v1
if: ${{ env.CACHE == 'true' }}

- run: make cargo.lint

rustfmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
components: rustfmt

- run: make cargo.fmt check=yes




###########
# Testing #
###########

test-e2e:
name: E2E tests
needs: ["docker"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ env.RUST_VER }}
override: true
- uses: Swatinem/rust-cache@v1
if: ${{ env.CACHE == 'true' }}
- uses: satackey/action-docker-layer-caching@v0.0.11
with:
key: test-e2e-{hash}
restore-keys: test-e2e-
continue-on-error: true
timeout-minutes: 10
if: ${{ env.CACHE == 'true' }}

- uses: actions/download-artifact@v3
with:
name: docker-${{ github.run_number }}
path: .cache/docker/
- run: make docker.untar

- run: make test.e2e start-app=yes dockerized=yes
tag=build-${{ github.run_number }}

test-unit:
name: Unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ env.RUST_VER }}
override: true
- uses: Swatinem/rust-cache@v1
if: ${{ env.CACHE == 'true' }}

- run: make test.unit




############
# Building #
############

docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: docker/setup-buildx-action@v2

- run: make docker.image debug=no no-cache=yes
tag=build-${{ github.run_number }}

- run: make docker.tar
tags=build-${{ github.run_number }}
- uses: actions/upload-artifact@v3
with:
name: docker-${{ github.run_number }}
path: .cache/docker/image.tar
retention-days: 1

rustdoc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ env.RUST_VER }}
override: true
- uses: Swatinem/rust-cache@v1
if: ${{ env.CACHE == 'true' }}

- run: make cargo.doc private=yes open=no




#############
# Releasing #
#############

release-docker:
name: Release Docker image
needs: ["docker", "test-e2e"]
if: ${{ github.event_name == 'push'
&& (github.ref == 'refs/heads/main'
|| startsWith(github.ref, 'refs/tags/v')) }}
strategy:
fail-fast: false
matrix:
registry: ["docker.io", "ghcr.io", "quay.io"]
runs-on: ubuntu-latest
steps:
# Skip if this is fork and no credentials are provided.
- id: skip
run: echo ::set-output name=no::${{ !(
github.repository_owner != 'instrumentisto'
&& ((matrix.registry == 'quay.io'
&& secrets.QUAYIO_ROBOT_USER == '')
|| (matrix.registry == 'docker.io'
&& secrets.DOCKERHUB_BOT_USER == ''))
) }}

- uses: actions/checkout@v3
if: ${{ steps.skip.outputs.no == 'true' }}

- uses: actions/download-artifact@v3
with:
name: docker-${{ github.run_number }}
path: .cache/docker/
if: ${{ steps.skip.outputs.no == 'true' }}
- run: make docker.untar
if: ${{ steps.skip.outputs.no == 'true' }}

- name: Login to ${{ matrix.registry }} container registry
uses: docker/login-action@v2
with:
registry: ${{ matrix.registry }}
username: ${{ (matrix.registry == 'docker.io'
&& secrets.DOCKERHUB_BOT_USER)
|| (matrix.registry == 'quay.io'
&& secrets.QUAYIO_ROBOT_USER)
|| github.repository_owner }}
password: ${{ (matrix.registry == 'docker.io'
&& secrets.DOCKERHUB_BOT_PASS)
|| (matrix.registry == 'quay.io'
&& secrets.QUAYIO_ROBOT_TOKEN)
|| secrets.GITHUB_TOKEN }}
if: ${{ steps.skip.outputs.no == 'true' }}

- name: Parse semver versions from Git tag
id: semver
uses: actions-ecosystem/action-regex-match@v2
with:
text: ${{ github.ref }}
regex: '^refs/tags/v((([0-9]+)\.[0-9]+)\.[0-9]+(-.+)?)$'
if: ${{ steps.skip.outputs.no == 'true'
&& startsWith(github.ref, 'refs/tags/v') }}
- name: Form version Docker tags
id: tags
uses: actions/github-script@v6
with:
result-encoding: string
script: |
let versions = '${{ steps.semver.outputs.group1 }}';
if ('${{ steps.semver.outputs.group4 }}' === '') {
versions += ',${{ steps.semver.outputs.group2 }}';
if ('${{ steps.semver.outputs.group3 }}' !== '0') {
versions += ',${{ steps.semver.outputs.group3 }}';
}
versions += 'latest';
}
return versions;
if: ${{ steps.skip.outputs.no == 'true'
&& startsWith(github.ref, 'refs/tags/v') }}

- run: make docker.tags
registries=${{ matrix.registry }}
of=build-${{ github.run_number }}
tags=${{ (startsWith(github.ref, 'refs/tags/v')
&& steps.tags.outputs.result)
|| 'edge' }}
if: ${{ steps.skip.outputs.no == 'true' }}
- run: make docker.push
registries=${{ matrix.registry }}
tags=${{ (startsWith(github.ref, 'refs/tags/v')
&& steps.tags.outputs.result)
|| 'edge' }}
if: ${{ steps.skip.outputs.no == 'true' }}

# On GitHub Container Registry README is automatically updated on pushes.
- name: Update README on Docker Hub
uses: christian-korneck/update-container-description-action@v1
with:
provider: dockerhub
destination_container_repo: ${{ github.repository }}
readme_file: README.md
env:
DOCKER_USER: ${{ secrets.DOCKERHUB_BOT_USER }}
DOCKER_PASS: ${{ secrets.DOCKERHUB_BOT_PASS }}
if: ${{ steps.skip.outputs.no == 'true'
&& matrix.registry == 'docker.io' }}
- name: Update README on Quay.io
uses: christian-korneck/update-container-description-action@v1
with:
provider: quay
destination_container_repo: ${{ matrix.registry }}/${{ github.repository }}
readme_file: README.md
env:
DOCKER_APIKEY: ${{ secrets.QUAYIO_API_TOKEN }}
if: ${{ steps.skip.outputs.no == 'true'
&& matrix.registry == 'quay.io' }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/*.iml
.DS_Store

/.cache/
/target/
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 29ad954

Please sign in to comment.