Add Python 3.11 to built matrix and Docker #31
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: Publish | |
on: | |
push: | |
tags: | |
- '[0-9]+.[0-9]+.[0-9]+' | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
build-and-publish: | |
runs-on: ubuntu-latest | |
permissions: | |
id-token: write | |
contents: write | |
packages: write | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up PDM | |
uses: pdm-project/setup-pdm@v3 | |
with: | |
python-version: '3.11' | |
# Publish to PyPI | |
- name: Publish to PyPI | |
run: pdm publish | |
- name: Bump version | |
run: | | |
TAG_NAME=${{ github.ref }} | |
CURRENT_RECAP_VERSION=${TAG_NAME#refs/tags/} | |
NEW_RECAP_VERSION=$(echo $CURRENT_RECAP_VERSION | awk -F. '{$NF++; print $1"."$2"."$NF}') | |
echo "CURRENT_RECAP_VERSION=$CURRENT_RECAP_VERSION" >> $GITHUB_ENV | |
echo "NEW_RECAP_VERSION=$NEW_RECAP_VERSION" >> $GITHUB_ENV | |
sed -i "s/^version = \"\([0-9]\+\)\.\([0-9]\+\)\.\([0-9]\+\)\"$/version = \"$NEW_RECAP_VERSION\"/" pyproject.toml | |
- name: Commit version bump | |
uses: stefanzweifel/git-auto-commit-action@v4 | |
with: | |
branch: main | |
commit_message: Bump version ${{ env.NEW_RECAP_VERSION }} | |
file_pattern: pyproject.toml | |
# Wait for PyPI to update | |
- name: Wait for PyPI to update | |
run: | | |
set -x | |
PACKAGE_VERSION=${{ env.CURRENT_RECAP_VERSION }} | |
MAX_ATTEMPTS=12 | |
ATTEMPT_COUNT=0 | |
SLEEP_SECONDS=10 | |
while [ $ATTEMPT_COUNT -lt $MAX_ATTEMPTS ]; do | |
# `true` because `pip index` returns a non-zero exit code when no package is found, | |
# which causes the script to fail. | |
AVAILABLE_VERSIONS=$(pip --no-cache-dir index --ignore-requires-python versions recap-core) || true | |
if [[ $AVAILABLE_VERSIONS =~ "recap-core ($PACKAGE_VERSION)" ]]; then | |
break | |
else | |
echo "Package version ${PACKAGE_VERSION} is not yet available on PyPI." | |
echo "Retrying in $SLEEP_SECONDS seconds." | |
sleep $SLEEP_SECONDS | |
let ATTEMPT_COUNT=ATTEMPT_COUNT+1 | |
fi | |
done | |
if [ $ATTEMPT_COUNT -eq $MAX_ATTEMPTS ]; then | |
echo "No package available after $MAX_ATTEMPTS. Exiting." | |
exit 1 | |
fi | |
# Publish Docker image | |
- name: Log in to the Container registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
build-args: | | |
RECAP_VERSION=${{ env.CURRENT_RECAP_VERSION }} |