Skip to content

Commit b19f22d

Browse files
committed
chore: test weekly that template copying works
1 parent 45b55e0 commit b19f22d

3 files changed

Lines changed: 140 additions & 0 deletions

File tree

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Test Template
2+
3+
on:
4+
schedule:
5+
# Monday at 9 AM UTC
6+
- cron: '0 9 * * 1'
7+
workflow_dispatch:
8+
9+
jobs:
10+
test-template:
11+
if: github.repository == 'mloda-ai/mloda-plugin-template'
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: write
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Set up Python
22+
uses: actions/setup-python@v5
23+
with:
24+
python-version: "3.10"
25+
26+
- name: Install uv
27+
run: |
28+
python -m pip install --upgrade pip
29+
python -m pip install uv
30+
31+
- name: Run template test
32+
run: |
33+
chmod +x scripts/test-template.sh
34+
./scripts/test-template.sh
35+
36+
- name: Bump version
37+
id: bump
38+
run: |
39+
# Fail in 2027 - need to bump base version for new year
40+
year=$(date +%Y)
41+
if [[ "$year" == "2027" ]]; then
42+
echo "ERROR: Year 2027 - bump base version in pyproject.toml manually"
43+
exit 1
44+
fi
45+
46+
# Extract base version (e.g., 0.2.2)
47+
base=$(grep -oP 'version = "\K[0-9]+\.[0-9]+\.[0-9]+' pyproject.toml | head -1)
48+
49+
# Get ISO week number
50+
week=$(date +%V)
51+
52+
# New version: base.week_number
53+
new_version="${base}.${week#0}"
54+
55+
# Update pyproject.toml (match any existing version format)
56+
sed -i "s/version = \"[^\"]*\"/version = \"$new_version\"/" pyproject.toml
57+
58+
echo "version=$new_version" >> $GITHUB_OUTPUT
59+
echo "Version: $new_version (week $week)"
60+
61+
- name: Commit and tag
62+
run: |
63+
git config user.name "github-actions[bot]"
64+
git config user.email "github-actions[bot]@users.noreply.github.com"
65+
git add pyproject.toml
66+
git commit -m "chore(release): ${{ steps.bump.outputs.version }}"
67+
git tag "v${{ steps.bump.outputs.version }}"
68+
git push origin main --tags
69+
70+
- name: Build package
71+
run: |
72+
python -m pip install build
73+
python -m build
74+
75+
- name: Publish to PyPI
76+
env:
77+
TWINE_USERNAME: __token__
78+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
79+
run: |
80+
python -m pip install twine
81+
twine upload dist/*

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ wheels/
2323
share/python-wheels/
2424
*.egg-info/
2525
.installed.cfg
26+
*.egg-info
2627
*.egg
2728
MANIFEST
2829

scripts/test-template.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Test the template customization process
5+
# Creates a sibling directory, copies files, customizes, runs tox
6+
7+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
REPO_DIR="$(dirname "$SCRIPT_DIR")"
9+
TEST_DIR="${REPO_DIR}/../test-template-creation"
10+
11+
echo "=== Template Test ==="
12+
echo "Source: $REPO_DIR"
13+
echo "Test dir: $TEST_DIR"
14+
15+
# Cleanup function
16+
cleanup() {
17+
if [[ -d "$TEST_DIR" ]]; then
18+
echo "Cleaning up $TEST_DIR"
19+
rm -rf "$TEST_DIR"
20+
fi
21+
}
22+
trap cleanup EXIT
23+
24+
# Remove any existing test directory
25+
cleanup
26+
27+
# Create test directory and copy files (excluding .git, __pycache__, etc.)
28+
echo "Creating test directory..."
29+
mkdir -p "$TEST_DIR"
30+
rsync -a --exclude='.git' --exclude='__pycache__' --exclude='*.pyc' \
31+
--exclude='.tox' --exclude='.venv' --exclude='dist' --exclude='*.egg-info' \
32+
"$REPO_DIR/" "$TEST_DIR/"
33+
34+
cd "$TEST_DIR"
35+
36+
# Customization: rename placeholder/ to testcompany/
37+
echo "Renaming placeholder/ to testcompany/..."
38+
mv placeholder testcompany
39+
40+
# Update pyproject.toml
41+
echo "Updating pyproject.toml..."
42+
sed -i 's/name = "placeholder-my-plugin"/name = "testcompany-my-plugin"/' pyproject.toml
43+
sed -i 's|"placeholder"|"testcompany"|g' pyproject.toml
44+
45+
# Update imports in Python files
46+
echo "Updating imports..."
47+
find testcompany -name "*.py" -exec sed -i 's/from placeholder/from testcompany/g' {} \;
48+
find testcompany -name "*.py" -exec sed -i 's/import placeholder/import testcompany/g' {} \;
49+
50+
# Update test files if any reference placeholder
51+
find . -path ./testcompany -prune -o -name "*.py" -exec sed -i 's/from placeholder/from testcompany/g' {} \;
52+
find . -path ./testcompany -prune -o -name "*.py" -exec sed -i 's/import placeholder/import testcompany/g' {} \;
53+
54+
# Run tox using uvx (runs in temporary environment, no install needed)
55+
echo "Running tox..."
56+
uvx --with tox-uv tox
57+
58+
echo "=== Template Test PASSED ==="

0 commit comments

Comments
 (0)