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
81 changes: 37 additions & 44 deletions .github/workflows/auto-check-workflow.yml
Original file line number Diff line number Diff line change
@@ -1,72 +1,65 @@
name: Initialise Repo
name: Initialise Repository

on:
push:
branches:
# NB: its difficult to get the default branch dynamically in
# push event, so it has been hardcoded.
# ${{ github.event.repository.default_branch }} does not
# work in this scenario.
#
- main
- main # first push triggers bootstrap

permissions:
contents: write

jobs:
run-script:
name: run script

# We will only run this action when this repository isn't the
# template repository
#
if: >-
${{ !github.event.repository.is_template }}

bootstrap:
# Only run for org repos and skip template repositories
if: ${{ github.repository_owner == 'snivilised' && !github.event.repository.is_template }}
runs-on: ubuntu-latest

steps:
- name: Configure Git
run: |
git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
shell: bash

- name: Checkout
# Checkout repository using default github.token (always safe)
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}

- name: Run script
# Configure Git author
- name: Configure Git
run: |
go run ./scripts/automate-checklist.go
shell: bash
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"

- name: Go Format
run: |
go fmt ./...
shell: bash
# Install Go version specified in go.mod
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod

# Run automation script
- name: Run automation script
run: go run ./scripts/automate-checklist.go

- name: Go Mod Tidy
# Format code and tidy modules
- name: Format & tidy Go
run: |
go fmt ./...
go mod tidy
shell: bash

- name: Clean up redundant scripts
# Remove bootstrap/template-only files
- name: Clean up template scripts
run: |
rm -fv .github/workflows/auto-check-workflow.yml 2>/dev/null
rm -fv ./scripts/automate-checklist.sh 2>/dev/null
rm -fv ./scripts/automate-checklist.go 2>/dev/null
shell: bash
rm -fv .github/workflows/auto-check-workflow.yml
rm -fv ./scripts/automate-checklist.go
rm -fv ./scripts/automate-checklist.sh

- name: Add files and commit changes
# Commit & push changes using org PAT (no linter warning)
- name: Commit & push changes
env:
ORG_PAT: ${{ secrets.AUTOMATION_PAT }}
run: |
git add .
if [ -n "$(git status --porcelain)" ]; then
git commit -m "chore(gh-actions): apply auto-check edits"
git push -u origin ${{ github.event.repository.default_branch }}
git commit -m "chore(repo): bootstrap repository"
# Update remote URL to include PAT for push
git remote set-url origin https://x-access-token:${ORG_PAT}@github.com/${GITHUB_REPOSITORY}.git
git push origin HEAD:${{ github.event.repository.default_branch }}
else
echo "No changes to commit"
fi
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
],
"cSpell.words": [
"astrolib",
"autocheck",
"bodyclose",
"cmds",
"cobrass",
Expand Down
50 changes: 23 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<!-- MarkDownLint-disable MD028 -->

<p align="left">
<a href="https://go.dev"><img src="resources/images/go-logo-light-blue.png" width="50" /></a>
<a href="https://go.dev"><img src="resources/images/go-logo-light-blue.png" alt="Go logo" width="50" /></a>
</p>

## 🔰 Introduction
Expand All @@ -38,8 +38,8 @@ This project is a template to aid in the startup of Go cli applications.
## 🎀 Features

<p align="left">
<a href="https://onsi.github.io/ginkgo/"><img src="https://onsi.github.io/ginkgo/images/ginkgo.png" width="100" /></a>
<a href="https://onsi.github.io/gomega/"><img src="https://onsi.github.io/gomega/images/gomega.png" width="100" /></a>
<a href="https://onsi.github.io/ginkgo/"><img src="https://onsi.github.io/ginkgo/images/ginkgo.png" alt="Ginkgo logo" width="100" /></a>
<a href="https://onsi.github.io/gomega/"><img src="https://onsi.github.io/gomega/images/gomega.png" alt="Gomega logo" width="100" /></a>
</p>

+ unit testing with [Ginkgo](https://onsi.github.io/ginkgo/)/[Gomega](https://onsi.github.io/gomega/)
Expand All @@ -53,39 +53,31 @@ By using this template, there is no need to use the cobra-cli to scaffold your a

### 📝 Checklist of required changes

The following is list of actions that must be performed before using this template. Most of the changes concern changing the name `Arcadia` to the name of the new application. As the template is instantiated from github, the new name will automatically replace the top level directory name, that being ___arcadia___.
The following is list of actions that must be performed before using this template. Most of the changes concern changing the name `Arcadia` to the name of the new application. As the template is instantiated from github, the new name will automatically replace the top level directory name, that being ___arcadia___. However, there are 2 situations at hand:

➕ The following descriptions use owner name ___pandora___ and repo name ___maestro___ as an example. That is to say the client has instantiated ___arcadia___ template into github at url _github.com/pandora/maestro_

#### 🤖 Automated changes

Automated via `automate-checklist.sh` script. When the user instantiates the repo, a github actions workflow is executed which applies changes to the clients repo automatically. The following description describes the changes that are applied on the user's behalf and the workflow is automatically deleted. However, there are other changes that should be made. These compose the manual checklist and should be heeded by the user.

##### ✅ Rename import statements

+ `rename import paths`: global search and replace ___snivilised/arcadia___ to ___pandora/maestro___
1) target repo is owned by the snivilised organisation: the changes required will be made automatically after the repo has been created from the template WITHOUT user intervention

##### ✅ Identifiers
2) target repo is NOT owned by snivilised, therefore user action is required after being cloned. Follow this sequence of steps:

+ `change arcadiaTemplData`: perform a refactor rename (_Rename Symbol_) to ___maestroTemplData___
+ after cloning the repo, run the task, autocheck:

##### ✅ Global search replace arcadia to maestro
```
$ task autocheck
```

Will take care of the following required changes:
This will result in various changes being made to the project. If you are using the pull-request model, then please make sure that you are on a feature branch before running the autocheck task. You can then check-in, then push the changes as per normal:

+ `change module name`: update the module name inside the .mod file in the root directory
+ `change ApplicationName`: modify to reflect the new application name. This application name is incorporated into the name of any translation files to be loaded.
+ `update BINARY_NAME`: Inside _Taskfile.yml_, change the value of ___BINARY_NAME___ to the name of the client application.
+ `update github action workflows`: change the name of the workflows in the .yaml files to replace ___Arcadia___ to ___Maestro___ (note the change of case, if this is important).
```
$ git add .
$ git commit -m "chore: initialise repository from template"
$ git push
```

##### ✅ Localisation/Internationalisation

+ `change the names of the translation files`: eg change ___arcadia.active.en-GB.json___ to ___maestro.active.en-GB.json___
➕ The following descriptions use owner name ___pandora___ and repo name ___maestro___ as an example. That is to say the client has instantiated ___arcadia___ template into github at url _github.com/pandora/maestro_

##### ✅ Miscellaneous automated changes
#### 🤖 Automated changes

+ `reset version files`: this is optional because the release process automatically updates the version number according to the tag specified by the user, but will initially contain the version number which reflects the current value of arcadia at the time the client project is instantiated.
+ `change SOURCE_ID`: to "github.com/pandora/maestro"
Automated via `./scripts/automate-checklist.go` script. This is invoked by the autocheck task. You can look at the contents of this file, before running the autocheck task, doing so, you'll gain an understanding of the changes that will be implemented, if you're so inclined. After the task is run, this go script will be deleted.

#### 🖐 Manual changes

Expand All @@ -99,6 +91,10 @@ The following documents manual changes required. Manual checklist:

+ `review bootstrap.go`: this will need to be modified to invoke creation of any custom commands. The `execute` method of __bootstrap__ should be modified to invoke command builder. Refer to the `widget` command to see how this is done.

#### ☑️ Taskfile change

+ Remove the autocheck task from Taskfile.yml

#### ☑️ Github changes

Unfortunately, github doesn't copy over the template project's settings to the client project, so these changes must be made manually:
Expand Down
12 changes: 12 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,18 @@ tasks:
- go tool cover -html=./coverage.out -o {{.COVER_HTML_PATH}}
- open {{.COVER_HTML_PATH}}

# === auto-check ===========================================

autocheck:
desc: Initialise repository from template
cmds:
- go run ./scripts/automate-checklist.go
- go fmt ./...
- go mod tidy
- rm -f .github/workflows/auto-check-workflow.yml
- rm -f scripts/automate-checklist.go
- rm -f scripts/automate-checklist.sh

# === i18n =================================================

clear:
Expand Down
Loading