changelog workflow (open-telemetry/opentelemetry-python)
The changelog workflow from open-telemetry/opentelemetry-python, explained and optimized by Latchkey.
CI health: C - fair
Point runs-on at Latchkey and get run de-duplication, job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the changelog workflow from the open-telemetry/opentelemetry-python 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
# This action requires that any PR targeting the main branch should add a
# changelog fragment file in the .changelog/ directory. If a changelog entry
# is not required, add the "Skip Changelog" label to disable this action.
name: changelog
on:
pull_request:
types: [opened, synchronize, reopened, labeled, unlabeled]
branches:
- main
merge_group:
permissions:
contents: read
jobs:
changelog:
runs-on: ubuntu-latest
if: |
github.event_name != 'merge_group' &&
!contains(github.event.pull_request.labels.*.name, 'Skip Changelog')
&& github.actor != 'otelbot[bot]'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Fetch base branch
run: git fetch origin ${{ github.base_ref }} --depth=1
- name: Ensure no direct changes to CHANGELOG.md
run: |
if [[ $(git diff --name-only FETCH_HEAD -- 'CHANGELOG.md') ]]
then
echo "CHANGELOG.md should not be directly modified."
echo "Please add a changelog fragment file to the .changelog/ directory instead."
echo "See CONTRIBUTING.md for details."
echo ""
echo "Or add the \"Skip Changelog\" label if this job should be skipped."
false
fi
- name: Install towncrier
run: pip install towncrier==25.8.0
- name: Check for changelog fragment
run: |
if ! towncrier check --compare-with origin/${{ github.base_ref }}; then
echo ""
echo "No changelog fragment found for this PR."
echo "Add a file named .changelog/${{ github.event.pull_request.number }}.<type>"
echo "where <type> is one of: added, changed, deprecated, removed, fixed"
echo "See CONTRIBUTING.md for details."
echo ""
echo "Or add the \"Skip Changelog\" label if this job should be skipped."
false
fi
- name: Validate fragment filenames
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
fragments=$(git diff --diff-filter=A --name-only origin/${{ github.base_ref }} -- '.changelog/*' | grep -v '/\.gitignore$' || true)
[ -z "$fragments" ] && exit 0
invalid=()
while IFS= read -r f; do
base=$(basename "$f")
if [[ ! "$base" =~ ^([0-9]+)\.(added|changed|deprecated|removed|fixed)$ ]]; then
invalid+=("$f (expected <PR_NUMBER>.<type>; type one of added, changed, deprecated, removed, fixed)")
continue
fi
if [[ "${BASH_REMATCH[1]}" != "${PR_NUMBER}" ]]; then
invalid+=("$f (PR number ${BASH_REMATCH[1]} does not match this PR's number ${PR_NUMBER})")
fi
done <<< "$fragments"
if (( ${#invalid[@]} > 0 )); then
echo "Invalid changelog fragment(s):"
for msg in "${invalid[@]}"; do
echo " $msg"
done
exit 1
fi
- name: Preview changelog
run: towncrier build --draft --version Unreleased
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
# This action requires that any PR targeting the main branch should add a # changelog fragment file in the .changelog/ directory. If a changelog entry # is not required, add the "Skip Changelog" label to disable this action. name: changelog on: pull_request: types: [opened, synchronize, reopened, labeled, unlabeled] branches: - main merge_group: permissions: contents: read concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: changelog: timeout-minutes: 30 runs-on: latchkey-small if: | github.event_name != 'merge_group' && !contains(github.event.pull_request.labels.*.name, 'Skip Changelog') && github.actor != 'otelbot[bot]' steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Fetch base branch run: git fetch origin ${{ github.base_ref }} --depth=1 - name: Ensure no direct changes to CHANGELOG.md run: | if [[ $(git diff --name-only FETCH_HEAD -- 'CHANGELOG.md') ]] then echo "CHANGELOG.md should not be directly modified." echo "Please add a changelog fragment file to the .changelog/ directory instead." echo "See CONTRIBUTING.md for details." echo "" echo "Or add the \"Skip Changelog\" label if this job should be skipped." false fi - name: Install towncrier run: pip install towncrier==25.8.0 - name: Check for changelog fragment run: | if ! towncrier check --compare-with origin/${{ github.base_ref }}; then echo "" echo "No changelog fragment found for this PR." echo "Add a file named .changelog/${{ github.event.pull_request.number }}.<type>" echo "where <type> is one of: added, changed, deprecated, removed, fixed" echo "See CONTRIBUTING.md for details." echo "" echo "Or add the \"Skip Changelog\" label if this job should be skipped." false fi - name: Validate fragment filenames env: PR_NUMBER: ${{ github.event.pull_request.number }} run: | fragments=$(git diff --diff-filter=A --name-only origin/${{ github.base_ref }} -- '.changelog/*' | grep -v '/\.gitignore$' || true) [ -z "$fragments" ] && exit 0 invalid=() while IFS= read -r f; do base=$(basename "$f") if [[ ! "$base" =~ ^([0-9]+)\.(added|changed|deprecated|removed|fixed)$ ]]; then invalid+=("$f (expected <PR_NUMBER>.<type>; type one of added, changed, deprecated, removed, fixed)") continue fi if [[ "${BASH_REMATCH[1]}" != "${PR_NUMBER}" ]]; then invalid+=("$f (PR number ${BASH_REMATCH[1]} does not match this PR's number ${PR_NUMBER})") fi done <<< "$fragments" if (( ${#invalid[@]} > 0 )); then echo "Invalid changelog fragment(s):" for msg in "${invalid[@]}"; do echo " $msg" done exit 1 fi - name: Preview changelog run: towncrier build --draft --version Unreleased
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. - Cancel superseded runs when a branch or PR gets a newer push.
- 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:
- Dependency installs
This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.