diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 0000000..b0c5175 --- /dev/null +++ b/.github/release.yml @@ -0,0 +1,4 @@ +changelog: + exclude: + labels: + - tagpr diff --git a/.github/workflows/tagpr.yml b/.github/workflows/tagpr.yml new file mode 100644 index 0000000..d693b6d --- /dev/null +++ b/.github/workflows/tagpr.yml @@ -0,0 +1,100 @@ +name: tagpr +on: + push: + branches: + - main + +jobs: + tagpr: + runs-on: ubuntu-latest + outputs: + tagpr-tag: ${{ steps.run-tagpr.outputs.tag }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - name: Check out source code + uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version-file: go.mod + cache: true + + - id: run-tagpr + name: Run tagpr + uses: Songmu/tagpr@v1 + + release: + needs: tagpr + if: needs.tagpr.outputs.tagpr-tag != '' + runs-on: macos-latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - name: Check out source code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version-file: go.mod + cache: true + + - name: Setup goreleaser + run: | + brew install goreleaser + + - name: Release + run: | + make release + + dockerimage: + needs: tagpr + if: needs.tagpr.outputs.tagpr-tag != '' + runs-on: ubuntu-latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - name: Check out source code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Get latest version + id: latest_version + run: | + echo -n 'version=' > $GITHUB_OUTPUT + gh release list --limit 1 | cut -f 1 >> $GITHUB_OUTPUT + cat $GITHUB_OUTPUT + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to ghcr.io + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: | + ghcr.io/k1low/gh-grep:${{ steps.latest_version.outputs.version }} + ghcr.io/k1low/gh-grep:latest + labels: | + org.opencontainers.image.name=gh-grep + org.opencontainers.image.revision=${{ github.sha }} + org.opencontainers.image.version=${{ steps.latest_version.outputs.version }} + org.opencontainers.image.source=https://github.com/k1LoW/gh-grep diff --git a/.goreleaser.yml b/.goreleaser.yml index 67cb595..b9e3650 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -42,6 +42,7 @@ archives: - goos: darwin format: zip files: + - LICENSE - CREDITS - README.md - CHANGELOG.md @@ -57,23 +58,6 @@ snapshot: name_template: "{{ .Version }}-next" changelog: skip: true -dockers: - - - goos: linux - goarch: amd64 - image_templates: - - 'ghcr.io/k1low/gh-grep:v{{ .Version }}' - - 'ghcr.io/k1low/gh-grep:latest' - dockerfile: Dockerfile - build_flag_templates: - - "--pull" - - "--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=https://github.com/k1LoW/gh-grep" - extra_files: - - scripts/entrypoint.sh nfpms: - id: gh-grep-nfpms file_name_template: "{{ .ProjectName }}_{{ .Version }}-1_{{ .Arch }}" diff --git a/.tagpr b/.tagpr new file mode 100644 index 0000000..3f3f326 --- /dev/null +++ b/.tagpr @@ -0,0 +1,36 @@ +# config file for the tagpr in git config format +# The tagpr generates the initial configuration, which you can rewrite to suit your environment. +# CONFIGURATIONS: +# tagpr.releaseBranch +# Generally, it is "main." It is the branch for releases. The pcpr tracks this branch, +# creates or updates a pull request as a release candidate, or tags when they are merged. +# +# tagpr.versionFile +# Versioning file containing the semantic version needed to be updated at release. +# It will be synchronized with the "git tag". +# Often this is a meta-information file such as gemspec, setup.cfg, package.json, etc. +# Sometimes the source code file, such as version.go or Bar.pm, is used. +# If you do not want to use versioning files but only git tags, specify the "-" string here. +# You can specify multiple version files by comma separated strings. +# +# tagpr.vPrefix +# Flag whether or not v-prefix is added to semver when git tagging. (e.g. v1.2.3 if true) +# This is only a tagging convention, not how it is described in the version file. +# +# tagpr.changelog (Optional) +# Flag whether or not changelog is added or changed during the release. +# +# tagpr.command (Optional) +# Command to change files just before release. +# +# tagpr.tmplate (Optional) +# Pull request template in go template format +# +# tagpr.release (Optional) +# GitHub Release creation behavior after tagging [true, draft, false] +# If this value is not set, the release is to be created. +[tagpr] + vPrefix = true + releaseBranch = main + versionFile = version/version.go + command = "make prerelease_for_tagpr" diff --git a/Dockerfile b/Dockerfile index aa56576..8740bb8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,24 @@ -FROM debian:buster-slim +FROM golang:1-bullseye AS builder -RUN apt-get update && apt-get install -y \ - curl \ - git \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* +WORKDIR /workdir/ +COPY . /workdir/ + +RUN apt-get update + +RUN update-ca-certificates + +RUN make build + +FROM debian:bullseye-slim + +RUN apt-get update \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --from=builder /workdir/ghgrep ./usr/bin/gh-grep ENTRYPOINT ["/entrypoint.sh"] COPY scripts/entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh - -COPY gh-grep_*.deb /tmp/ -RUN dpkg -i /tmp/gh-grep_*.deb diff --git a/Makefile b/Makefile index 5e3ad41..5e20811 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ lint: golangci-lint run ./... build: - go build -ldflags="$(BUILD_LDFLAGS)" -o grep + go build -ldflags="$(BUILD_LDFLAGS)" -o ghgrep depsdev: go install github.com/Songmu/ghch/cmd/ghch@latest @@ -33,11 +33,15 @@ prerelease: git pull origin main --tag go mod tidy ghch -w -N ${VER} - gocredits . > CREDITS + gocredits -w . git add CHANGELOG.md CREDITS go.mod go.sum gh-grep git commit -m'Bump up version number' git tag ${VER} +prerelease_for_tagpr: + gocredits -w . + git add CHANGELOG.md CREDITS go.mod go.sum + release: git push origin main --tag goreleaser --clean diff --git a/version/version.go b/version/version.go index b9a2c19..f69dcb2 100644 --- a/version/version.go +++ b/version/version.go @@ -4,4 +4,4 @@ package version const Name string = "gh-grep" // Version for this -var Version = "dev" +var Version = "1.1.0"