From a6f88d8f8a9618c0cd2ace2b474bf996eebca048 Mon Sep 17 00:00:00 2001 From: Guido Zuidhof Date: Sat, 20 Jul 2024 20:38:39 +0200 Subject: [PATCH 1/3] Fix goreleaser, readme tweaks --- .github/workflows/goreleaser.yml | 10 +++++----- .gitignore | 2 ++ README.md | 12 +++++------- goreleaser.yml | 2 ++ 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml index 695ef10..7422093 100644 --- a/.github/workflows/goreleaser.yml +++ b/.github/workflows/goreleaser.yml @@ -9,18 +9,18 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v5 with: go-version: "^1.18" - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v2 + uses: goreleaser/goreleaser-action@v6 with: distribution: goreleaser - version: latest - args: release --rm-dist + version: '~> v2' + args: release --clean env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index aab7caf..e997001 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,5 @@ examples/time examples/tygo examples/http + +dist/ \ No newline at end of file diff --git a/README.md b/README.md index dd67c2c..58a70d0 100644 --- a/README.md +++ b/README.md @@ -4,15 +4,12 @@ Tygo is a tool for generating Typescript typings from Golang source files that j It preserves comments, understands constants and also supports non-struct `type` expressions. It's perfect for generating equivalent types for a Golang REST API to be used in your front-end codebase. -**🚀 Now supports Golang 1.18 generic types, struct inheritance** +**🚀 Supports Golang 1.18 generic types and struct inheritance** ## Installation ```shell -# Go >= 1.17 go install github.com/gzuidhof/tygo@latest -# Go < 1.17: -go install github.com/gzuidhof/tygo ``` ## Example @@ -391,6 +388,7 @@ export interface ABCD< ## YAML support Tygo supports generating typings for YAML-serializable objects that can be understood by Go apps. + By default, Tygo will respect `yaml` Go struct tags, in addition to `json`, but it will not apply any transformations to untagged fields. However, the default behavior of the popular `gopkg.in/yaml.v2` package for Go structs without tags is to downcase the struct field names. To emulate this behavior, one can use the `flavor` configuration option: @@ -420,10 +418,10 @@ export interface Foo { ## Related projects -- [**typescriptify-golang-structs**](https://github.com/tkrajina/typescriptify-golang-structs): Probably the most popular choice. The downside of this package is that it relies on reflection rather than parsing, which means that certain things can't be kept such as comments without adding a bunch of tags to your structs. The CLI generates a Go file which is then executed and reflected on, and its library requires you to manually specify all types that should be converted. -- [**go2ts**](https://github.com/StirlingMarketingGroup/go2ts): A transpiler with a web interface, this project was based off this project. It's perfect for quick one-off transpilations. There is no CLI, no support for `const` and there are no ways to customize the output. +- [**typescriptify-golang-structs**](https://github.com/tkrajina/typescriptify-golang-structs): Probably the most popular choice. The downside of this package is that it relies on reflection rather than parsing, which means that certain things can't be kept such as comments without adding a bunch of tags to your structs. The CLI generates a Go file which is then executed and reflected on. The library requires you to manually specify all types that should be converted. +- [**go2ts**](https://github.com/StirlingMarketingGroup/go2ts): A transpiler with a web interface, this project can be seen as an evolution of this project. It's perfect for quick one-off transpilations. There is no CLI, no support for `const` and there are no ways to customize the output. -If this repository was useful for your project, consider leaving a star. +**If `tygo` is useful for your project, consider leaving a star.** ## License diff --git a/goreleaser.yml b/goreleaser.yml index 445415a..6f459e9 100644 --- a/goreleaser.yml +++ b/goreleaser.yml @@ -1,3 +1,4 @@ +version: 2 project_name: tygo builds: - binary: tygo @@ -7,6 +8,7 @@ builds: - linux goarch: - amd64 + - arm64 ldflags: - -s -w -X github.com/gzuidhof/tygo/cmd.version={{.Version}} -X github.com/gzuidhof/tygo/cmd.commit={{.Commit}} -X github.com/gzuidhof/tygo/cmd.commitDate={{.CommitDate}} archives: From 587e78706176c52b70d0c0c572e70d67a5f64131 Mon Sep 17 00:00:00 2001 From: Guido Zuidhof Date: Sun, 21 Jul 2024 00:07:50 +0200 Subject: [PATCH 2/3] Add permissions field to goreleaser config --- .github/workflows/goreleaser.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml index 7422093..f78b786 100644 --- a/.github/workflows/goreleaser.yml +++ b/.github/workflows/goreleaser.yml @@ -3,6 +3,10 @@ name: goreleaser on: pull_request: push: + + +permissions: + contents: write jobs: goreleaser: From e60ba266e99a4fcbcb72be1cb7a37c779c2803ec Mon Sep 17 00:00:00 2001 From: Guido Zuidhof Date: Sun, 21 Jul 2024 00:11:04 +0200 Subject: [PATCH 3/3] Build snapshot for non-releases --- .github/workflows/goreleaser.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml index f78b786..573d291 100644 --- a/.github/workflows/goreleaser.yml +++ b/.github/workflows/goreleaser.yml @@ -11,7 +11,11 @@ permissions: jobs: goreleaser: runs-on: ubuntu-latest + env: + flags: "" steps: + - if: ${{ !startsWith(github.ref, 'refs/tags/v') }} + run: echo "flags=--snapshot" >> $GITHUB_ENV # See https://github.com/goreleaser/goreleaser-action/issues/387 - name: Checkout uses: actions/checkout@v4 with: @@ -25,6 +29,6 @@ jobs: with: distribution: goreleaser version: '~> v2' - args: release --clean + args: release --clean ${{ env.flags }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}