Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 45 additions & 5 deletions .github/workflows/UpdateReadme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,55 @@ on:
- cron: '0 6 * * 1' # every Monday at 06:00 UTC
workflow_dispatch: # manual trigger

env:
DOC_URL_OVERRIDE: "" # optional, e.g. https://my-domain.example/MyApp.jl
CITATION_BADGE: "" # optional, e.g. "[![DOI](https://zenodo.org/badge/....svg)](https://zenodo.org/doi/....)"
ASSIGNEE: "" # optional, GitHub username(s), comma-separated

jobs:
check-template:
runs-on: ubuntu-latest
outputs:
has_template: ${{ steps.check.outputs.has_template }}
repo_name: ${{ steps.meta.outputs.repo_name }}
package_name: ${{ steps.meta.outputs.package_name }}
doc_url: ${{ steps.meta.outputs.doc_url }}
citation_badge: ${{ steps.config.outputs.citation_badge }}
assignee: ${{ steps.config.outputs.assignee }}
steps:
- name: Checkout repo
uses: actions/checkout@v5

- name: Compute repository metadata
id: meta
shell: bash
run: |
repo_name="${GITHUB_REPOSITORY}" # owner/repo
repo_owner="${GITHUB_REPOSITORY%%/*}" # owner
repo_basename="${GITHUB_REPOSITORY#*/}" # repo
package_name="${repo_basename%.jl}" # strip .jl suffix if present

if [[ -n "${DOC_URL_OVERRIDE}" ]]; then
doc_url="${DOC_URL_OVERRIDE}"
else
if [[ "${repo_owner}" == "control-toolbox" ]]; then
doc_url="https://control-toolbox.org/${repo_basename}"
else
doc_url="https://${repo_owner}.github.io/${repo_basename}"
fi
fi

echo "repo_name=${repo_name}" >> "$GITHUB_OUTPUT"
echo "package_name=${package_name}" >> "$GITHUB_OUTPUT"
echo "doc_url=${doc_url}" >> "$GITHUB_OUTPUT"

- name: Expose config variables as outputs
id: config
shell: bash
run: |
echo "citation_badge=${CITATION_BADGE}" >> "$GITHUB_OUTPUT"
echo "assignee=${ASSIGNEE}" >> "$GITHUB_OUTPUT"

- name: Check for README.template.md
id: check
shell: bash
Expand All @@ -32,9 +72,9 @@ jobs:
with:
template_file: README.template.md
output_file: README.md
package_name: CTAppTemplate # package for INSTALL.md
repo_name: control-toolbox/CTAppTemplate.jl # repository for CONTRIBUTING.md links
doc_url: https://control-toolbox.org/CTAppTemplate.jl
citation_badge: "[![DOI](https://zenodo.org/badge/541187171.svg)](https://zenodo.org/doi/10.5281/zenodo.16753152)" # example, can be empty
assignee: "ocots"
package_name: ${{ needs.check-template.outputs.package_name }} # package for INSTALL.md
repo_name: ${{ needs.check-template.outputs.repo_name }} # repository for CONTRIBUTING.md links
doc_url: ${{ needs.check-template.outputs.doc_url }}
citation_badge: ${{ needs.check-template.outputs.citation_badge }}
assignee: ${{ needs.check-template.outputs.assignee }}
secrets: inherit
84 changes: 84 additions & 0 deletions .github/workflows/setup-repo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Setup Repository

on:
workflow_dispatch:

jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Get repository metadata
id: meta
run: |
repo_name="${{ github.repository }}"
package_name=$(basename "${{ github.repository }}" .jl)
echo "repo_name=$repo_name" >> $GITHUB_OUTPUT
echo "package_name=$package_name" >> $GITHUB_OUTPUT
echo "actor=${{ github.actor }}" >> $GITHUB_OUTPUT

- name: Get author info
id: author
run: |
USER_INFO=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/users/${{ github.actor }}")
USER_NAME=$(echo "$USER_INFO" | jq -r '.name // ""')
USER_EMAIL=$(echo "$USER_INFO" | jq -r '.email // ""')
if [[ -n "$USER_NAME" && -n "$USER_EMAIL" ]]; then
AUTHOR_STRING="[\"$USER_NAME <$USER_EMAIL>\"]"
elif [[ -n "$USER_NAME" ]]; then
AUTHOR_STRING="[\"$USER_NAME\"]"
else
AUTHOR_STRING="[\"${{ github.actor }}\"]"
fi
echo "author_string=$AUTHOR_STRING" >> $GITHUB_OUTPUT

- name: Run setup script
run: |
# 1. Replace repo name and package name
OLD_REPO="control-toolbox/CTAppTemplate.jl"
NEW_REPO="${{ steps.meta.outputs.repo_name }}"
OLD_PACKAGE="CTAppTemplate"
NEW_PACKAGE="${{ steps.meta.outputs.package_name }}"

echo "Replacing '$OLD_REPO' with '$NEW_REPO'"
find . -type f -not -path "./.git/*" -exec sed -i "s|$OLD_REPO|$NEW_REPO|g" {} +

echo "Replacing '$OLD_PACKAGE' with '$NEW_PACKAGE'"
find . -type f -not -path "./.git/*" -exec sed -i "s|$OLD_PACKAGE|$NEW_PACKAGE|g" {} +

# 2. Rename source file
echo "Renaming src/$OLD_PACKAGE.jl to src/$NEW_PACKAGE.jl"
if [ -f "src/$OLD_PACKAGE.jl" ]; then
mv src/$OLD_PACKAGE.jl src/$NEW_PACKAGE.jl
else
echo "Warning: src/$OLD_PACKAGE.jl not found, skipping rename."
fi

# 3. Update metadata in Project.toml
echo "Updating Project.toml"
NEW_UUID=$(uuidgen)
sed -i "s/^uuid = .*/uuid = \"$NEW_UUID\"/" Project.toml
sed -i "s|^authors = .*|authors = ${{ steps.author.outputs.author_string }}|" Project.toml

# 4. Update assignees
echo "Updating default assignees to '${{ steps.meta.outputs.actor }}'"
find .github/ISSUE_TEMPLATE -type f -name "*.md" -exec sed -i 's/assignees: ocots/assignees: ${{ steps.meta.outputs.actor }}/g' {} +
sed -i 's/assignees: ocots/assignees: ${{ steps.meta.outputs.actor }}/g' .github/workflows/AutoAssign.yml

- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
with:
commit-message: "feat: automate repository setup"
branch: "chore/auto-setup"
delete-branch: true
title: "Automate repository setup"
body: |
This PR automates the initial setup of the repository by:
- Replacing template names (`CTAppTemplate`, `control-toolbox/CTAppTemplate.jl`) with the new repository's name.
- Renaming the main source file.
- Generating a new UUID and updating the author in `Project.toml`.
- Setting the default assignee to the user who triggered this workflow.

Please review the changes and merge this PR to finalize the setup.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ Manifest.toml
**/Manifest.toml
# ...except the one inside docs/src/assets
!docs/src/assets/Manifest.toml

#
reports/
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ authors = ["Olivier Cots <olivier.cots@toulouse-inp.fr>"]
version = "0.1.0"

[compat]
julia = "1.11"
julia = "1.10"
Loading