From 3a8ce8678cbb875797141e72077da071cedd53e6 Mon Sep 17 00:00:00 2001 From: Scott Leggett Date: Tue, 12 Dec 2023 17:10:54 +0800 Subject: [PATCH 1/4] fix: configure the binary name in GoReleaser config Otherwise the binary name is set to the _project_ name, not the name of the directory of main. --- .goreleaser.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.goreleaser.yml b/.goreleaser.yml index 92b9929..c53b41c 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,5 +1,6 @@ builds: - main: ./cmd/go-cli-github + binary: go-cli-github ldflags: - > -s -w From fa7fba8b7ad61e72763f25f844ff12c3c7bccc5b Mon Sep 17 00:00:00 2001 From: Scott Leggett Date: Tue, 12 Dec 2023 17:12:03 +0800 Subject: [PATCH 2/4] chore: improve README --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index fb15411..10f2b62 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Go CLI Github +# Go CLI GitHub [![Release](https://github.com/smlx/go-cli-github/actions/workflows/release.yaml/badge.svg)](https://github.com/smlx/go-cli-github/actions/workflows/release.yaml) [![Coverage](https://coveralls.io/repos/github/smlx/go-cli-github/badge.svg?branch=main)](https://coveralls.io/github/smlx/go-cli-github?branch=main) @@ -26,16 +26,16 @@ It also automatically builds and tests your code using [GitHub Actions](https:// ## How to use -First set up the Github repo +First set up the GitHub repo -1. Create a new empty Github repository. +1. Create a new empty GitHub repository. Then push some code to main: 1. Install [gonew](https://go.dev/blog/gonew) and run this command, replacing the last argument with the name of your new module: ```bash - gonew github.com/smlx/go-cli-github github.com/smlx/newproject + gonew github.com/smlx/go-cli-github@main github.com/smlx/newproject ``` 1. Create the git repo and push to `main` (which will become the default branch): @@ -46,7 +46,7 @@ Then push some code to main: git branch -M main git remote add origin git@github.com:smlx/newproject.git git add . - git commit -a + git commit -am 'chore: create repository from template' git push -u origin main ``` @@ -56,21 +56,21 @@ Then customize the code for your repository: 1. Update the code for your project: + * rename `cmd/go-cli-github` to `cmd/$YOUR_COMMAND` * rename `deploy/go-cli-github` to `deploy/$YOUR_COMMAND` * update `deploy/$YOUR_COMMAND/Dockerfile` - * rename `cmd/go-cli-github` to `cmd/$YOUR_COMMAND` - * update module in `cmd/$YOUR_COMMAND/*.go`, `internal/server/serve_test.go` + * update `.github/workflows/build.yaml`, replacing `go-cli-github` with `$YOUR_COMMAND`. * update `.goreleaser.yml` to build `cmd/$YOUR_COMMAND` * update the links at the top of the README - * update the `build`, `release`, and `tag-to-release` workflows, replacing `go-cli-github` with `$YOUR_COMMAND`. 1. Commit and push: ```bash - git commit -a + git add . + git commit -am 'chore: update template for new project' git push -u origin setup ``` -1. Open a PR, ensure all the actions are green, then merge the PR. +1. Open a PR, wait until all the checks go green, then merge the PR. Configure the repository: From 8841dc4aec4ff0cf13ef439f94b56f855e860cc9 Mon Sep 17 00:00:00 2001 From: Scott Leggett Date: Tue, 12 Dec 2023 17:32:32 +0800 Subject: [PATCH 3/4] fix: build action --- .github/workflows/build.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 18ffdba..253315e 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -39,6 +39,7 @@ jobs: uses: docker/metadata-action@31cebacef4805868f9ce9a0cb03ee36c32df2ac4 # v5.3.0 with: images: ghcr.io/${{ github.repository }}/${{ matrix.binary }} + - run: echo "REPO_NAME=$(basename ${{ github.repository }})" >> "$GITHUB_ENV" - name: Build and push ${{ matrix.binary }} container image if: github.actor != 'dependabot[bot]' uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5.1.0 @@ -47,4 +48,4 @@ jobs: tags: ${{ steps.docker_metadata.outputs.tags }} labels: ${{ steps.docker_metadata.outputs.labels }} file: deploy/${{ matrix.binary }}/Dockerfile - context: dist/${{ matrix.binary }}_linux_amd64_v1 + context: dist/${{ env.REPO_NAME }}_linux_amd64_v1 From a21bb5e413a8b329acb46317c3177f10fcb453d6 Mon Sep 17 00:00:00 2001 From: Scott Leggett Date: Tue, 12 Dec 2023 17:38:24 +0800 Subject: [PATCH 4/4] fix: remove unnecessary instructions --- README.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/README.md b/README.md index 10f2b62..b84e99e 100644 --- a/README.md +++ b/README.md @@ -83,16 +83,8 @@ Configure the repository: 1. Go to repository Settings > Code security and analysis, and enable: - * Dependabot alerts - * Dependabot security updates - * Secret scanning - * Push protection * Private vulnerability reporting -1. Go to repository Settings > Actions > General: - - * Set Workflow permissions to "Read repository contents and package permissions" - 1. Go to repository Settings > Rules > Rulesets, and import the `protect-default-branch.json` ruleset. 1. That's it.