Skip to content

Commit 9741d1e

Browse files
authored
Merge pull request #1 from codewars/improve-github-action
2 parents b6a7df1 + 66f14ff commit 9741d1e

File tree

5 files changed

+88
-30
lines changed

5 files changed

+88
-30
lines changed

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.github/
2+
bin/
3+
examples/

.github/workflows/ci.yml

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,48 @@ name: CI
22

33
on:
44
push:
5-
branches: [ "main" ]
5+
branches:
6+
- main
67
pull_request:
7-
branches: [ "main" ]
8-
9-
env:
10-
IMAGE_NAME: ${{ github.event.repository.name }}
118

129
jobs:
13-
build-and-push-image:
10+
build_and_test:
1411
runs-on: ubuntu-latest
12+
if: ${{ github.repository == 'codewars/riscv' }}
1513
permissions:
1614
contents: read
1715
packages: write
1816
steps:
1917
- uses: actions/checkout@v3
2018

21-
- name: Enable QEMU user-mode emulation
22-
run: sudo apt-get update && sudo apt-get install -y qemu-user-static
19+
- name: Set up QEMU
20+
uses: docker/setup-qemu-action@v2
21+
with:
22+
platforms: riscv64
23+
24+
- name: Set up Docker Buildx
25+
uses: docker/setup-buildx-action@v2
2326

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

2739
- name: Run multiply example
28-
run: IMAGE_TAG=$IMAGE_NAME bin/run multiply
40+
run: bin/run multiply
2941

3042
- name: Run multiply-failing example
31-
run: IMAGE_TAG=$IMAGE_NAME bin/run multiply-failing
43+
run: bin/run multiply-failing
3244

3345
- name: Run syntax-error example
34-
run: IMAGE_TAG=$IMAGE_NAME bin/run syntax-error || true
46+
run: bin/run syntax-error || true
3547

3648
- name: Run invalid-regname example
37-
run: IMAGE_TAG=$IMAGE_NAME bin/run invalid-regname || true
38-
39-
- name: Log in to registry
40-
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
41-
42-
- name: Push image
43-
run: |
44-
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
45-
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
46-
docker tag $IMAGE_NAME $IMAGE_ID:latest
47-
docker push $IMAGE_ID:latest
49+
run: bin/run invalid-regname || true

.github/workflows/push-image.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Build and push a Docker image to GitHub Container Registry when
2+
# a new tag is pushed.
3+
name: Push Image
4+
5+
on:
6+
push:
7+
tags:
8+
- "*"
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
if: ${{ github.repository == 'codewars/riscv' }}
14+
permissions:
15+
contents: read
16+
packages: write
17+
steps:
18+
- uses: actions/checkout@v3
19+
20+
- name: Set up QEMU
21+
uses: docker/setup-qemu-action@v2
22+
with:
23+
platforms: riscv64
24+
25+
- name: Set up Docker Buildx
26+
uses: docker/setup-buildx-action@v2
27+
28+
- name: Login to GitHub Container Registry
29+
uses: docker/login-action@v2
30+
with:
31+
registry: ghcr.io
32+
username: codewars
33+
password: ${{ secrets.GITHUB_TOKEN }}
34+
35+
- name: Build and push image
36+
uses: docker/build-push-action@v3
37+
with:
38+
context: .
39+
push: true
40+
platforms: linux/riscv64
41+
tags: |
42+
ghcr.io/codewars/riscv:latest
43+
ghcr.io/codewars/riscv:${{ github.ref_name }}
44+
cache-from: type=gha
45+
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
1-
FROM docker.io/library/ubuntu:jammy
1+
FROM docker.io/library/ubuntu:22.04
22

33
RUN set -ex; \
44
apt-get update; \
5-
apt-get install -y --no-install-recommends gcc g++ make cmake \
6-
wget ca-certificates;
7-
8-
WORKDIR /tmp
5+
apt-get install -y --no-install-recommends \
6+
gcc \
7+
g++ \
8+
make \
9+
cmake \
10+
wget \
11+
ca-certificates \
12+
; \
13+
apt-get autoremove -y; \
14+
apt-get clean; \
15+
rm -rf /var/lib/apt/lists/*;
916

1017
RUN set -ex; \
18+
cd /tmp; \
1119
wget https://github.com/cgreen-devs/cgreen/archive/refs/tags/1.6.0.tar.gz; \
1220
tar xvf 1.6.0.tar.gz; \
1321
rm -vf 1.6.0.tar.gz; \
1422
cd cgreen-1.6.0; \
1523
make; \
1624
make install; \
17-
cd; \
25+
cd ..; \
1826
rm -rvf /tmp/cgreen-1.6.0;
1927

2028
ENV LD_LIBRARY_PATH=/usr/local/lib

bin/run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if [ -z "${CONTAINER_ENGINE:+x}" ]; then
66
fi
77

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

1212
W=/workspace

0 commit comments

Comments
 (0)