From c44f8d284c1aa92975826ccd8e35e2b4f938ed40 Mon Sep 17 00:00:00 2001 From: Divanshu Chauhan <23524935+Divkix@users.noreply.github.com> Date: Mon, 5 Sep 2022 03:12:07 -0700 Subject: [PATCH] add goreleaser --- .github/workflows/ci.yml | 31 +++++++------ .github/workflows/release.yml | 65 ++++++++++++++++++++++++++ .goreleaser.yaml | 87 +++++++++++++++++++++++++++++++++++ goreleaser.Dockerfile | 3 ++ 4 files changed, 172 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 .goreleaser.yaml create mode 100644 goreleaser.Dockerfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7e14310..3ddb7ad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,23 +4,26 @@ on: push: branches: - main + - dev pull_request: + workflow_dispatch: jobs: ci: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - go-version: ['1.18', '1.19'] - os: [ubuntu-latest, macOS-latest, windows-latest] - + name: CI + runs-on: ubuntu-latest steps: - - name: Set up ${{ matrix.go-version }} - uses: actions/setup-go@v3 - with: - go-version: ${{ matrix.go-version }} - uses: actions/checkout@v3 - - name: Build app - run: |- - go build -ldflags="-w -s" . + - uses: docker/setup-qemu-action@v2 + - uses: docker/setup-buildx-action@v2 + - uses: actions/setup-go@v3 + with: + go-version: 1.19 + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v3 + with: + version: latest + args: release --snapshot --skip-publish --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..8ee5a24 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,65 @@ +name: Release + +on: + push: + tags: + - '*' + workflow_dispatch: + inputs: + tag: + description: 'Tag to release' + required: true + +jobs: + goreleaser: + name: Release Binaries + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - uses: actions/setup-go@v3 + with: + go-version: 1.19 + + # only run this step when the tag is not already created + - if: startsWith(github.ref, 'refs/tags/') != 'true' && github.event.inputs.tag != '' + name: Create and Push Tag + run: |- + git config --global user.email "23524935+Divkix@users.noreply.github.com" + git config --global user.name "Divanshu Chauhan" + tag=${{ github.event.inputs.tag }} # if triggered by workflow_dispatch + if [ -z "$tag" ]; then + tag=${GITHUB_REF#refs/tags/} + fi + git tag -f -a -m "$tag" "$tag" + git push -f origin "$tag" + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v3 + with: + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..b21e6a6 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,87 @@ +project_name: gigafeed +release: + replace_existing_draft: true + header: | + Welcome to this new release! + footer: | + Docker Images: + `docker.io/divideprojects/{{ .ProjectName }}:latest` + `ghcr.io/gigauserbot/{{ .ProjectName }}:latest` +before: + hooks: + - go mod tidy + - go mod download +builds: + - goos: + - linux + - windows + - darwin + goarch: + - amd64 + - arm64 + mod_timestamp: '{{ .CommitTimestamp }}' + flags: + - -trimpath + ldflags: + - -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{ .CommitDate }} +archives: + - format: binary +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ incpatch .Version }}-next" + +dockers: + # amd64 only + - goarch: amd64 + dockerfile: goreleaser.Dockerfile + use: buildx + image_templates: + - "docker.io/divideprojects/{{ .ProjectName }}:{{ .Tag }}-amd64" + - "ghcr.io/gigauserbot/{{ .ProjectName }}:{{ .Tag }}-amd64" + build_flag_templates: + - "--platform=linux/amd64" + - "--pull" + - "--label=org.opencontainers.image.created={{.Date}}" + - "--label=org.opencontainers.image.title={{ .ProjectName }}" + - "--label=org.opencontainers.image.revision={{.FullCommit}}" + - "--label=org.opencontainers.image.version={{.Version}}" + extra_files: + - changelog.json + # arm64 only + - goarch: arm64 + dockerfile: goreleaser.Dockerfile + use: buildx + image_templates: + - "docker.io/divideprojects/{{ .ProjectName }}:{{ .Tag }}-arm64v8" + - "ghcr.io/gigauserbot/{{ .ProjectName }}:{{ .Tag }}-arm64v8" + build_flag_templates: + - "--platform=linux/arm64/v8" + - "--pull" + - "--label=org.opencontainers.image.created={{.Date}}" + - "--label=org.opencontainers.image.title={{ .ProjectName }}" + - "--label=org.opencontainers.image.revision={{.FullCommit}}" + - "--label=org.opencontainers.image.version={{.Version}}" + extra_files: + - changelog.json + +docker_manifests: + # docker hub + - name_template: "docker.io/divideprojects/{{ .ProjectName }}:{{ .Version }}" + image_templates: + - "docker.io/divideprojects/{{ .ProjectName }}:{{ .Tag }}-amd64" + - "docker.io/divideprojects/{{ .ProjectName }}:{{ .Tag }}-arm64v8" + - name_template: "docker.io/divideprojects/{{ .ProjectName }}:latest" + image_templates: + - "docker.io/divideprojects/{{ .ProjectName }}:{{ .Tag }}-amd64" + - "docker.io/divideprojects/{{ .ProjectName }}:{{ .Tag }}-arm64v8" + + # github container registry + - name_template: "ghcr.io/gigauserbot/{{ .ProjectName }}:{{ .Version }}" + image_templates: + - "ghcr.io/gigauserbot/{{ .ProjectName }}:{{ .Tag }}-amd64" + - "ghcr.io/gigauserbot/{{ .ProjectName }}:{{ .Tag }}-arm64v8" + - name_template: "ghcr.io/gigauserbot/{{ .ProjectName }}:latest" + image_templates: + - "ghcr.io/gigauserbot/{{ .ProjectName }}:{{ .Tag }}-amd64" + - "ghcr.io/gigauserbot/{{ .ProjectName }}:{{ .Tag }}-arm64v8" diff --git a/goreleaser.Dockerfile b/goreleaser.Dockerfile new file mode 100644 index 0000000..7d5d702 --- /dev/null +++ b/goreleaser.Dockerfile @@ -0,0 +1,3 @@ +FROM gcr.io/distroless/static +COPY gigafeed / +CMD ["/gigafeed"]