Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tagging Github action #849

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: documentation
on:
push:
tags:
- 'v*.*.*'
branches: [ master ]
permissions:
contents: write
jobs:
Expand All @@ -27,6 +26,6 @@ jobs:
git config --global user.email vektra-bot@vektra.github.io
git fetch origin gh-pages --depth=1
- name: Deploy docs
run: "mike deploy --push --update-aliases $(echo ${{ github.ref_name }} | cut -d'.' -f1-2 ) latest"
run: "mike deploy --push --update-aliases $(grep VERSION mockery-tools.env | cut -d'=' -f 2 | cut -d'.' -f1-2) latest"
env:
GOOGLE_ANALYTICS_KEY: ${{ secrets.GOOGLE_ANALYTICS_KEY }}
43 changes: 0 additions & 43 deletions .github/workflows/release.yml

This file was deleted.

84 changes: 84 additions & 0 deletions .github/workflows/tag-and-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Create new Git tag

on:
push:
branches:
- master
permissions:
contents: write
jobs:
tag:
runs-on: ubuntu-latest
outputs:
tag_result: ${{ steps.tag.outputs.tag_result }}
steps:
- run: sudo apt update && sudo apt install -y git && git --version
- uses: actions/checkout@v2
with:
# We need entire history of tags
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: ./tools/go.mod
check-latest: true
cache-dependency-path: "**/*.sum"

- name: Download Go dependencies
run: cd tools/ && go run github.com/go-task/task/v3/cmd/task install-deps && echo "~/go/bin" >> $GITHUB_PATH

- name: Run tagging commands
id: tag
run: |
set +e
task -x tag
tag_result="$?"
echo "tag_result=$tag_result" >> $GITHUB_OUTPUT
# The range between 8 and 63 inclusive is reserved for custom
# error codes that contain specific meaning.
if [ $tag_result -lt 8 -o $tag_result -gt 63 ]; then
exit $tag_result
fi
exit 0
- name: Push tags
run: task tag.push
if: steps.tag.outputs.tag_result == 0

release:
needs: tag
if: needs.tag.outputs.tag_result == 0
runs-on: ubuntu-latest
env:
DOCKER_CLI_EXPERIMENTAL: "enabled"

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: GoReleaser
uses: goreleaser/goreleaser-action@v2.7.0
with:
args: release --rm-dist
version: "<2"
env:
GITHUB_TOKEN: ${{ secrets.GORELEASER_GITHUB_TOKEN }}
HOMEBREW_TAP_TOKEN: ${{ secrets.GORELEASER_HOMEBREW_TAP_TOKEN }}
16 changes: 16 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,19 @@ tasks:

default:
deps: [test.ci]

build-tools:
desc: Build tools directory
cmds:
- cd ./tools && go build -o tools .

tag:
desc: Tag the git repo with the version specified.
deps: [build-tools]
cmds:
- ./tools/tools tag --dry-run=false

tag.push:
desc: Push tags to origin
cmds:
- git push origin --tags
157 changes: 4 additions & 153 deletions go.work.sum

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions mockery-tools.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VERSION=v2.49.0
71 changes: 71 additions & 0 deletions tools/cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package cmd

import (
"fmt"
"os"

"github.com/go-errors/errors"
"github.com/rs/zerolog"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var logger zerolog.Logger

type timestampHook struct{}

func (t timestampHook) Run(e *zerolog.Event, level zerolog.Level, message string) {
e.Timestamp()
}

func maybeExit(err error) {
printStack(err)
if err != nil {
os.Exit(1)
}
}

func newViper() *viper.Viper {
v := viper.New()
v.SetConfigType("env")
v.SetConfigName("mockery-tools")
v.AddConfigPath(".")
v.AddConfigPath("../")
v.SetEnvPrefix("MOCKERYTOOLS")
maybeExit(v.ReadInConfig())
return v
}

func NewRootCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "mockery_tools [command]",
}

logger = zerolog.New(zerolog.ConsoleWriter{
Out: os.Stdout,
}).Hook(timestampHook{})

subCommands := []func(v *viper.Viper) (*cobra.Command, error){
NewTagCmd,
}
for _, CommandFunc := range subCommands {
subCmd, err := CommandFunc(newViper())
if err != nil {
panic(err)
}
cmd.AddCommand(subCmd)
}
return cmd
}

func printStack(err error) {
if err == nil {
return
}
newErr, ok := err.(*errors.Error)
if ok {
fmt.Printf("%v\n", newErr.ErrorStack())
} else {
fmt.Printf("%v\n", err)
}
}
Loading
Loading