Skip to content

Update template_setup.yml #27

Update template_setup.yml

Update template_setup.yml #27

# From https://raw.githubusercontent.com/simonw/python-lib-template-repository/main/.github/workflows/setup.yml
name: Execute template to populate repository
on:
push:
workflow_dispatch:
permissions:
actions: write
contents: write
jobs:
setup-repo:
if: ${{ !endsWith(github.repository, '-auto-template') }}
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 $GITHUB_WORKSPACE --no-input \
lib_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)" \
author_email="${{ github.event.pusher.email }}" \
github_id=$GITHUB_REPOSITORY
popd
# Move generated content to root directory of repo
rm -r tests
rm -r hooks
mv /tmp/$REPO_NAME/* .
# And hidden settings files:
mv /tmp/$REPO_NAME/.gitignore .
mv /tmp/$REPO_NAME/.devcontainer .
mv /tmp/$REPO_NAME/.vscode .
# Delete the template related workflow and the cookiecutter files
rm .github/workflows/template_setup.yml
rm .github/workflows/template_test.yml
rm -r "{{cookiecutter.hyphenated}}"
rm -r cookiecutter.json
rm pytest.ini
rm requirements.dev.txt
- name: Force push new repo contents
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "Initial library structure"
push_options: --force