Build and publish #25
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 and publish | |
on: | |
workflow_dispatch: | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
variables: | |
name: Set environment variables | |
runs-on: ubuntu-latest | |
container: | |
image: python:3.12-alpine | |
outputs: | |
version: "${{ env.VERSION }}" | |
version-major: "${{ env.VERSION_MAJOR }}" | |
version-minor: "${{ env.VERSION_MINOR }}" | |
timeout-minutes: 5 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Install poetry | |
run: pip install poetry==${{ vars.POETRY_VERSION }} | |
- name: Save version to environment | |
run: | | |
VERSION=$(poetry version -s) | |
VERSION="${VERSION#[vV]}" | |
VERSION_MAJOR="${VERSION%%\.*}" | |
VERSION_MINOR="${VERSION#*.}" | |
VERSION_MINOR="${VERSION_MINOR%.*}" | |
echo "VERSION=$VERSION" >> "$GITHUB_ENV" | |
echo "VERSION_MAJOR=$VERSION_MAJOR" >> "$GITHUB_ENV" | |
echo "VERSION_MINOR=$VERSION_MINOR" >> "$GITHUB_ENV" | |
- name: Display version | |
run: echo "Version ${{ env.VERSION }}" | |
build: | |
name: Build images | |
runs-on: ubuntu-latest | |
needs: variables | |
container: | |
image: docker:20.10 | |
services: | |
dind: | |
image: docker:20.10-dind | |
timeout-minutes: 60 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and push | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
platforms: linux/amd64,linux/arm64 | |
pull: true | |
push: true | |
build-args: | | |
POETRY_VERSION=${{ vars.POETRY_VERSION }} | |
tags: | | |
${{ vars.CONTAINER_IMAGE }}:latest | |
${{ vars.CONTAINER_IMAGE }}:${{ needs.variables.outputs.version }} | |
${{ vars.CONTAINER_IMAGE }}:${{ needs.variables.outputs.version-major }} | |
${{ vars.CONTAINER_IMAGE }}:${{ needs.variables.outputs.version-major }}.${{ needs.variables.outputs.version-minor }} | |
labels: | | |
org.opencontainers.image.created=$(date -u +'%Y-%m-%dT%H:%M:%SZ') | |
org.opencontainers.image.authors=Fabian Eulitz | |
org.opencontainers.image.url=https://hub.docker.com/repository/docker/${{ vars.CONTAINER_IMAGE }} | |
org.opencontainers.image.source=https://github.com/${{ github.repository }} | |
org.opencontainers.image.version=${{ needs.variables.outputs.version }} | |
org.opencontainers.image.revision=${{ github.sha }} | |
org.opencontainers.image.licenses=Apache-2.0 | |
org.opencontainers.image.title=SureHub API | |
org.opencontainers.image.description=SureHub API is a simple, yet powerful RESTful API for products from Sure Petcare | |
publish-docs: | |
uses: ./.github/workflows/docs.yml | |
create-release: | |
name: Create release | |
runs-on: ubuntu-latest | |
needs: [ variables,build ] | |
timeout-minutes: 5 | |
steps: | |
- name: Release | |
uses: softprops/action-gh-release@v2 | |
with: | |
name: Release ${{ needs.variables.outputs.version }} | |
tag_name: ${{ needs.variables.outputs.version }} | |
target_commitish: ${{ github.sha }} | |
generate_release_notes: true |