Skip to content

fix(git): Syntax error, empty env, add files to message #192 #28

fix(git): Syntax error, empty env, add files to message #192

fix(git): Syntax error, empty env, add files to message #192 #28

Workflow file for this run

name: Test and Coverage
on:
pull_request:
branches: [main]
paths-ignore:
- "**.md"
- "docs/**"
workflow_dispatch:
inputs:
debug_hypothesis:
description: 'Enable hypothesis debug output'
required: false
type: boolean
default: false
jobs:
check_mode:
runs-on: ubuntu-latest
outputs:
is_test_mode: ${{ steps.check.outputs.is_test_mode }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- id: check
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
COMMIT_MSG=$(git log --format=%B -n 1 ${{ github.event.pull_request.head.sha }})
else
COMMIT_MSG="${{ github.event.head_commit.message }}"
fi
if echo "$COMMIT_MSG" | grep -q "\[workflow-test\]"; then
echo "is_test_mode=true" >> $GITHUB_OUTPUT
else
echo "is_test_mode=false" >> $GITHUB_OUTPUT
fi
test_and_coverage:
needs: check_mode
if: needs.check_mode.outputs.is_test_mode != 'true'
name: Test Python ${{ matrix.python-version }} on ${{ matrix.os }}
permissions:
checks: write
contents: read
pull-requests: write
actions: read
outputs:
tests_check_name: ${{ steps.get_outputs.outputs.tests_check_name }}
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
python-version: ["3.13"]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
concurrency:
group: ${{ github.workflow }}-${{ matrix.python-version }}-${{ github.ref }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Generate pip cache hash
id: pip-cache-hash
run: |
files_to_hash="requirements.txt docs/requirements.txt"
hash_files=$(for file in $files_to_hash; do
if [ -f "$file" ]; then
cat "$file"
fi
done | sha256sum | cut -d' ' -f1)
echo "hash=${hash_files}" >> $GITHUB_OUTPUT
- name: Restore pip cache
id: cache-pip-restore
uses: actions/cache/restore@v4
with:
path: ~/.cache/pip
key: refs/heads/main/pip-${{ matrix.python-version }}-${{ steps.pip-cache-hash.outputs.hash }}
restore-keys: |
refs/heads/main/pip-${{ matrix.python-version }}-
- name: Install dependencies
if: steps.cache-pip-restore.outputs.cache-hit != 'true'
run: |
python -m pip install --upgrade pip setuptools
pip install -r requirements.txt
- name: Save pip cache
if: always() && steps.cache-pip-restore.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: ~/.cache/pip
key: ${{ steps.cache-pip-restore.outputs.cache-primary-key }}
- name: Test with tox
run: |
python -m pip install --upgrade pip tox tox-gh-actions
HYPOTHESIS_FLAGS=""
if [ "$TESTING_HYPOTHESIS_DEBUG" = "true" ]; then
HYPOTHESIS_FLAGS="--hypothesis-show-statistics"
fi
tox -vv -- $HYPOTHESIS_FLAGS
env:
PYTEST_ADDOPTS: "-v"
FORCE_COLOR: "1"
DJANGO_SETTINGS_MODULE: "config.settings.test"
DATABASE_URL: "sqlite:///test_db.sqlite3"
PYTEST_XDIST_AUTO_NUM_WORKERS: "2"
- name: Check coverage file exists
run: |
if [ ! -f coverage.xml ]; then
echo "coverage.xml not found"
exit 1
fi
- name: Generate coverage report and check threshold
if: github.event_name == 'pull_request'
run: python .github/scripts/generate_coverage_report.py
- name: Add coverage report comment
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const reportContent = fs.readFileSync('coverage_report.md', 'utf8');
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: reportContent
});
- name: Set Outputs
id: get_outputs
run: |
echo "tests_check_name=Test Python ${{ matrix.python-version }} on ${{ matrix.os }}" >> $GITHUB_OUTPUT
- name: Testing job status
if: always()
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const conclusion = '${{ job.status }}' === 'success' ? 'success' : 'failure';
const check = await github.rest.checks.create({
owner,
repo,
name: 'Test Python ${{ matrix.python-version }} on ${{ matrix.os }}',
head_sha: context.sha,
status: 'completed',
conclusion: conclusion,
output: {
title: conclusion === 'success' ? 'Tests passed' : 'Tests failed',
summary: conclusion === 'success' ? 'All tests completed successfully' : 'Some tests failed'
}
});
core.setOutput('check_run_id', check.data.id);
update_changelog:
needs: [check_mode, test_and_coverage]
if: |
needs.check_mode.outputs.is_test_mode != 'true' &&
success() &&
github.event_name == 'pull_request' &&
!contains(github.event.pull_request.title, 'skip-changelog')
name: Update Changelog
runs-on: ubuntu-latest
permissions:
checks: write
contents: write
pull-requests: read
outputs:
changelog_check_name: ${{ steps.get_outputs.outputs.changelog_check_name }}
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install GPG
run: |
sudo apt-get update
sudo apt-get install -y gnupg2
- name: Import GPG key
run: |
echo "${{ secrets.SGK }}" | gpg --batch --import
KEY_ID=$(gpg --list-secret-keys --keyid-format LONG | grep sec | awk '{print $2}' | cut -d'/' -f2)
echo "trust\n5\ny\nquit" | gpg --batch --command-fd 0 --edit-key $KEY_ID
echo "GPG_KEY_ID=${KEY_ID}" >> $GITHUB_ENV
- name: Configure Git for signing
run: |
git config --global user.name "GitHub Actions Bot"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global commit.gpgsign true
git config --global user.signingkey ${{ env.GPG_KEY_ID }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Install changelog dependencies
run: |
python -m pip install --upgrade pip
pip install PyGithub tenacity
- name: Run Update Changelog Script
id: update_changelog
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ ! -f CHANGELOG.md ] || [ ! -f README.rst ] || [ ! -f pyproject.toml ] || [ ! -f tag_me/__init__.py ] || [ ! -f version.toml ]; then
echo "status=failure" >> $GITHUB_OUTPUT
echo "### Changelog Update Failed" >> $GITHUB_STEP_SUMMARY
echo "Error: Required files not found" >> $GITHUB_STEP_SUMMARY
exit 1
fi
echo "original_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
git checkout ${{ github.head_ref }} || exit 1
python .github/scripts/update_changelog.py
SCRIPT_EXIT=$?
if [ $SCRIPT_EXIT -eq 0 ]; then
if [ -n "$(git status --porcelain)" ]; then
git add CHANGELOG.md pyproject.toml README.rst tag_me/__init__.py version.toml
git -c user.name="GitHub Actions Bot" \
-c user.email="github-actions[bot]@users.noreply.github.com" \
-c user.signingkey="${GPG_KEY_ID}" \
commit -S -m "chore(version): Bump to $(cat version.toml | grep '__version__' | cut -d'"' -f2)"
git push origin HEAD:${{ github.head_ref }}
echo "new_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
echo "changes_made=true" >> $GITHUB_OUTPUT
else
echo "changes_made=false" >> $GITHUB_OUTPUT
fi
echo "status=success" >> $GITHUB_OUTPUT
elif [ $SCRIPT_EXIT -eq 2 ]; then
echo "status=success" >> $GITHUB_OUTPUT
echo "changes_made=false" >> $GITHUB_OUTPUT
else
echo "status=failure" >> $GITHUB_OUTPUT
exit 1
fi
workflow_test:
needs: check_mode
if: needs.check_mode.outputs.is_test_mode == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Test workflow
run: echo "Running in workflow test mode"