Publish Release workflow (zefhub/zef)
The Publish Release workflow from zefhub/zef, explained and optimized by Latchkey.
CI health: C - fair
Point runs-on at Latchkey and get caching, job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Publish Release workflow from the zefhub/zef repository, a real project running GitHub Actions. It is shown here with attribution under its Apache-2.0 license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
name: Publish Release
on:
workflow_dispatch:
inputs:
tag:
description: 'The pyzef-x tag of the release'
required: true
type: string
release:
types: [published, create]
jobs:
extract-tag-name:
name: Just for tag name variable
runs-on: ubuntu-20.04
outputs:
tag: ${{ steps.find_tag.outputs.tag }}
steps:
- id: find_tag
env:
MAYBE_DISPATCH: ${{ github.event.inputs.tag }}
MAYBE_RELEASE: ${{ github.event.release.tag_name }}
run: |
if [ -n "$MAYBE_DISPATCH" ] ; then
echo "tag=${MAYBE_DISPATCH}" >> $GITHUB_OUTPUT
else
echo "tag=${MAYBE_RELEASE##pyzef-}" >> $GITHUB_OUTPUT
fi
upload-zefops:
name: Deploy zefops docstrings to zef-docs.
runs-on: ubuntu-20.04
environment: Release
needs: [extract-tag-name]
env:
ZEF_TAG: ${{ needs.extract-tag-name.outputs.tag }}
steps:
- uses: actions/checkout@v3
with:
path: zef-latest
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: 3.8
- name: Grab built wheel
run: |
python3 -mpip install zef==${ZEF_TAG}
########
# Generate docs
- name: Run extract docstrings script
env:
VERSION_STRING: ${{ env.ZEF_TAG }}
run: |
python zef-latest/scripts/extract-docstrings.py
- uses: actions/checkout@v3
with:
repository: zefhub/zef-docs
path: zef-docs
token: ${{ secrets.GIT_FULL_ACCESS_TOKEN }}
- name: Commit to zef-docs
env:
TARGET_FILE: "docs/reference/zef-ops.mdx"
run: |
# Make sure the file hasn't moved
[ -f zef-docs/${TARGET_FILE} ]
mv zef-ops.mdx zef-docs/$TARGET_FILE
cd zef-docs
git status
git config user.email "thedanielforum@gmail.com"
git config user.name "Zef Bot by Github Actions"
git add ${TARGET_FILE}
if ! git diff-index --quiet HEAD ; then
git commit -m "Auto generated zef-ops docs from docstrings in Zef repo for version ${ZEF_TAG}."
git push origin master
fi
publish-announcement:
name: Publish announcement of new release
runs-on: ubuntu-20.04
needs: [extract-tag-name, upload-zefops]
env:
ZEF_TAG: ${{ needs.extract-tag-name.outputs.tag }}
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Get announcement details
id: release-details
run: |
curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/zefhub/zef/releases/tags/pyzef-${ZEF_TAG} -o curl.out || exit 1
cat curl.out | jq -re .body > release.body || exit 1
title=$(cat curl.out | jq -re .name)
echo "title=${title}" >> $GITHUB_OUTPUT
- name: Release announcement
env:
MATTERMOST_URL: ${{ secrets.MATTERMOST_URL }}
CHANNEL: "releases"
NAME: ${{ steps.release-details.outputs.title }}
DESCRIPTION_FILE: "release.body"
VERSION_STRING: ${{ env.ZEF_TAG }}
DOWNLOAD_STRING: "`pip3 install --upgrade zef`"
run: go run .github/scripts/publish_release_announcement.go
The same workflow, on Latchkey
Estimated ~20% faster on cache hits, plus fewer wasted runs and a safer supply chain. Added and changed lines are highlighted.
name: Publish Release on: workflow_dispatch: inputs: tag: description: 'The pyzef-x tag of the release' required: true type: string release: types: [published, create] jobs: extract-tag-name: timeout-minutes: 30 name: Just for tag name variable runs-on: latchkey-small outputs: tag: ${{ steps.find_tag.outputs.tag }} steps: - id: find_tag env: MAYBE_DISPATCH: ${{ github.event.inputs.tag }} MAYBE_RELEASE: ${{ github.event.release.tag_name }} run: | if [ -n "$MAYBE_DISPATCH" ] ; then echo "tag=${MAYBE_DISPATCH}" >> $GITHUB_OUTPUT else echo "tag=${MAYBE_RELEASE##pyzef-}" >> $GITHUB_OUTPUT fi upload-zefops: timeout-minutes: 30 name: Deploy zefops docstrings to zef-docs. runs-on: latchkey-small environment: Release needs: [extract-tag-name] env: ZEF_TAG: ${{ needs.extract-tag-name.outputs.tag }} steps: - uses: actions/checkout@v3 with: path: zef-latest token: ${{ secrets.GITHUB_TOKEN }} - name: Setup python uses: actions/setup-python@v4 with: cache: 'pip' python-version: 3.8 - name: Grab built wheel run: | python3 -mpip install zef==${ZEF_TAG} ######## # Generate docs - name: Run extract docstrings script env: VERSION_STRING: ${{ env.ZEF_TAG }} run: | python zef-latest/scripts/extract-docstrings.py - uses: actions/checkout@v3 with: repository: zefhub/zef-docs path: zef-docs token: ${{ secrets.GIT_FULL_ACCESS_TOKEN }} - name: Commit to zef-docs env: TARGET_FILE: "docs/reference/zef-ops.mdx" run: | # Make sure the file hasn't moved [ -f zef-docs/${TARGET_FILE} ] mv zef-ops.mdx zef-docs/$TARGET_FILE cd zef-docs git status git config user.email "thedanielforum@gmail.com" git config user.name "Zef Bot by Github Actions" git add ${TARGET_FILE} if ! git diff-index --quiet HEAD ; then git commit -m "Auto generated zef-ops docs from docstrings in Zef repo for version ${ZEF_TAG}." git push origin master fi publish-announcement: timeout-minutes: 30 name: Publish announcement of new release runs-on: latchkey-small needs: [extract-tag-name, upload-zefops] env: ZEF_TAG: ${{ needs.extract-tag-name.outputs.tag }} steps: - uses: actions/checkout@v3 with: token: ${{ secrets.GITHUB_TOKEN }} - name: Get announcement details id: release-details run: | curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/zefhub/zef/releases/tags/pyzef-${ZEF_TAG} -o curl.out || exit 1 cat curl.out | jq -re .body > release.body || exit 1 title=$(cat curl.out | jq -re .name) echo "title=${title}" >> $GITHUB_OUTPUT - name: Release announcement env: MATTERMOST_URL: ${{ secrets.MATTERMOST_URL }} CHANNEL: "releases" NAME: ${{ steps.release-details.outputs.title }} DESCRIPTION_FILE: "release.body" VERSION_STRING: ${{ env.ZEF_TAG }} DOWNLOAD_STRING: "`pip3 install --upgrade zef`" run: go run .github/scripts/publish_release_announcement.go
What changed
- Run on Latchkey managed runners with one line (
runs-on), which apply the fixes below automatically and self-heal transient failures. This example useslatchkey-small; pick the runner size that fits the job. - Cache dependency installs on the setup step so they are served from cache.
- Add a job timeout so a hung step cannot burn hours of runner time.
What Latchkey heals here
This workflow has steps that commonly fail on transient issues (network, registries, flaky browsers). On Latchkey managed runners they are detected, retried, and self-healed instead of failing your build:
- Network fetches
This workflow runs 3 jobs per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.