Skip to content

Commit 511db75

Browse files
Merge pull request #122 from forefireAPI/dev-ci
[Docker ci] Update to push to GithubRegistry + run the test script #118
2 parents 5c6af38 + efdcee9 commit 511db75

1 file changed

Lines changed: 40 additions & 15 deletions

File tree

.github/workflows/docker.yml

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,58 @@
1-
name: Docker
1+
name: Build, Test, and Push Docker Image
22

33
on:
44
push:
5-
branches:
6-
- "master"
7-
- "dev-ci"
5+
branches: [ "master" ]
6+
tags: [ 'v*.*.*' ] # Trigger on semver tags
87
pull_request:
98
branches: [ "master" ]
10-
119
workflow_dispatch:
1210

11+
env:
12+
REGISTRY: ghcr.io
13+
IMAGE_NAME: ${{ github.repository }}
14+
1315
jobs:
14-
docker:
16+
build-test-and-push:
1517
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
20+
packages: write
21+
1622
steps:
1723
- name: Checkout repository
1824
uses: actions/checkout@v4
1925
with:
2026
lfs: true
2127

22-
- name: Set up Docker Buildx
23-
uses: docker/setup-buildx-action@v3
28+
- name: Log in to GitHub Container Registry
29+
uses: docker/login-action@v3
30+
with:
31+
registry: ${{ env.REGISTRY }}
32+
username: ${{ github.actor }}
33+
password: ${{ secrets.GITHUB_TOKEN }}
2434

25-
- name: Build Docker Image
26-
run: docker build -t forefire:latest .
35+
- name: Extract Docker metadata
36+
id: meta
37+
uses: docker/metadata-action@v5
38+
with:
39+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
40+
tags: |
41+
type=semver,pattern={{version}}
2742
28-
- name: Check ForeFire version inside Docker
29-
run: |
30-
docker run --rm forefire:latest forefire -v
43+
- name: Build and push Docker image
44+
id: build-and-push
45+
uses: docker/build-push-action@v5
46+
with:
47+
context: .
48+
# Only push if the ref starts with 'refs/tags/'
49+
push: ${{ startsWith(github.ref, 'refs/tags/') }}
50+
tags: ${{ steps.meta.outputs.tags }}
51+
labels: ${{ steps.meta.outputs.labels }}
52+
load: true
3153

32-
- name: Run 'runff' Test Script inside Docker
33-
run: docker run --rm forefire:latest bash -c "cd tests/runff && bash ff-run.bash"
54+
- name: Run 'runff' Test Script on the built image
55+
run: |
56+
TEST_TAG=$(echo "${{ steps.meta.outputs.tags }}" | head -n 1)
57+
echo "Testing image with tag: $TEST_TAG"
58+
docker run --rm $TEST_TAG bash -c "cd tests/runff && bash ff-run.bash"

0 commit comments

Comments
 (0)