Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,28 @@ env:
UV_VERSION: "0.13.4"

jobs:
test:
permissions:
contents: read
timeout-minutes: 90
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
fetch-depth: 0
- uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6
with:
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
- uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7
with:
version: ${{ env.UV_VERSION }}
enable-cache: true
- name: Install dependencies
run: uv sync --only-group nox --locked
- name: Run unit tests
run: uv run nox -vs unit -p ${{ env.PYTHON_DEFAULT_VERSION }} -- -v
deploy:
needs: test
permissions:
contents: write
env:
Expand All @@ -23,14 +44,14 @@ jobs:
IS_PRERELEASE=$([[ ${{ github.ref }} =~ [^0-9]$ ]] && echo true || echo false)
export IS_PRERELEASE
echo "prerelease=$IS_PRERELEASE" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v4
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
fetch-depth: 0
- name: Set up Python ${{ env.PYTHON_DEFAULT_VERSION }}
uses: actions/setup-python@v6
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6
with:
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
- uses: astral-sh/setup-uv@v7
- uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7
with:
version: ${{ env.UV_VERSION }}
enable-cache: true
Expand Down Expand Up @@ -115,7 +136,7 @@ jobs:
--draft="$IS_DRAFT" --prerelease="$IS_PRERELEASE"
- name: Upload the distribution to PyPI
if: ${{ env.B2_PYPI_PASSWORD != '' && steps.prerelease_check.outputs.prerelease == 'false' }}
uses: pypa/gh-action-pypi-publish@release/v1
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # release/v1
with:
user: __token__
password: ${{ secrets.B2_PYPI_PASSWORD }}
41 changes: 22 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
branches: [master]
types: [opened, synchronize, reopened, ready_for_review]

permissions:
contents: read

env:
PYTHON_DEFAULT_VERSION: "3.14"
UV_VERSION: "0.13.4"
Expand All @@ -16,7 +19,7 @@ jobs:
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
fetch-depth: 0
# actions-governance: replaced by Check spelling; remove after a real run verifies the replacement
Expand All @@ -27,10 +30,10 @@ jobs:
# Preserve the original action's effective CLI arguments, including its positional path.
run: pipx run codespell --count --skip ./.git --ignore-words-list datas re-use
- name: Set up Python ${{ env.PYTHON_DEFAULT_VERSION }}
uses: actions/setup-python@v6
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6
with:
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
- uses: astral-sh/setup-uv@v7
- uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7
with:
version: ${{ env.UV_VERSION }}
enable-cache: true
Expand Down Expand Up @@ -59,14 +62,14 @@ jobs:
needs: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
fetch-depth: 0
- name: Set up Python ${{ env.PYTHON_DEFAULT_VERSION }}
uses: actions/setup-python@v6
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6
with:
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
- uses: astral-sh/setup-uv@v7
- uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7
with:
version: ${{ env.UV_VERSION }}
enable-cache: true
Expand All @@ -84,16 +87,16 @@ jobs:
B2_TEST_APPLICATION_KEY_ID: ${{ (vars.B2_LIVE_TESTS_ENABLED == 'true' && (github.event_name != 'pull_request' || !github.event.pull_request.draft)) && secrets.B2_TEST_APPLICATION_KEY_ID || '' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
if: ${{ env.B2_TEST_APPLICATION_KEY != '' && env.B2_TEST_APPLICATION_KEY_ID != '' }} # TODO: skip this whole job instead
with:
fetch-depth: 0
- name: Set up Python ${{ env.PYTHON_DEFAULT_VERSION }}
if: ${{ env.B2_TEST_APPLICATION_KEY != '' && env.B2_TEST_APPLICATION_KEY_ID != '' }} # TODO: skip this whole job instead
uses: actions/setup-python@v6
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6
with:
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
- uses: astral-sh/setup-uv@v7
- uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7
if: ${{ env.B2_TEST_APPLICATION_KEY != '' && env.B2_TEST_APPLICATION_KEY_ID != '' }} # TODO: skip this whole job instead
with:
version: ${{ env.UV_VERSION }}
Expand Down Expand Up @@ -129,14 +132,14 @@ jobs:
extras: "full"
os: "ubuntu-latest"
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6
with:
python-version: ${{ matrix.python-version }}
- uses: astral-sh/setup-uv@v7
- uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7
with:
version: ${{ env.UV_VERSION }}
enable-cache: true
Expand Down Expand Up @@ -169,19 +172,19 @@ jobs:
- os: windows-latest
python-version: "3.12"
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
fetch-depth: 0
path: b2-sdk-python
- uses: actions/checkout@v4
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
repository: Backblaze/B2_Command_Line_Tool
path: B2_Command_Line_Tool
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6
with:
python-version: ${{ matrix.python-version }}
- uses: astral-sh/setup-uv@v7
- uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7
with:
version: ${{ env.UV_VERSION }}
enable-cache: true
Expand Down Expand Up @@ -219,14 +222,14 @@ jobs:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
fetch-depth: 0
- name: Set up Python ${{ env.PYTHON_DEFAULT_VERSION }}
uses: actions/setup-python@v6
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6
with:
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
- uses: astral-sh/setup-uv@v7
- uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7
with:
version: ${{ env.UV_VERSION }}
enable-cache: true
Expand Down
1 change: 1 addition & 0 deletions changelog.d/+release-ci-safety.infrastructure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Pin workflow actions and require unit tests to pass before release.
43 changes: 43 additions & 0 deletions test/static/test_release_workflow_safety.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
######################################################################
#
# File: test/static/test_release_workflow_safety.py
#
# Copyright 2026 Backblaze Inc. All Rights Reserved.
#
# License https://www.backblaze.com/using_b2_code.html
#
######################################################################
"""Check the CI permissions, action pins, and release test gate."""

import re
from pathlib import Path

import yaml

WORKFLOWS = Path(__file__).parents[2] / '.github' / 'workflows'


def load_workflow(name):
return yaml.safe_load((WORKFLOWS / name).read_text())


def test_ci_token_is_read_only():
assert load_workflow('ci.yml')['permissions'] == {'contents': 'read'}


def test_active_actions_are_pinned_to_full_commit_shas():
for path in WORKFLOWS.glob('*.yml'):
for job in load_workflow(path)['jobs'].values():
for step in job.get('steps', []):
action = step.get('uses', '')
if action and not action.startswith(('./', 'docker://')):
assert re.fullmatch(r'[^@]+@[0-9a-f]{40}', action), action


def test_release_requires_successful_unit_tests():
jobs = load_workflow('cd.yml')['jobs']
assert jobs['deploy']['needs'] == 'test'
assert 'if' not in jobs['deploy']
steps = jobs['test']['steps']
assert any('nox -vs unit' in step.get('run', '') for step in steps)
assert jobs['test'].get('permissions') == {'contents': 'read'}
Loading