Skip to content

Commit d5d5393

Browse files
committed
Set up Continuous Integration
For pull requests, we try to build the container. This also runs unit tests due to how the Dockerfile is set up. GitHub will display the build status on its review page for the pull request. If the build (and tests that are run as part of the build) succeeded, the icon is green. If it failed, the icon is red. For changes to the main branch, we build the container and push it to the GitHub container registry. Once this change is part of the main repo and GitHub had a chance to run the corresponding workflow for the first time, users can use one of the following commands to fetch the latest container, depending on whether they prefer docker (which needs installation of proprietary software) or podman (which is open source): ```sh $ docker pull ghcr.io/bdon/osmexpress:latest $ podman pull ghcr.io/bdon/osmexpress:latest ``` The full list of `osmexpress` containers will be available from [this page](https://github.com/bdon/OSMExpress/pkgs/container/osmexpress).
1 parent 55488b1 commit d5d5393

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Build and push container image
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
release:
9+
types: [published]
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Check out repository
16+
uses: actions/checkout@v4
17+
with:
18+
submodules: recursive
19+
20+
- name: Set up Podman
21+
run: |
22+
sudo apt-get update
23+
sudo apt-get install -y podman
24+
25+
- name: Log into the container registry
26+
if: github.event_name != 'pull_request'
27+
run: echo "${{ secrets.GITHUB_TOKEN }}" | podman login ghcr.io -u ${{ github.actor }} --password-stdin
28+
29+
- name: Build the container image
30+
run: |
31+
# Container image identifiers must be all-lowercase.
32+
# The two commas transform "User/OSMExpress" to "user/osmexpress".
33+
IMAGE_ID=ghcr.io/${GITHUB_REPOSITORY,,}
34+
SHA_TAG=${{ github.sha }}
35+
LATEST_TAG=latest
36+
37+
# Build the container image with SHA and latest tags.
38+
podman build -t ${IMAGE_ID}:${SHA_TAG} -t ${IMAGE_ID}:${LATEST_TAG} .
39+
40+
# If this is a release event, tag the image with the release tag.
41+
if [ "${{ github.event_name }}" = "release" ]; then
42+
RELEASE_TAG=${{ github.event.release.tag_name }}
43+
podman tag ${IMAGE_ID}:${SHA_TAG} ${IMAGE_ID}:${RELEASE_TAG}
44+
fi
45+
46+
- name: Push the container image to the registry
47+
if: github.event_name != 'pull_request'
48+
run: |
49+
IMAGE_ID=ghcr.io/${GITHUB_REPOSITORY,,}
50+
SHA_TAG=${{ github.sha }}
51+
LATEST_TAG=latest
52+
53+
# Push the container image with SHA and latest tags.
54+
podman push $IMAGE_ID:$SHA_TAG
55+
podman push $IMAGE_ID:$LATEST_TAG
56+
57+
# If this is a release event, push the image with the release tag.
58+
if [ "${{ github.event_name }}" = "release" ]; then
59+
RELEASE_TAG=${{ github.event.release.tag_name }}
60+
podman push $IMAGE_ID:$RELEASE_TAG
61+
fi

0 commit comments

Comments
 (0)