|
| 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