Skip to content

Commit

Permalink
Merge pull request #1 from codewars/improve-github-action
Browse files Browse the repository at this point in the history
  • Loading branch information
kazk authored Aug 2, 2022
2 parents b6a7df1 + 66f14ff commit 9741d1e
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 30 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.github/
bin/
examples/
48 changes: 25 additions & 23 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,48 @@ name: CI

on:
push:
branches: [ "main" ]
branches:
- main
pull_request:
branches: [ "main" ]

env:
IMAGE_NAME: ${{ github.event.repository.name }}

jobs:
build-and-push-image:
build_and_test:
runs-on: ubuntu-latest
if: ${{ github.repository == 'codewars/riscv' }}
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v3

- name: Enable QEMU user-mode emulation
run: sudo apt-get update && sudo apt-get install -y qemu-user-static
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: riscv64

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" --platform linux/riscv64
uses: docker/build-push-action@v3
with:
context: .
push: false
# Make the image available in next step
load: true
platforms: linux/riscv64
tags: ghcr.io/codewars/riscv:latest
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Run multiply example
run: IMAGE_TAG=$IMAGE_NAME bin/run multiply
run: bin/run multiply

- name: Run multiply-failing example
run: IMAGE_TAG=$IMAGE_NAME bin/run multiply-failing
run: bin/run multiply-failing

- name: Run syntax-error example
run: IMAGE_TAG=$IMAGE_NAME bin/run syntax-error || true
run: bin/run syntax-error || true

- name: Run invalid-regname example
run: IMAGE_TAG=$IMAGE_NAME bin/run invalid-regname || true

- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin

- name: Push image
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
docker tag $IMAGE_NAME $IMAGE_ID:latest
docker push $IMAGE_ID:latest
run: bin/run invalid-regname || true
45 changes: 45 additions & 0 deletions .github/workflows/push-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Build and push a Docker image to GitHub Container Registry when
# a new tag is pushed.
name: Push Image

on:
push:
tags:
- "*"

jobs:
test:
runs-on: ubuntu-latest
if: ${{ github.repository == 'codewars/riscv' }}
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: riscv64

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: codewars
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push image
uses: docker/build-push-action@v3
with:
context: .
push: true
platforms: linux/riscv64
tags: |
ghcr.io/codewars/riscv:latest
ghcr.io/codewars/riscv:${{ github.ref_name }}
cache-from: type=gha
cache-to: type=gha,mode=max
20 changes: 14 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
FROM docker.io/library/ubuntu:jammy
FROM docker.io/library/ubuntu:22.04

RUN set -ex; \
apt-get update; \
apt-get install -y --no-install-recommends gcc g++ make cmake \
wget ca-certificates;

WORKDIR /tmp
apt-get install -y --no-install-recommends \
gcc \
g++ \
make \
cmake \
wget \
ca-certificates \
; \
apt-get autoremove -y; \
apt-get clean; \
rm -rf /var/lib/apt/lists/*;

RUN set -ex; \
cd /tmp; \
wget https://github.com/cgreen-devs/cgreen/archive/refs/tags/1.6.0.tar.gz; \
tar xvf 1.6.0.tar.gz; \
rm -vf 1.6.0.tar.gz; \
cd cgreen-1.6.0; \
make; \
make install; \
cd; \
cd ..; \
rm -rvf /tmp/cgreen-1.6.0;

ENV LD_LIBRARY_PATH=/usr/local/lib
Expand Down
2 changes: 1 addition & 1 deletion bin/run
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if [ -z "${CONTAINER_ENGINE:+x}" ]; then
fi

if [ -z "${IMAGE_TAG:+x}" ]; then
IMAGE_TAG=ghcr.io/codewars/riscv64:latest
IMAGE_TAG=ghcr.io/codewars/riscv:latest
fi

W=/workspace
Expand Down

0 comments on commit 9741d1e

Please sign in to comment.