-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from dionomusuko/refactor-all
- Loading branch information
Showing
14 changed files
with
247 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.* | ||
* | ||
!go.mod | ||
!go.sum | ||
!*.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,27 @@ | ||
on: | ||
push: | ||
branches: | ||
- master | ||
- main | ||
paths: | ||
- 'RELEASE' | ||
pull_request: | ||
types: [opened, synchronize] | ||
branches: | ||
- master | ||
- main | ||
paths: | ||
- 'RELEASE' | ||
|
||
jobs: | ||
gh-release: | ||
runs-on: ubuntu-latest | ||
runs-on: ubuntu-22.04 | ||
permissions: | ||
contents: write | ||
pull-requests: write | ||
timeout-minutes: 5 | ||
steps: | ||
- id: checkout | ||
name: Checkout repository | ||
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 | ||
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # https://github.com/actions/checkout/releases/tag/v3.1.0 | ||
with: | ||
fetch-depth: 0 | ||
- uses: pipe-cd/[email protected].4 | ||
- uses: pipe-cd/actions-gh-release@b83d245d1b73261a6400cee9731b6af03df02f4a # https://github.com/pipe-cd/actions-gh-release/releases/tag/v2.3.6 | ||
with: | ||
release_file: 'RELEASE' | ||
token: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,34 @@ | ||
name: Release | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
releaseFilePath: | ||
description: 'Define the path of RELEASE file' | ||
release_file_path: | ||
description: "path to RELEASE file" | ||
required: true | ||
type: choice | ||
options: | ||
- RELEASE | ||
- testdata/RELEASE | ||
next_semver_level: | ||
description: "semver level to bump" | ||
required: true | ||
default: 'RELEASE' | ||
type: choice | ||
options: | ||
- 'RELEASE' | ||
- 'testdata/RELEASE' | ||
newTag: | ||
description: 'new tag' | ||
required: false | ||
- patch | ||
- minor | ||
#- major | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
main: | ||
runs-on: ubuntu-22.04 | ||
permissions: | ||
contents: read | ||
timeout-minutes: 5 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- uses: dionomusuko/gh-release-with-wf-dispatch@master | ||
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # https://github.com/actions/checkout/releases/tag/v3.1.0 | ||
- uses: dionomusuko/gh-release-with-wf-dispatch@main | ||
with: | ||
"github_token": ${{ secrets.GH_PAT }} | ||
"owner": ${{ github.event.repository.owner.login }} | ||
"repo_full_name": ${{ github.event.repository.full_name }} | ||
"repo": ${{ github.event.repository.name }} | ||
"release_file_path": ${{ github.event.inputs.releaseFilePath }} | ||
"base_branch": ${{ github.event.repository.default_branch }} | ||
"new_tag": ${{ github.event.inputs.newTag }} | ||
github_token: ${{ secrets.GH_PAT }} | ||
release_file_path: ${{ github.event.inputs.release_file_path }} | ||
next_semver_level: ${{ github.event.inputs.next_semver_level }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
DOCKER_IMAGE_NAME := ghcr.io/dionomusuko/gh-release-with-wf-dispatch | ||
DOCKER_SCOPE := docker-latest | ||
|
||
.PHONY: test | ||
test: | ||
go test -v ./... | ||
|
||
.PHONY: build | ||
build: | ||
CGO_ENABLED=0 go build | ||
|
||
.PHONY: docker-setup-buildx | ||
docker-setup-buildx: | ||
docker buildx create --use --driver docker-container | ||
|
||
.PHONY: docker-build | ||
docker-build: docker-setup-buildx | ||
docker buildx build . \ | ||
--tag "${DOCKER_IMAGE_NAME}:latest" \ | ||
--platform "linux/amd64" \ | ||
--output "type=docker" \ | ||
--cache-from "type=gha,scope=${DOCKER_SCOPE}" \ | ||
--cache-to "type=gha,mode=max,scope=${DOCKER_SCOPE}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,15 +49,12 @@ jobs: | |
timeout-minutes: 5 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: release | ||
uses: peaceiris/gh-release-with-wf-dispatch@feat-semver-input | ||
- uses: dionomusuko/gh-release-with-wf-dispatch@main | ||
with: | ||
github_token: ${{ secrets.GH_PAT }} | ||
release_file_path: ${{ github.event.inputs.release_file_path }} | ||
next_semver_level: ${{ github.event.inputs.next_semver_level }} | ||
base_branch: "master" | ||
base_branch: "develop" | ||
user_name: "username" | ||
user_email: "[email protected]" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ package main | |
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"os" | ||
"time" | ||
|
||
|
@@ -12,7 +11,6 @@ import ( | |
"github.com/go-git/go-git/v5" | ||
"github.com/go-git/go-git/v5/plumbing" | ||
"github.com/go-git/go-git/v5/plumbing/object" | ||
"github.com/go-git/go-git/v5/plumbing/transport/http" | ||
"github.com/go-git/go-git/v5/storage/memory" | ||
) | ||
|
||
|
@@ -29,67 +27,80 @@ type gitConfig struct { | |
userEmail string | ||
} | ||
|
||
func newGitClient(ctx context.Context, token, repository string, config gitConfig) *gitClient { | ||
func newGitClient(ctx context.Context, token, repository string, config gitConfig) (*gitClient, error) { | ||
fs := memfs.New() | ||
|
||
// https://<GITHUB_TOKEN>@github.com/<REPO>.git | ||
repo, err := git.CloneContext(ctx, memory.NewStorage(), fs, &git.CloneOptions{ | ||
URL: fmt.Sprintf("https://%[email protected]/%s.git", token, repository), | ||
}) | ||
if err != nil { | ||
log.Fatalf("falied to clone repository: %s", err.Error()) | ||
fmt.Printf("failed to clone repository %s\n", repository) | ||
return nil, err | ||
} | ||
w, err := repo.Worktree() | ||
if err != nil { | ||
log.Fatalf("falied to get worktree: %v", err) | ||
fmt.Println("failed to get worktree") | ||
return nil, err | ||
} | ||
return &gitClient{ | ||
repository: repo, | ||
worktree: w, | ||
file: fs, | ||
token: token, | ||
config: config, | ||
} | ||
}, nil | ||
} | ||
|
||
// Checkout new branch | ||
func (g *gitClient) Checkout(newTag string) string { | ||
branch := plumbing.ReferenceName("refs/heads/release-" + newTag) | ||
func (g *gitClient) Checkout(refName string) (string, error) { | ||
branch := plumbing.ReferenceName(refName) | ||
if err := g.worktree.Checkout(&git.CheckoutOptions{ | ||
Create: true, | ||
Branch: branch, | ||
}); err != nil { | ||
log.Fatalf("falied to chckout repository: %v", err) | ||
return "", nil | ||
} | ||
return branch.String() | ||
return branch.String(), nil | ||
} | ||
|
||
func (g *gitClient) Commit(filePath, newTag string) { | ||
// Create Commit | ||
func (g *gitClient) Add(filePath string) error { | ||
if _, err := g.worktree.Add(filePath); err != nil { | ||
log.Fatalf("falied to add") | ||
fmt.Printf("failed to git add file %s\n", filePath) | ||
return err | ||
} | ||
_, err := g.worktree.Commit("chore: release-"+newTag, &git.CommitOptions{ | ||
Author: &object.Signature{ | ||
Name: g.config.userName, | ||
Email: g.config.userEmail, | ||
When: time.Now(), | ||
}}) | ||
return nil | ||
} | ||
|
||
func (g *gitClient) Commit(msg string) error { | ||
commitHash, err := g.worktree.Commit( | ||
msg, | ||
&git.CommitOptions{ | ||
Author: &object.Signature{ | ||
Name: g.config.userName, | ||
Email: g.config.userEmail, | ||
When: time.Now(), | ||
}, | ||
}, | ||
) | ||
if err != nil { | ||
log.Fatalf("falied to commit") | ||
fmt.Println("failed to git commit") | ||
return err | ||
} | ||
fmt.Printf("commit %s has been created\n", commitHash.String()) | ||
return nil | ||
} | ||
|
||
func (g *gitClient) Push(ctx context.Context, owner string) { | ||
if err := g.repository.PushContext(ctx, &git.PushOptions{ | ||
Progress: os.Stdout, | ||
Auth: &http.BasicAuth{ | ||
Username: owner, | ||
Password: g.token, | ||
func (g *gitClient) Push(ctx context.Context) error { | ||
if err := g.repository.PushContext( | ||
ctx, | ||
&git.PushOptions{ | ||
Progress: os.Stdout, | ||
RemoteName: "origin", | ||
}, | ||
RemoteName: "origin", | ||
}); err != nil { | ||
log.Fatalf("failed to push: %v", err) | ||
); err != nil { | ||
fmt.Println("failed to git push") | ||
return err | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.