Skip to content

Commit

Permalink
Merge pull request #47 from pfnet-research/tagpr
Browse files Browse the repository at this point in the history
tagpr based automated release
  • Loading branch information
everpeace authored Oct 17, 2022
2 parents ea79ad0 + 6a15c7a commit 672c2ea
Show file tree
Hide file tree
Showing 15 changed files with 310 additions and 218 deletions.
38 changes: 38 additions & 0 deletions .github/actions/release/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: release
description: release executables

inputs:
tag:
description: check out the tag if not empty
default: ''
token:
description: GitHub token
required: true

runs:
using: composite

steps:
- uses: actions/checkout@v3
name: "checkout tag ${{ inputs.tag }}"
if: "inputs.tag != ''"
with:
ref: refs/tags/${{ inputs.tag }}
env:
GITHUB_TOKEN: ${{ inputs.token }}
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ~1.16
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: pfnet-research
password: ${{ inputs.token }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
with:
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ inputs.token }}
20 changes: 0 additions & 20 deletions .github/release-drafter.yml

This file was deleted.

24 changes: 24 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
changelog:
exclude:
labels:
- release-note/skip
- tagpr
categories:
- title: "💣 Breaking Changes"
labels:
- release-note/breaking-change
- title: "🚀 Features"
labels:
- release-note/feature
- title: "🐛 Bug Fixes"
labels:
- release-note/bugfix
- title: "📜 Documentation"
labels:
- release-note/document
- title: "🧰 Maintenance"
labels:
- release-note/chore
- title: "🔬 Other Changes"
labels:
- "*"
74 changes: 37 additions & 37 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,57 +11,57 @@ on:

jobs:

test:
name: Test
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v3
- name: Set up Go 1.x
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ^1.16
go-version: ~1.16
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Get dependencies
run: go mod download
- name: Get Devtools
run: make setup
- name: Lint
run : make lint

test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v3
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: ~1.16
id: go
- name: Get dependencies
run: go mod download
- name: Get Devtools
run: make setup
- name: Build
run: make
run: make build-only
- name: Test
run: make test
- name: Validate .goreleaser.yml
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --snapshot --skip-publish --rm-dist --debug

image_build:
name: Image Build
validate-goreleaser:
name: Validate .goreleaser.yml
runs-on: ubuntu-latest
env:
DOCKER_BUILDKIT: 1
IMAGE_PREFIX: docker.pkg.github.com/${{ github.repository }}/
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.16
id: go
- name: Check out
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Get Devtools
run: make setup
- name: Login GitHub Registry
run: docker login docker.pkg.github.com -u owner -p ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker image
run: make build-image
- name: Push Docker image
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
run: make push-image
- name: Check out
uses: actions/checkout@v3
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: ~1.16
id: go
- name: Validate GoReleaser
uses: goreleaser/goreleaser-action@v3
with:
version: latest
args: release --snapshot --skip-publish --rm-dist --debug
17 changes: 17 additions & 0 deletions .github/workflows/manual_release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Release By Tagged Manually
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"

jobs:
goreleaser:
name: Release
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Check out
uses: actions/checkout@v3
- uses: ./.github/actions/release
with:
token: ${{ secrets.GITHUB_TOKEN }}
47 changes: 47 additions & 0 deletions .github/workflows/publish_dev_image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Publish Dev Image

on:
push:
branches: [ master ]
tags-ignore: [ "**" ]
paths-ignore: [ "**.md" ]

jobs:
publish_dev_image:
name: Publish Dev Image
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v3
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: ~1.16
id: go
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: pfnet-research
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Snapshots
uses: goreleaser/goreleaser-action@v3
with:
version: latest
args: release --snapshot --rm-dist --debug
# Mimic docker, docker_manifests artifacts in goreleaser here.
# because "goreleaser release --snapshot" does NOT publish any artifact
- name: Publish Snapshot Images
shell: bash
run: |
set -euo pipefail
IMAGES=($(jq -r '.[] | select(.type=="Docker Image") | .name' dist/artifacts.json))
for i in ${IMAGES[@]}; do
docker push $i
done
MANIFEST=$(jq '.[] | select(.type=="Docker Image") | .name' dist/artifacts.json | jq -sr '.[0]' | sed -e "s|-[a-z0-9]\+$||g")
docker manifest create ${MANIFEST} ${IMAGES[@]}
docker manifest push ${MANIFEST}
MANIFEST_LATEST=$(jq '.[] | select(.type=="Docker Image") | .name' dist/artifacts.json | jq -sr '.[0]' | sed -e "s|:.*$||g"):latest
docker manifest create ${MANIFEST_LATEST} ${IMAGES[@]}
docker manifest push ${MANIFEST_LATEST}
72 changes: 0 additions & 72 deletions .github/workflows/release.yaml

This file was deleted.

32 changes: 32 additions & 0 deletions .github/workflows/tagpr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# tagpr workflow
#
name: tagpr
on:
push:
branches: ["master"]

jobs:
tagpr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- id: tagpr
name: Tagpr
uses: Songmu/tagpr@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# If tagpr pushed tags, invoke release custom action manually.
# It is because:
# > When you use the repository's GITHUB_TOKEN to perform tasks,
# > events triggered by the GITHUB_TOKEN, with the exception of
# > workflow_dispatch and repository_dispatch, will not create
# > a new workflow run.
# ref: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#using-the-github_token-in-a-workflow
- name: "Release (only when tagged)"
uses: ./.github/actions/release
if: "steps.tagpr.outputs.tag != ''"
with:
tag: ${{ steps.tagpr.outputs.tag }}
token: ${{ secrets.GITHUB_TOKEN }}
Loading

0 comments on commit 672c2ea

Please sign in to comment.