Skip to content

Commit

Permalink
Merge pull request #40 from k1LoW/tagpr
Browse files Browse the repository at this point in the history
Setup tagpr
  • Loading branch information
k1LoW authored Jul 4, 2023
2 parents a5d1826 + 6c0fa43 commit ad0b734
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 29 deletions.
4 changes: 4 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changelog:
exclude:
labels:
- tagpr
100 changes: 100 additions & 0 deletions .github/workflows/tagpr.yml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 1 addition & 17 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ archives:
- goos: darwin
format: zip
files:
- LICENSE
- CREDITS
- README.md
- CHANGELOG.md
Expand All @@ -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 }}"
Expand Down
36 changes: 36 additions & 0 deletions .tagpr
Original file line number Diff line number Diff line change
@@ -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"
27 changes: 18 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ package version
const Name string = "gh-grep"

// Version for this
var Version = "dev"
var Version = "1.1.0"

0 comments on commit ad0b734

Please sign in to comment.