From b0ac1282c0fccbb2ed6195b450c0fbca4fe1a342 Mon Sep 17 00:00:00 2001 From: Carlos A Becker Date: Wed, 30 Nov 2022 21:57:41 -0300 Subject: [PATCH] feat: first --- .github/workflows/nightly.yml | 126 +++++++++++++++++++++++++++ .gitignore | 3 + .goreleaser.yaml | 155 ++++++++++++++++++++++++++++++++++ Dockerfile | 3 + README.md | 17 ++++ go.mod | 3 + go.sum | 0 main.go | 7 ++ windows.dockerfile | 4 + 9 files changed, 318 insertions(+) create mode 100644 .github/workflows/nightly.yml create mode 100644 .gitignore create mode 100644 .goreleaser.yaml create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go create mode 100644 windows.dockerfile diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml new file mode 100644 index 0000000..d1d03f3 --- /dev/null +++ b/.github/workflows/nightly.yml @@ -0,0 +1,126 @@ +name: goreleaser-nightly + +on: + workflow_dispatch: + push: + tags: ['v*'] + +permissions: + contents: write + id-token: write + packages: write + +jobs: + prepare: + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} + env: + DOCKER_CLI_EXPERIMENTAL: "enabled" + steps: + - shell: bash + run: | + if test '${{ github.event_name }}' = "workflow_dispatch"; then + echo "flags=--nightly" >> $GITHUB_ENV + else + echo "flags=" >> $GITHUB_ENV + fi + case '${{ matrix.os }}' in + ubuntu-latest) + echo "goos=linux" >> $GITHUB_ENV + ;; + macos-latest) + echo "goos=darwin" >> $GITHUB_ENV + ;; + windows-latest) + echo "goos=windows" >> $GITHUB_ENV + ;; + esac + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: docker/setup-qemu-action@v1 + if: matrix.os == 'ubuntu-latest' + - uses: docker/setup-buildx-action@v1 + if: matrix.os == 'ubuntu-latest' + - name: ghcr-login + uses: docker/login-action@v1 + if: matrix.os != 'macos-latest' + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - uses: actions/setup-go@v3 + with: + go-version: 1.19 + cache: true + - shell: bash + run: | + echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_ENV + - id: cache + uses: actions/cache@v3 + with: + path: dist/${{ env.goos }} + key: ${{ env.goos }}-${{ env.sha_short }} + - uses: goreleaser/goreleaser-action@v3 + if: steps.cache.outputs.cache-hit != 'true' # do not run if cache hit + with: + distribution: goreleaser-pro + version: latest + args: release --rm-dist --split ${{ env.flags }} + env: + GITHUB_TOKEN: ${{ secrets.GH_PAT }} + GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} + release: + runs-on: ubuntu-latest + needs: prepare + env: + DOCKER_CLI_EXPERIMENTAL: "enabled" + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: docker/setup-qemu-action@v1 + - uses: docker/setup-buildx-action@v1 + - uses: sigstore/cosign-installer@v2.7.0 + - uses: anchore/sbom-action/download-syft@v0.12.0 + - name: ghcr-login + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - uses: actions/setup-go@v3 + with: + go-version: 1.19 + cache: true + + # copy the cashes from prepare + - shell: bash + run: | + echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_ENV + - uses: actions/cache@v3 + with: + path: dist/linux + key: linux-${{ env.sha_short }} + - uses: actions/cache@v3 + with: + path: dist/darwin + key: darwin-${{ env.sha_short }} + - uses: actions/cache@v3 + with: + path: dist/windows + key: windows-${{ env.sha_short }} + + + # release + - uses: goreleaser/goreleaser-action@v3 + if: steps.cache.outputs.cache-hit != 'true' # do not run if cache hit + with: + distribution: goreleaser-pro + version: latest + args: continue --merge + env: + GITHUB_TOKEN: ${{ secrets.GH_PAT }} + GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..db9e522 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +dist* + +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..bbe4468 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,155 @@ +# This is an example-real .goreleaser.yml file with some sensible defaults. +# Make sure to check the documentation at https://goreleaser.com +before: + hooks: + - go mod tidy +builds: +- targets: [go_first_class] + mod_timestamp: '{{ .CommitTimestamp }}' + flags: + # trims path + - -trimpath + ldflags: + # use commit date instead of current date as main.date + # only needed if you actually use those things in your main package, otherwise can be ignored. + - -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{ .CommitDate }} +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ incpatch .Version }}-next" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' + +nfpms: +- file_name_template: '{{ .ConventionalFileName }}' + homepage: https://goreleaser.com + description: Just another example + maintainer: Carlos Alexandro Becker + license: MIT + vendor: GoReleaser + bindir: /usr/bin + section: utils + formats: [apk, deb, rpm] + +release: + name_template: 'v{{ .Version }}' + footer: | + * * * + + GoReleaser logo + + Find example-reals and commented usage of all options in our [website](https://goreleaser.com/intro/). + Want to help? You can [sponsor](https://goreleaser.com/sponsors/),get a [Pro License](https://goreleaser.com/pro) or [contribute](https://goreleaser.com/contributing). + Also, feel free to reach out on [Discord](https://discord.gg/RGEBtg8vQ6) and [Twitter](https://twitter.com/goreleaser)! + + +nightly: + publish_release: true + keep_single_release: true + name_template: '{{ incminor .Version }}-nightly' + tag_name: nightly + + +dockers: +- image_templates: + - 'ghcr.io/caarlos0/goreleaser-pro-split-merge-example-real:v{{ .Version }}-amd64' + build_flag_templates: + - "--pull" + - "--label=org.opencontainers.image.description=Just an example-real" + - "--label=org.opencontainers.image.created={{.Date}}" + - "--label=org.opencontainers.image.name={{.ProjectName}}" + - "--label=org.opencontainers.image.revision={{.FullCommit}}" + - "--label=org.opencontainers.image.version={{.Version}}" + - "--label=org.opencontainers.image.source={{.GitURL}}" + - "--platform=linux/amd64" + use: buildx +- image_templates: + - 'ghcr.io/caarlos0/goreleaser-pro-split-merge-example-real:v{{ .Version }}-arm64' + build_flag_templates: + - "--pull" + - "--label=org.opencontainers.image.description=Just an example-real" + - "--label=org.opencontainers.image.created={{.Date}}" + - "--label=org.opencontainers.image.name={{.ProjectName}}" + - "--label=org.opencontainers.image.revision={{.FullCommit}}" + - "--label=org.opencontainers.image.version={{.Version}}" + - "--label=org.opencontainers.image.source={{.GitURL}}" + - "--platform=linux/arm64" + use: buildx +- image_templates: + - 'ghcr.io/caarlos0/goreleaser-pro-split-merge-example-real:v{{ .Version }}-windows-amd64' + build_flag_templates: + - "--pull" + - "--label=org.opencontainers.image.description=Just an example-real" + - "--label=org.opencontainers.image.created={{.Date}}" + - "--label=org.opencontainers.image.name={{.ProjectName}}" + - "--label=org.opencontainers.image.revision={{.FullCommit}}" + - "--label=org.opencontainers.image.version={{.Version}}" + - "--label=org.opencontainers.image.source={{.GitURL}}" + - "--platform=windows/amd64" + goos: windows + dockerfile: windows.dockerfile + +docker_manifests: +- name_template: 'ghcr.io/caarlos0/goreleaser-pro-split-merge-example-real:v{{ .Version }}' + image_templates: + - 'ghcr.io/caarlos0/goreleaser-pro-split-merge-example-real:v{{ .Version }}-amd64' + - 'ghcr.io/caarlos0/goreleaser-pro-split-merge-example-real:v{{ .Version }}-arm64' + - 'ghcr.io/caarlos0/goreleaser-pro-split-merge-example-real:v{{ .Version }}-windows-amd64' +- name_template: '{{ if not .IsNightly }}ghcr.io/caarlos0/goreleaser-pro-split-merge-example-real:latest{{ end }}' + image_templates: + - 'ghcr.io/caarlos0/goreleaser-pro-split-merge-example-real:v{{ .Version }}-amd64' + - 'ghcr.io/caarlos0/goreleaser-pro-split-merge-example-real:v{{ .Version }}-arm64' + - 'ghcr.io/caarlos0/goreleaser-pro-split-merge-example-real:v{{ .Version }}-windows-amd64' + +monorepo: + tag_prefix: v # so it always filters out the nightly tag + + +# signs the checksum file +# all files (including the sboms) are included in the checksum, so we don't need to sign each one if we don't want to +# https://goreleaser.com/customization/sign +signs: +- cmd: cosign + env: + - COSIGN_EXPERIMENTAL=1 + certificate: '${artifact}.pem' + args: + - sign-blob + - '--output-certificate=${certificate}' + - '--output-signature=${signature}' + - '${artifact}' + artifacts: checksum + output: true + +# create a source tarball +# https://goreleaser.com/customization/source/ +source: + enabled: true + +# creates SBOMs of all archives and the source tarball using syft +# https://goreleaser.com/customization/sbom +sboms: +- artifacts: archive +- id: source # Two different sbom configurations need two different IDs + artifacts: source + +# signs our docker image +# https://goreleaser.com/customization/docker_sign +docker_signs: +- cmd: cosign + env: + - COSIGN_EXPERIMENTAL=1 + artifacts: images + output: true + args: + - 'sign' + - '${artifact}' + + +# modelines, feel free to remove those if you don't want/use them: +# yaml-language-server: $schema=https://goreleaser.com/static/schema-pro.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4b565f2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,3 @@ +FROM alpine +COPY goreleaser-pro-split-merge-example-real /usr/bin/example +ENTRYPOINT ["/usr/bin/example"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..fef6216 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# GoReleaser Pro Split & Merge Example (real) + +This repo contains a quick and to-the-point example of how to use +[GoReleaser Pro](https://goreleaser.com/pro) +[split and merge builds](https://goreleaser.com/customization/partial/). + +This also serves as a [nightly](https://goreleaser.com/customization/nightlies/) example. + +The difference from this and +[the other example](https://github.com/caarlos0/goreleaser-pro-split-merge-example/commits/main), +is that this one uses the "real" OS instead of just setting `GOOS`. It also +leverages that to create Windows Docker Images. + +--- + +For now, this repo is not using the goreleaser action, as it does not work with +nightlies (yet), but it will, soon enough. diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..6cad3e9 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module test + +go 1.19 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..e69de29 diff --git a/main.go b/main.go new file mode 100644 index 0000000..7776ec8 --- /dev/null +++ b/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("hello world!") +} diff --git a/windows.dockerfile b/windows.dockerfile new file mode 100644 index 0000000..d3357bb --- /dev/null +++ b/windows.dockerfile @@ -0,0 +1,4 @@ +FROM mcr.microsoft.com/windows/nanoserver:ltsc2022 +WORKDIR /app +COPY goreleaser-pro-split-merge-example-real.exe example.exe +ENTRYPOINT ["/app/example.exe"]