Skip to content

Create or Update Repo #16

Create or Update Repo

Create or Update Repo #16

name: Create or Update Repo
on:
workflow_dispatch:
inputs:
repo_name:
description: 'Name of the Repo to Create/Update.'
required: true
type: string
is_public_repo:
description: 'Make Repo Public (Default: Private).'
required: true
default: false
type: boolean
repo_description:
description: 'Repo Description. If not provided, default is used.'
required: false
default: 'This is a generated repository using the `python-cookiecutter-template`.'
type: string
package_import_name:
description: 'Package Import Name, used in generated project. E.g. `from <pkg_name> import <module_name>`'
required: true
type: string
upsert_pypi_secrets:
description: 'Upsert PyPI Secrets (Default: false).'
required: true
default: false
type: boolean
populate_from_template:
description: 'Populate from Template (Default: true).'
required: true
default: true
type: boolean
# Common environment variables used by all jobs
env:
GH_TOKEN: ${{ secrets.PERSONAL_GITHUB_TOKEN }}
AUTHOR_EMAIL: "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com"
GITHUB_USERNAME: ${{ github.actor}}
REPO_NAME: ${{ github.event.inputs.repo_name }}
jobs:
create-repository-if-not-exists:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set Author Name
run: |
AUTHOR_NAME="$(gh api /users/${{ github.actor }} | jq .name -r)"
echo "AUTHOR_NAME=$AUTHOR_NAME" >> "$GITHUB_ENV"
- name: Configure Git User
run: |
git config --global user.name "${{ env.AUTHOR_NAME }}"
git config --global user.email "${{ env.AUTHOR_EMAIL }}"
- name: Create Repo if not exists
env:
IS_PUBLIC_REPO: ${{ github.event.inputs.is_public_repo }}
REPO_DESCRIPTION: ${{ github.event.inputs.repo_description }}
run: |
bash -x run.sh create-repository-if-not-exists
configure-repository:
needs:
- create-repository-if-not-exists
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set Author Name
run: |
AUTHOR_NAME="$(gh api /users/${{ github.actor }} | jq .name -r)"
echo "AUTHOR_NAME=$AUTHOR_NAME" >> "$GITHUB_ENV"
- name: Configure Git User
run: |
git config --global user.name "$AUTHOR_NAME"
git config --global user.email "$AUTHOR_EMAIL"
- name: Configure Repository
env:
UPSERT_PYPI_SECRETS: ${{ github.event.inputs.upsert_pypi_secrets }}
TEST_PYPI_TOKEN: ${{ secrets.TEST_PYPI_TOKEN }}
PROD_PYPI_TOKEN: ${{ secrets.PROD_PYPI_TOKEN }}
run: |
bash -x run.sh configure-repository
open-pull-request-with-generated-project:
name: Open Pull Request with Generated Project - Populate from Template
if: ${{ github.event.inputs.populate_from_template == 'true'}}
needs:
- create-repository-if-not-exists
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set Author Name
run: |
AUTHOR_NAME="$(gh api /users/${{ github.actor }} | jq .name -r)"
echo "AUTHOR_NAME=$AUTHOR_NAME" >> "$GITHUB_ENV"
- name: Configure Git User
run: |
git config --global user.name "$AUTHOR_NAME"
git config --global user.email "$AUTHOR_EMAIL"
- name: Open Pull Request
env:
PACKAGE_IMPORT_NAME: ${{ github.event.inputs.package_import_name }}
run: |
bash -x run.sh open-pull-request-with-generated-project