浏览代码

Add GitHub Actions CI rules (#70)

* Prepare Dockerfile for GitHub Actions

* Add Action

* Add CI rules

* Move docker files into the docker directory to prevent fetching build artifacts

* Cache Docker layers

Co-authored-by: aanper <mail@s3f.ru>
Vadim Kaushan 5 年之前
父节点
当前提交
a008c38078
共有 5 个文件被更改,包括 60 次插入3 次删除
  1. 11 0
      .github/actions/docker/action.yml
  2. 29 0
      .github/workflows/ci.yml
  3. 1 1
      docker-compose.yml
  4. 2 2
      docker/Dockerfile
  5. 17 0
      docker/entrypoint.sh

+ 11 - 0
.github/actions/docker/action.yml

@@ -0,0 +1,11 @@
+name: 'Run in docker'
+inputs:
+  run:  # id of input
+    description: 'A command to run'
+    required: true
+    default: ''
+runs:
+  using: 'docker'
+  image: '../../../docker/Dockerfile'
+  args:
+    - ${{ inputs.run }}

+ 29 - 0
.github/workflows/ci.yml

@@ -0,0 +1,29 @@
+name: 'CI'
+
+on:
+  push:
+    branches: [ master ]
+  pull_request:
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    steps:
+      - name: Checkout code
+        uses: actions/checkout@v2
+
+      - name: Cache Docker layers
+        uses: satackey/action-docker-layer-caching@v0.0.8
+
+      - name: Build docker image
+        uses: ./.github/actions/docker
+
+      - name: Build target_lo in docker
+        uses: ./.github/actions/docker
+        with:
+          run: make -C target_lo
+
+      - name: Build target_f1 in docker
+        uses: ./.github/actions/docker
+        with:
+          run: make -C target_f1

+ 1 - 1
docker-compose.yml

@@ -1,7 +1,7 @@
 version: '3'
 services:
   dev:
-    build: .
+    build: docker
     network_mode: "host"
     privileged: true
     tty: true

+ 2 - 2
Dockerfile → docker/Dockerfile

@@ -22,5 +22,5 @@ RUN apt-get update && \
 
 RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --profile=minimal --target thumbv7em-none-eabi thumbv7em-none-eabihf
 
-ENV PATH="/root/.cargo/bin:${PATH}"
-ENV USER=root
+COPY entrypoint.sh /entrypoint.sh
+ENTRYPOINT ["/entrypoint.sh"]

+ 17 - 0
docker/entrypoint.sh

@@ -0,0 +1,17 @@
+#!/bin/bash
+
+# A hack for GitHub Actions to not install Rust twice
+if [ "$HOME" != "/root" ]; then
+    ln -sf /root/.rustup "$HOME/.rustup"
+    ln -sf /root/.cargo "$HOME/.cargo"
+fi
+
+PATH="$HOME/.cargo/bin:${PATH}"
+
+if [ -z "$1" ]; then
+    bash
+else
+    echo "Running $1"
+    set -ex
+    bash -c "$1"
+fi