Skip to content

Release

Release #89

Workflow file for this run

name: Release
on:
workflow_run:
workflows: [CI]
types: [completed]
jobs:
release:
if: >
github.event.workflow_run.conclusion == 'success' &&
startsWith(github.event.workflow_run.head_branch, 'v')
runs-on: ubuntu-latest
environment: production
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_branch }}
fetch-depth: 0
fetch-tags: true
- uses: actions/setup-go@v5
with:
go-version-file: src/go.mod
- run: make release
- name: Determine version
id: version
run: |
TAG="${{ github.event.workflow_run.head_branch }}"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "version=${TAG#v}" >> "$GITHUB_OUTPUT"
- name: Generate release notes
id: notes
run: |
git fetch --tags
CUR_TAG="${{ steps.version.outputs.tag }}"
PREV_TAG=$(git tag --sort=-v:refname | grep -A1 "^${CUR_TAG}$" | tail -1)
if [ "$PREV_TAG" = "$CUR_TAG" ]; then PREV_TAG=""; fi
if [ -z "$PREV_TAG" ]; then
RANGE="${CUR_TAG}"
else
RANGE="${PREV_TAG}..${CUR_TAG}"
fi
git log ${RANGE} --no-merges --format='%s%n%b%n---%n' | sed '/^Bump version/,/^---$/d' | sed 's/^---$/\n---/' > /tmp/release-notes.md
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.tag }}
name: ${{ steps.version.outputs.tag }}
body_path: /tmp/release-notes.md
make_latest: true
files: |
build/factorly-${{ steps.version.outputs.version }}-linux-amd64
build/factorly-${{ steps.version.outputs.version }}-darwin-amd64
build/factorly-${{ steps.version.outputs.version }}-darwin-arm64
build/factorly-${{ steps.version.outputs.version }}-windows-amd64.exe
- uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Publish to npm
working-directory: npm
run: |
CURRENT=$(node -p "require('./package.json').version")
PUBLISHED=$(npm view factorly version 2>/dev/null || echo "none")
if [ "$CURRENT" = "$PUBLISHED" ]; then
echo "npm factorly@$CURRENT already published, skipping"
else
npm publish
fi
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Publish to PyPI
working-directory: pip
run: |
pip install build twine
CURRENT=$(python -c "import re; print(re.search(r'version = \"(.+?)\"', open('pyproject.toml').read()).group(1))")
PUBLISHED=$(pip index versions factorly 2>/dev/null | grep -oP 'factorly \(\K[^)]+' || echo "none")
if [ "$CURRENT" = "$PUBLISHED" ]; then
echo "PyPI factorly@$CURRENT already published, skipping"
else
python -m build
twine upload dist/*
fi
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}