3.5.3.2 #671
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: Create and publish Docker images | |
on: | |
release: | |
types: | |
- published | |
workflow_dispatch: | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
build-and-push-image: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # Ensures we get all history for tag retrieval | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- 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: Get lowercase repo name | |
id: get_lowercase_repo_name | |
run: | | |
REPO_NAME=${{ env.IMAGE_NAME }} | |
echo "LOWER_CASE_REPO_NAME=${REPO_NAME,,}" >> $GITHUB_ENV | |
- name: Get release version and notes (only for release events) | |
if: github.event_name == 'release' | |
id: get_release_info | |
run: | | |
RELEASE_VERSION=${{ github.event.release.tag_name }} | |
RELEASE_NOTES="${{ github.event.release.body }}" | |
if [ -z "$RELEASE_VERSION" ]; then | |
echo "Error: RELEASE_VERSION is empty. Ensure a valid release tag." | |
exit 1 | |
fi | |
# Escape special characters for safe writing to file | |
RELEASE_NOTES=$(echo "$RELEASE_NOTES" | sed 's/"/\\"/g') | |
echo "VERSION=${RELEASE_VERSION}" >> $GITHUB_ENV | |
echo "RELEASE_NOTES=\"$RELEASE_NOTES\"" >> $GITHUB_ENV | |
- name: Update version.py (only on release) | |
if: github.event_name == 'release' | |
run: | | |
TIMESTAMP=$(date +"%Y-%m-%d") | |
VERSION_FILE="data/version.py" | |
# Create version.py if it doesn't exist | |
if [ ! -f "$VERSION_FILE" ]; then | |
echo "# Version Information" > "$VERSION_FILE" | |
echo "" >> "$VERSION_FILE" | |
fi | |
# Prepend new release info | |
TEMP_FILE=$(mktemp) | |
echo "__version__ = \"${{ env.VERSION }}\"" > "$TEMP_FILE" | |
echo "" >> "$TEMP_FILE" | |
echo "\"\"\"" >> "$TEMP_FILE" | |
echo "Changelog for version ${{ env.VERSION }} ($TIMESTAMP):" >> "$TEMP_FILE" | |
echo "" >> "$TEMP_FILE" | |
echo "$RELEASE_NOTES" >> "$TEMP_FILE" | |
echo "\"\"\"" >> "$TEMP_FILE" | |
echo "" >> "$TEMP_FILE" | |
cat "$VERSION_FILE" >> "$TEMP_FILE" | |
mv "$TEMP_FILE" "$VERSION_FILE" | |
- name: Commit and push version update (only on release) | |
if: github.event_name == 'release' | |
run: | | |
git checkout master # Ensure we're on master branch | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git add data/version.py | |
git commit -m "Update version.py to ${{ env.VERSION }} with changelog" | |
git push origin master | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v3 | |
with: | |
context: . | |
push: true | |
tags: ${{ env.REGISTRY }}/${{ env.LOWER_CASE_REPO_NAME }}:${{ env.VERSION }}, ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max |