Push halmos package #9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# based on https://docs.github.com/en/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions#upgrading-a-workflow-that-accesses-a-registry-using-a-personal-access-token | |
name: Push halmos package | |
on: | |
workflow_dispatch: | |
workflow_run: | |
workflows: ["Push halmos-builder package"] | |
types: | |
- completed | |
push: | |
paths: | |
- packages/halmos/**/* | |
- .github/workflows/publish-halmos-package.yml | |
tags: | |
# push when we release a new tagged version | |
- 'v*' | |
env: | |
IMAGE_NAME: halmos | |
jobs: | |
# This pushes the image to GitHub Packages. | |
push: | |
# if triggered by a workflow_run, only run if the previous workflow succeeded | |
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name != 'workflow_run' }} | |
runs-on: ubuntu-latest | |
permissions: | |
packages: write | |
contents: read | |
steps: | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- uses: actions/checkout@v4 | |
with: | |
# we may need tests/lib for the workflows using this image | |
submodules: recursive | |
- name: Build image | |
run: docker build . --file packages/halmos/Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" | |
- name: Print halmos version | |
run: docker run $IMAGE_NAME halmos --version | |
- name: Push image | |
run: | | |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME | |
# This changes all uppercase characters to lowercase. | |
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | |
# This strips the git ref prefix from the version. | |
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') | |
# This strips the "v" prefix from the tag name. | |
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') | |
# This uses the Docker `latest` tag convention. | |
[ "$VERSION" == "main" ] && VERSION=latest | |
echo IMAGE_ID=$IMAGE_ID | |
echo VERSION=$VERSION | |
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION | |
docker push $IMAGE_ID:$VERSION |