Skip to content

feat: add simple release workflow and documentation #1

feat: add simple release workflow and documentation

feat: add simple release workflow and documentation #1

Workflow file for this run

name: Release
on:
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g., 1.0.1)'
required: true
type: string
release_type:
description: 'Release type'
required: true
type: choice
options:
- patch
- minor
- major
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install toml
- name: Validate version format
run: |
if ! echo "${{ inputs.version }}" | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "Error: Version must be in format X.Y.Z"
exit 1
fi
- name: Check if tag already exists
run: |
if git rev-parse "v${{ inputs.version }}" >/dev/null 2>&1; then
echo "Error: Tag v${{ inputs.version }} already exists"
exit 1
fi
- name: Wait for tests to complete
uses: lewagon/wait-on-check-action@v1.3.4
with:
ref: ${{ github.sha }}
check-name: 'Test template generation'
repo-token: ${{ secrets.GITHUB_TOKEN }}
wait-interval: 10
- name: Update version in pyproject.toml
run: |
python -c "
import toml

Check failure on line 67 in .github/workflows/release.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/release.yml

Invalid workflow file

You have an error in your yaml syntax on line 67
import sys
# Read the current pyproject.toml
with open('pyproject.toml', 'r') as f:
data = toml.load(f)
# Update the version
data['project']['version'] = '${{ inputs.version }}'
# Write back
with open('pyproject.toml', 'w') as f:
toml.dump(data, f)
"
- name: Update version in cookiecutter.json
run: |
python -c "
import json
# Read cookiecutter.json
with open('cookiecutter.json', 'r') as f:
data = json.load(f)
# Add version field if it doesn't exist
data['_template_version'] = '${{ inputs.version }}'
# Write back with proper formatting
with open('cookiecutter.json', 'w') as f:
json.dump(data, f, indent=4)
f.write('\n')
"
- name: Commit version updates
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add pyproject.toml cookiecutter.json
git commit -m "chore: bump version to ${{ inputs.version }}"
git push origin main
- name: Create and push tag
run: |
git tag -a "v${{ inputs.version }}" -m "Release v${{ inputs.version }}"
git push origin "v${{ inputs.version }}"
- name: Generate release notes
id: release_notes
run: |
# Get the previous tag
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -z "$PREV_TAG" ]; then
echo "No previous tag found, this is the first release"
COMPARE_FROM=$(git rev-list --max-parents=0 HEAD)
else
COMPARE_FROM=$PREV_TAG
fi
# Generate commit list
echo "commits<<EOF" >> $GITHUB_OUTPUT
git log --pretty=format:"- %s (%h)" $COMPARE_FROM..HEAD >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ inputs.version }}
name: Release v${{ inputs.version }}
draft: false
prerelease: false
generate_release_notes: true
body: |
## 🎉 Release v${{ inputs.version }}
**Release type**: ${{ inputs.release_type }}
### For Users of This Template
To update your existing protocol generated from this template:
```bash
cruft update
```
Or to create a new protocol:
```bash
cookiecutter gh:ReproNim/reproschema-protocol-cookiecutter
```
### What's Changed
Auto-generated release notes are below.