0.7.0 - Mono (Prepare, Validate) #18
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 0.7.0 - Mono (Prepare, Validate) | |
on: | |
workflow_dispatch: | |
concurrency: | |
group: dev-branch-prepare-workflow | |
cancel-in-progress: false | |
jobs: | |
set-matrix: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.get-matrix.outputs.matrix }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Setup Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.x' | |
- name: Install dependencies for matrix generation | |
run: pip install toml | |
- name: Get workspace members | |
id: get-matrix | |
run: | | |
cd pkgs | |
python - <<'EOF' | |
import toml, json, os | |
# Open the root pyproject.toml file | |
with open("pyproject.toml", "r") as f: | |
config = toml.load(f) | |
# Extract the workspace members from tool.uv.workspace.members | |
members = config.get("tool", {}).get("uv", {}).get("workspace", {}).get("members", []) | |
if not isinstance(members, list): | |
raise Exception("The 'members' entry is not a list.") | |
# Build a matrix with one entry per member | |
matrix = {"include": [{"member": member} for member in members]} | |
print(f"Matrix: {json.dumps(matrix)}") | |
# Write the matrix JSON to the GitHub Actions output | |
with open(os.environ["GITHUB_OUTPUT"], "a") as fh: | |
print(f"matrix={json.dumps(matrix)}", file=fh) | |
EOF | |
test: | |
needs: set-matrix | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: ${{ fromJson(needs.set-matrix.outputs.matrix) }} | |
fail-fast: false | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Setup Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.x' | |
- name: Install dependencies for testing | |
run: pip install uv pytest toml | |
- name: Bump Version Placeholder | |
run: | | |
MEMBER="${{ matrix.member }}" | |
echo "Running tests for workspace member: $MEMBER" | |
# Read the package name from the member's pyproject.toml | |
PACKAGE_NAME=$(python -c "import toml; print(toml.load('${{ github.workspace }}/pkgs/${MEMBER}/pyproject.toml')['project']['name'])") | |
echo "Package name: $PACKAGE_NAME" | |
uv run --active scripts/bump_pyproject_version.py --bump patch ${{ github.workspace }}/pkgs/${MEMBER}/pyproject.toml | |
- name: Ruff format | |
run: | | |
cd pkgs | |
MEMBER="${{ matrix.member }}" | |
echo "Running tests for workspace member: $MEMBER" | |
# Read the package name from the member's pyproject.toml | |
PACKAGE_NAME=$(python -c "import toml; print(toml.load('${{ github.workspace }}/pkgs/${MEMBER}/pyproject.toml')['project']['name'])") | |
echo "Package name: $PACKAGE_NAME" | |
# Run the test command with uv | |
uv run --directory "$MEMBER" --package "$PACKAGE_NAME" --isolated --active ruff format . | |
- name: Ruff lint check & fix | |
run: | | |
cd pkgs | |
MEMBER="${{ matrix.member }}" | |
echo "Running tests for workspace member: $MEMBER" | |
# Read the package name from the member's pyproject.toml | |
PACKAGE_NAME=$(python -c "import toml; print(toml.load('${{ github.workspace }}/pkgs/${MEMBER}/pyproject.toml')['project']['name'])") | |
echo "Package name: $PACKAGE_NAME" | |
# Run the test command with uv | |
uv run --directory "$MEMBER" --package "$PACKAGE_NAME" --isolated --active ruff check . --fix | |
- name: Run tests for member ${{ matrix.member }} | |
run: | | |
cd pkgs | |
MEMBER="${{ matrix.member }}" | |
echo "Running tests for workspace member: $MEMBER" | |
# Read the package name from the member's pyproject.toml | |
PACKAGE_NAME=$(python -c "import toml; print(toml.load('${{ github.workspace }}/pkgs/${MEMBER}/pyproject.toml')['project']['name'])") | |
echo "Package name: $PACKAGE_NAME" | |
# Run the test command with uv | |
uv run --directory "$MEMBER" --package "$PACKAGE_NAME" --isolated --active pytest -vvv | |
- name: Create patch for changes | |
if: always() | |
run: | | |
mkdir -p patches | |
MEMBER="${{ matrix.member }}" | |
# Replace "/" with "-" to ensure a safe filename | |
SAFE_MEMBER=$(echo "$MEMBER" | tr '/' '-') | |
# Check for changes in the member directory (located under pkgs) | |
if [ -n "$(git -C pkgs status --porcelain "$MEMBER")" ]; then | |
git -C pkgs diff "$MEMBER" > patches/patch_${SAFE_MEMBER}.patch | |
else | |
echo "No changes in ${MEMBER} to create a patch." | |
fi | |
- name: Set safe member variable | |
id: set_safe_member | |
run: | | |
echo "SAFE_MEMBER=$(echo '${{ matrix.member }}' | tr '/' '-')" >> $GITHUB_OUTPUT | |
- name: Upload patch artifact | |
if: always() | |
uses: actions/upload-artifact@v4 | |
with: | |
name: patch-${{ steps.set_safe_member.outputs.SAFE_MEMBER }} | |
path: patches/patch_${{ steps.set_safe_member.outputs.SAFE_MEMBER }}.patch | |
if-no-files-found: warn | |
commit: | |
name: Commit Changes | |
needs: test | |
runs-on: ubuntu-latest | |
if: always() | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.ref }} | |
- name: Setup Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.x' | |
- name: Download patch artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
# This will download all artifacts that start with "patch | |
path: patches | |
- name: Apply patches | |
run: | | |
for patch in patches/*.patch; do | |
if [ -f "$patch" ]; then | |
echo "Applying patch $patch" | |
git apply --directory=pkgs "$patch" || true | |
fi | |
done | |
- name: Git Commit and Push | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
rm -rf patches | |
git add . | |
if ! git diff-index --quiet HEAD; then | |
git commit -m "chore: apply automatic formatting and lint fixes" | |
git pull --rebase origin "${{ github.ref }}" | |
git push origin HEAD:"${{ github.ref }}" | |
else | |
echo "No changes to commit." | |
fi |