Initial commit

This commit is contained in:
Simon Willison 2022-11-21 17:56:46 -08:00 committed by GitHub
commit ac7aaab22d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 174 additions and 0 deletions

47
.github/workflows/publish.yml vendored Normal file
View file

@ -0,0 +1,47 @@
name: Publish Python Package
on:
release:
types: [created]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: '**/setup.py'
- name: Install dependencies
run: |
pip install -e '.[test]'
- name: Run tests
run: |
pytest
deploy:
runs-on: ubuntu-latest
needs: [test]
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.10'
cache: pip
cache-dependency-path: '**/setup.py'
- name: Install dependencies
run: |
pip install setuptools wheel twine build
- name: Publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: |
python -m build
twine upload dist/*

71
.github/workflows/setup.yml vendored Normal file
View file

@ -0,0 +1,71 @@
name: Execute template to populate repository
on:
push:
workflow_dispatch:
jobs:
setup-repo:
if: ${{ github.repository != 'simonw/click-app-template-repository' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
ref: ${{ github.head_ref }}
- name: Install cookiecutter
run: pip3 install cookiecutter
- uses: actions/github-script@v4
id: fetch-repo-and-user-details
with:
script: |
const query = `query($owner:String!, $name:String!) {
repository(owner:$owner, name:$name) {
name
description
owner {
login
... on User {
name
}
... on Organization {
name
}
}
}
}`;
const variables = {
owner: context.repo.owner,
name: context.repo.repo
}
const result = await github.graphql(query, variables)
console.log(result)
return result
- name: Rebuild contents using cookiecutter
env:
INFO: ${{ steps.fetch-repo-and-user-details.outputs.result }}
run: |
export REPO_NAME=$(echo $INFO | jq -r '.repository.name')
# Run cookiecutter
pushd /tmp
cookiecutter gh:simonw/click-app --no-input \
app_name=$REPO_NAME \
description="$(echo $INFO | jq -r .repository.description)" \
github_username="$(echo $INFO | jq -r .repository.owner.login)" \
author_name="$(echo $INFO | jq -r .repository.owner.name)"
popd
# Move generated content to root directory of repo
mv /tmp/$REPO_NAME/* .
# And .gitignore too:
mv /tmp/$REPO_NAME/.gitignore .
# Delete the setup.yml workflow, it has served its purpose
rm .github/workflows/setup.yml
- name: Force push new repo contents
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "Initial library structure"
push_options: --force

29
.github/workflows/test.yml vendored Normal file
View file

@ -0,0 +1,29 @@
name: Test
on:
push:
workflow_dispatch:
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
if: hashFiles('setup.py')
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: '**/setup.py'
- name: Install dependencies
if: hashFiles('setup.py')
run: |
pip install -e '.[test]'
- name: Run tests
if: hashFiles('setup.py')
run: |
pytest