Skip to content

Commit 715994f

Browse files
committed
Add GitHub Actions workflow to build and push Docker image to GHCR
1 parent 9d81062 commit 715994f

3 files changed

Lines changed: 67 additions & 1 deletion

File tree

‎.dockerignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.git
2+
.gitignore
3+
README.md
4+
LICENSE

‎.github/workflows/build-push.yml‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Build and push Docker image
2+
3+
on:
4+
push:
5+
branches: [ main, master ]
6+
tags: [ 'v*' ]
7+
pull_request:
8+
branches: [ main, master ]
9+
schedule:
10+
- cron: '0 0 * * 0' # Weekly
11+
12+
jobs:
13+
build-push:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
packages: write
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v3
21+
22+
- name: Set up Docker Buildx
23+
uses: docker/setup-buildx-action@v2
24+
25+
- name: Log in to GHCR
26+
if: github.event_name != 'pull_request'
27+
uses: docker/login-action@v2
28+
with:
29+
registry: ghcr.io
30+
username: ${{ github.actor }}
31+
password: ${{ secrets.GITHUB_TOKEN }}
32+
33+
- name: Extract metadata
34+
id: meta
35+
uses: docker/metadata-action@v4
36+
with:
37+
images: ghcr.io/tg9541/docker-sdcc
38+
tags: |
39+
type=ref,event=branch
40+
type=ref,event=pr
41+
type=semver,pattern={{version}}
42+
type=semver,pattern={{major}}.{{minor}}
43+
type=semver,pattern={{major}}
44+
type=sha,prefix={{branch}}-
45+
type=raw,value=3.9.0,enable={{is_default_branch}}
46+
47+
- name: Build and push
48+
uses: docker/build-push-action@v4
49+
with:
50+
context: .
51+
push: ${{ github.event_name != 'pull_request' }}
52+
tags: ghcr.io/tg9541/docker-sdcc:3.9.0
53+
labels: ${{ steps.meta.outputs.labels }}
54+
cache-from: type=gha
55+
cache-to: type=gha,mode=max

‎README.md‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,25 @@ This repository contains all that's needed for building and testing TG9541/STM8E
77
* telnet for debugging STM8 code with uCsim
88

99
The corresponding Docker Hub repository is [tg9541/docker-sdcc](https://hub.docker.com/r/tg9541/docker-sdcc/builds/).
10+
The GitHub Container Registry image is [ghcr.io/tg9541/docker-sdcc](https://github.com/TG9541/docker-sdcc/pkgs/container/docker-sdcc).
1011

1112
To build it run:
1213
```
1314
docker build -t docker-sdcc .
1415
```
1516

16-
To publish it run:
17+
To publish to Docker Hub:
1718
```
1819
docker tag docker-sdcc <DockerId>/docker-sdcc
1920
docker push <DockerId>/docker-sdcc
2021
```
2122

23+
To publish to GitHub Container Registry:
24+
```
25+
docker tag docker-sdcc ghcr.io/tg9541/docker-sdcc:3.9.0
26+
docker push ghcr.io/tg9541/docker-sdcc:3.9.0
27+
```
28+
2229
The following builds the W1209 binary, runs it in uCsim, compiles the code in W1209/board.fs, and dumps the Flash memory to out/W1209/W1209-forth.ihx:
2330
```
2431
docker run -ti -v `pwd`:/home docker-sdcc /bin/sh -c "cd /home && make BOARD=W1209 forth"

0 commit comments

Comments
 (0)