This repository has been archived by the owner on Dec 12, 2024. It is now read-only.
generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [Chore] Add swag fmt to `mage spec` * Keep CI in sync with toolchain * We're not going crazy * Remove unnecessary installation * typo * moved spec step after git checkout * Do not fetch history * fetch - but without history * setting ref * Bump down checkout action * v3 with repository * changing the user * use PAT for publish of swagger docs * use publish action instead of script * using a separate workflow * pr trigger * syntax * helps to checkout the code * simplify * trying push * checkout * adding in github token reference * trying the previoous approach with a twist * push as script * trying to push back to the repo * set token like this * set token * set token * set token * expand variables helps * using clone url * push to HEAD * cleaning up full url * oh no now using sed * giving up - this will generate doc if needed on push to main * can't push to protected branch so have a swagger one Co-authored-by: Andres Uribe Gonzalez <[email protected]> Co-authored-by: Andres Uribe <[email protected]> Co-authored-by: Gabe <[email protected]>
- Loading branch information
1 parent
a3d5e1b
commit 56ec92c
Showing
4 changed files
with
48 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,43 +29,6 @@ jobs: | |
- name: Check Vulnerabilities | ||
run: mage -v vuln | ||
|
||
generate-spec: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: fetch history | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.19.4 | ||
cache: true | ||
|
||
- name: Install Mage | ||
run: go install github.com/magefile/mage | ||
|
||
- name: Update to latest spec | ||
shell: bash | ||
run: | | ||
export PATH=$PATH:$(go env GOPATH)/bin | ||
go install github.com/swaggo/swag/cmd/[email protected] | ||
mage spec | ||
- name: Push generated spec file | ||
uses: actions/checkout@v3 | ||
- run: | | ||
git config --global user.name "${GITHUB_ACTOR}" | ||
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com" | ||
if (git diff --shortstat | grep '[0-9]'); then \ | ||
git add .; \ | ||
git commit -m "gen OpenAPI Spec by github-actions"; \ | ||
git push | ||
fi | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: swagger-doc | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
|
||
generate-swagger: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.19.4 | ||
cache: true | ||
|
||
- name: Install Mage | ||
run: go install github.com/magefile/mage | ||
|
||
- name: Update spec and push generated spec file | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
ref: ${{ github.event.pull_request.head.ref }} | ||
repository: ${{ github.event.pull_request.head.repo.full_name }} | ||
- run: | | ||
export PATH=$PATH:$(go env GOPATH)/bin | ||
mage spec | ||
git config user.name github-actions | ||
git config user.email [email protected] | ||
if (git diff --shortstat | grep '[0-9]'); then \ | ||
git checkout -B main_swagger | ||
git add .; \ | ||
git commit -m "gen OpenAPI Spec by github-actions"; \ | ||
git push | ||
fi | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,7 +108,11 @@ func Integration() error { | |
// Spec generates an OpenAPI spec yaml based on code annotations. | ||
func Spec() error { | ||
swagCommand := "swag" | ||
if err := installIfNotPresent(swagCommand, "github.com/swaggo/swag/cmd/swag@latest"); err != nil { | ||
if err := installIfNotPresent(swagCommand, "github.com/swaggo/swag/cmd/[email protected]"); err != nil { | ||
logrus.Fatal(err) | ||
return err | ||
} | ||
if err := sh.Run(swagCommand, "fmt", "-d", "pkg/server/router"); err != nil { | ||
logrus.Fatal(err) | ||
return err | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters