Run tests in GitHub Actions #96
Workflow file for this run
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
name: Build | |
on: | |
push: | |
branches: [ master ] | |
tags: | |
- 'v[0-9]+.[0-9]+.[0-9]+*' | |
pull_request: | |
branches: [ master ] | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-24.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install rye | |
uses: eifinger/setup-rye@d4c3ac7b15d8bf2e0b45e2d257c6b5cdbebc3643 # v4.2.1 | |
with: | |
version: '0.36.0' | |
enable-cache: true | |
cache-prefix: ${{ github.workflow }} | |
- name: Decide image tags | |
id: info | |
shell: python | |
run: | | |
import os | |
import itertools | |
registries = ['docker.io', 'ghcr.io'] | |
repos = ['${{ github.repository }}'.lower()] | |
if '${{ github.ref_type }}' == 'branch': | |
tags = ['latest'] | |
elif '${{ github.ref_type }}' == 'tag': | |
version = '${{ github.ref_name }}'[1:] | |
tags = ['latest', version] | |
else: | |
tags = [] | |
def join_tag(t): | |
registry, repo, tag = t | |
return f'{registry}/{repo}:{tag}' | |
product = itertools.product(registries, repos, tags) | |
tags_csv = ','.join(map(join_tag, product)) | |
push = 'true' if tags_csv else 'false' | |
with open(os.environ['GITHUB_OUTPUT'], 'a') as out: | |
out.write(f'tags={tags_csv}\n') | |
out.write(f'push={push}\n') | |
- name: Set version | |
run: | | |
if [ '${{ github.ref_type }}' = 'tag' ]; then | |
rye version '${{ github.ref_name }}' | |
else | |
commit='${{ github.sha }}' | |
rye version "0.0.0.dev1+commit.${commit:0:7}" | |
fi | |
rye version > src/chrisomatic/version.txt | |
- name: Build Python wheel | |
run: rye build --wheel --clean | |
- uses: docker/setup-buildx-action@v3 | |
- name: Login to DockerHub | |
if: github.event_name == 'push' | |
id: dockerhub_login | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Login to GitHub Container Registry | |
if: github.event_name == 'push' | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build image | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
platforms: linux/amd64,linux/ppc64le,linux/arm64 | |
tags: ${{ steps.info.outputs.tags }} | |
push: ${{ steps.info.outputs.push }} | |
- name: Update DockerHub description | |
uses: peter-evans/dockerhub-description@v4 | |
if: ${{ steps.info.outputs.push }} | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
short-description: ${{ github.event.repository.description }} |