Skip to content

Release

Release #13

Workflow file for this run

name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
tag:
description: "Release tag to create or publish (for example, v0.1.0)"
required: true
type: string
allow_move_release_tag:
description: "Allow force-moving an existing v* release tag to the selected commit"
required: true
default: false
type: boolean
mark_as_latest:
description: "Also move the git tag 'latest' to this release commit and publish the container 'latest' tag"
required: true
default: false
type: boolean
permissions:
contents: write
packages: write
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
release_tag: ${{ steps.meta.outputs.release_tag }}
release_ref: ${{ steps.meta.outputs.release_ref }}
release_version: ${{ steps.meta.outputs.release_version }}
publish_latest: ${{ steps.meta.outputs.publish_latest }}
image_name: ${{ steps.image.outputs.value }}
steps:
- name: Determine release metadata
id: meta
env:
RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}
ALLOW_MOVE_RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.allow_move_release_tag || 'false' }}
PUBLISH_LATEST: ${{ github.event_name == 'push' && 'true' || inputs.mark_as_latest }}
run: |
case "$RELEASE_TAG" in
v*) ;;
*)
echo "Only tags starting with v are supported: $RELEASE_TAG" >&2
exit 1
;;
esac
{
echo "release_tag=$RELEASE_TAG"
echo "release_ref=refs/tags/$RELEASE_TAG"
echo "release_version=${RELEASE_TAG#v}"
echo "publish_latest=$PUBLISH_LATEST"
} >> "$GITHUB_OUTPUT"
- name: Check out source
uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ github.ref }}
- name: Ensure release tag exists
if: ${{ github.event_name == 'workflow_dispatch' }}
env:
RELEASE_TAG: ${{ steps.meta.outputs.release_tag }}
ALLOW_MOVE_RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.allow_move_release_tag || 'false' }}
run: |
if git ls-remote --exit-code --tags origin "refs/tags/$RELEASE_TAG" >/dev/null; then
if [ "$ALLOW_MOVE_RELEASE_TAG" = "true" ]; then
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag -f "$RELEASE_TAG"
git push --force origin "refs/tags/$RELEASE_TAG"
else
echo "Release tag '$RELEASE_TAG' already exists on origin." >&2
echo "Reusing an existing release tag is not allowed unless 'allow_move_release_tag' is enabled." >&2
exit 1
fi
else
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag "$RELEASE_TAG"
git push origin "refs/tags/$RELEASE_TAG"
fi
- name: Update latest git tag
if: ${{ steps.meta.outputs.publish_latest == 'true' }}
env:
RELEASE_TAG: ${{ steps.meta.outputs.release_tag }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git fetch --tags origin
git checkout --detach "refs/tags/$RELEASE_TAG"
git tag -f latest
git push --force origin refs/tags/latest
- name: Compute image name
id: image
run: |
echo "value=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT"
build_linux:
runs-on: ubuntu-latest
needs: prepare
steps:
- name: Check out release tag
uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ needs.prepare.outputs.release_ref }}
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Build Linux distribution
run: |
python -m pip install --upgrade pip
python -m pip install . pyinstaller
pyinstaller --noconfirm office-docs-to-md-sync.spec
tar -C dist -czf dist/office-docs-to-md-sync-linux-x86_64.tar.gz office-docs-to-md-sync
- name: Upload Linux artifact
uses: actions/upload-artifact@v7
with:
name: release-linux
path: dist/office-docs-to-md-sync-linux-x86_64.tar.gz
if-no-files-found: error
build_windows:
runs-on: windows-latest
needs: prepare
steps:
- name: Check out release tag
uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ needs.prepare.outputs.release_ref }}
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Build Windows distribution
shell: powershell
run: |
python -m pip install --upgrade pip
python -m pip install . pyinstaller
pyinstaller --noconfirm office-docs-to-md-sync.spec
Compress-Archive -Path dist/office-docs-to-md-sync/* -DestinationPath dist/office-docs-to-md-sync-windows-x86_64.zip -Force
- name: Upload Windows artifact
uses: actions/upload-artifact@v7
with:
name: release-windows
path: dist/office-docs-to-md-sync-windows-x86_64.zip
if-no-files-found: error
publish_release:
runs-on: ubuntu-latest
needs:
- prepare
- build_linux
- build_windows
steps:
- name: Download Linux artifact
uses: actions/download-artifact@v7
with:
name: release-linux
path: dist
- name: Download Windows artifact
uses: actions/download-artifact@v7
with:
name: release-windows
path: dist
- name: Publish GitHub release
uses: ncipollo/release-action@v1
with:
tag: ${{ needs.prepare.outputs.release_tag }}
artifacts: "dist/*"
artifactErrorsFailBuild: true
allowUpdates: true
replacesArtifacts: true
removeArtifacts: true
generateReleaseNotes: true
makeLatest: ${{ needs.prepare.outputs.publish_latest == 'true' }}
publish_container:
runs-on: ubuntu-latest
needs: prepare
steps:
- name: Check out release tag
uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ needs.prepare.outputs.release_ref }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Log in to GHCR
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Smoke test builder environment
run: |
docker build --target builder -t office-docs-to-md-sync-builder-smoke .
docker run --rm office-docs-to-md-sync-builder-smoke python -c "import app.converter, markitdown_no_magika"
- name: Generate Docker metadata
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ needs.prepare.outputs.image_name }}
tags: |
type=raw,value=${{ needs.prepare.outputs.release_tag }}
type=raw,value=${{ needs.prepare.outputs.release_version }}
type=raw,value=latest,enable=${{ needs.prepare.outputs.publish_latest == 'true' }}
- name: Build and push Docker image
uses: docker/build-push-action@v7
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}