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

fix(rename): Fix github's action for rename project #126

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
36 changes: 36 additions & 0 deletions .github/rename_project.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
while getopts a:n:u:d: flag
do
case "${flag}" in
a) author=${OPTARG};;
n) name=${OPTARG};;
u) urlname=${OPTARG};;
d) description=${OPTARG};;
esac
done

echo "Author: $author";
echo "Project Name: $name";
echo "Project URL name: $urlname";
echo "Description: $description";

echo "Renaming project..."

original_author="author_name"
original_name="project_name"
original_urlname="project_urlname"
original_description="project_description"
# for filename in $(find . -name "*.*")
for filename in $(git ls-files)
do
sed -i "s/$original_author/$author/g" $filename
sed -i "s/$original_name/$name/g" $filename
sed -i "s/$original_urlname/$urlname/g" $filename
sed -i "s/$original_description/$description/g" $filename
echo "Renamed $filename"
done

mv project_name $name

# This command runs only once on GHA!
rm -rf .github/template.yml
1 change: 1 addition & 0 deletions .github/template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
author: LikeRainDay
43 changes: 43 additions & 0 deletions .github/workflows/rename_project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Rename the project from template

on: [push]

permissions: write-all

jobs:
rename-project:
if: ${{ !contains(github.repository,'/kratos-layout') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
ref: ${{ github.head_ref }}

- run: chmod +x .github/rename_project.sh
shell: bash

- run: echo "REPOSITORY_NAME=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}' | tr '-' '_' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
shell: bash

- run: echo "REPOSITORY_URLNAME=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_ENV
shell: bash

- run: echo "REPOSITORY_OWNER=$(echo '${{ github.repository }}' | awk -F '/' '{print $1}')" >> $GITHUB_ENV
shell: bash

- name: Is this still a template
id: is_template
run: echo "::set-output name=is_template::$(ls .github/template.yml &> /dev/null && echo true || echo false)"

- name: Rename the project
if: steps.is_template.outputs.is_template == 'true'
run: |
echo "Renaming the project with -a(author) ${{ env.REPOSITORY_OWNER }} -n(name) ${{ env.REPOSITORY_NAME }} -u(urlname) ${{ env.REPOSITORY_URLNAME }}"
.github/rename_project.sh -a ${{ env.REPOSITORY_OWNER }} -n ${{ env.REPOSITORY_NAME }} -u ${{ env.REPOSITORY_URLNAME }} -d "Awesome ${{ env.REPOSITORY_NAME }} created by ${{ env.REPOSITORY_OWNER }}"

- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "✅ Ready to clone and code."
# commit_options: '--amend --no-edit'
push_options: --force
2 changes: 1 addition & 1 deletion api/helloworld/v1/error_reason.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ syntax = "proto3";

package helloworld.v1;

option go_package = "github.com/go-kratos/kratos-layout/api/helloworld/v1;v1";
option go_package = "github.com/author_name/project_name/api/helloworld/v1;v1";
option java_multiple_files = true;
option java_package = "helloworld.v1";
option objc_class_prefix = "APIHelloworldV1";
Expand Down
2 changes: 1 addition & 1 deletion api/helloworld/v1/greeter.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package helloworld.v1;

import "google/api/annotations.proto";

option go_package = "github.com/go-kratos/kratos-layout/api/helloworld/v1;v1";
option go_package = "github.com/author_name/project_name/api/helloworld/v1;v1";
option java_multiple_files = true;
option java_package = "dev.kratos.api.helloworld.v1";
option java_outer_classname = "HelloworldProtoV1";
Expand Down
4 changes: 2 additions & 2 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package main

import (
"flag"
"github.com/go-kratos/kratos/v2"
"os"

"github.com/go-kratos/kratos-layout/internal/conf"
"github.com/author_name/project_name/internal/conf"

"github.com/go-kratos/kratos/v2"
"github.com/go-kratos/kratos/v2/config"
"github.com/go-kratos/kratos/v2/config/file"
"github.com/go-kratos/kratos/v2/log"
Expand Down
10 changes: 5 additions & 5 deletions cmd/server/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
package main

import (
"github.com/go-kratos/kratos-layout/internal/biz"
"github.com/go-kratos/kratos-layout/internal/conf"
"github.com/go-kratos/kratos-layout/internal/data"
"github.com/go-kratos/kratos-layout/internal/server"
"github.com/go-kratos/kratos-layout/internal/service"
"github.com/author_name/project_name/internal/biz"
"github.com/author_name/project_name/internal/conf"
"github.com/author_name/project_name/internal/data"
"github.com/author_name/project_name/internal/server"
"github.com/author_name/project_name/internal/service"

"github.com/go-kratos/kratos/v2"
"github.com/go-kratos/kratos/v2/log"
Expand Down
15 changes: 9 additions & 6 deletions cmd/server/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/go-kratos/kratos-layout
module github.com/author_name/project_name

go 1.17

Expand All @@ -17,15 +17,18 @@ require (
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-playground/form/v4 v4.2.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/subcommands v1.0.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opentelemetry.io/otel v1.7.0 // indirect
go.opentelemetry.io/otel/trace v1.7.0 // indirect
golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2 // indirect
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135 // indirect
gopkg.in/yaml.v3 v3.0.0 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/google/subcommands v1.0.1 h1:/eqq+otEXm5vhfBrbREPCSVQbvofip6kIz+mX5TUH7k=
github.com/google/subcommands v1.0.1/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
Expand Down Expand Up @@ -158,6 +159,7 @@ golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190422233926-fe54fb35175b/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135 h1:5Beo0mZN8dRzgrMMkDp0jc8YXQKx9DiJ2k1dkvGsn5A=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
Expand Down
2 changes: 1 addition & 1 deletion internal/biz/greeter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package biz
import (
"context"

v1 "github.com/go-kratos/kratos-layout/api/helloworld/v1"
v1 "github.com/author_name/project_name/api/helloworld/v1"

"github.com/go-kratos/kratos/v2/errors"
"github.com/go-kratos/kratos/v2/log"
Expand Down
2 changes: 1 addition & 1 deletion internal/data/data.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package data

import (
"github.com/go-kratos/kratos-layout/internal/conf"
"github.com/author_name/project_name/internal/conf"

"github.com/go-kratos/kratos/v2/log"
"github.com/google/wire"
Expand Down
2 changes: 1 addition & 1 deletion internal/data/greeter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package data
import (
"context"

"github.com/go-kratos/kratos-layout/internal/biz"
"github.com/author_name/project_name/internal/biz"

"github.com/go-kratos/kratos/v2/log"
)
Expand Down
6 changes: 3 additions & 3 deletions internal/server/grpc.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package server

import (
v1 "github.com/go-kratos/kratos-layout/api/helloworld/v1"
"github.com/go-kratos/kratos-layout/internal/conf"
"github.com/go-kratos/kratos-layout/internal/service"
v1 "github.com/author_name/project_name/api/helloworld/v1"
"github.com/author_name/project_name/internal/conf"
"github.com/author_name/project_name/internal/service"

"github.com/go-kratos/kratos/v2/log"
"github.com/go-kratos/kratos/v2/middleware/recovery"
Expand Down
6 changes: 3 additions & 3 deletions internal/server/http.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package server

import (
v1 "github.com/go-kratos/kratos-layout/api/helloworld/v1"
"github.com/go-kratos/kratos-layout/internal/conf"
"github.com/go-kratos/kratos-layout/internal/service"
v1 "github.com/author_name/project_name/api/helloworld/v1"
"github.com/author_name/project_name/internal/conf"
"github.com/author_name/project_name/internal/service"

"github.com/go-kratos/kratos/v2/log"
"github.com/go-kratos/kratos/v2/middleware/recovery"
Expand Down
4 changes: 2 additions & 2 deletions internal/service/greeter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package service
import (
"context"

v1 "github.com/go-kratos/kratos-layout/api/helloworld/v1"
"github.com/go-kratos/kratos-layout/internal/biz"
v1 "github.com/author_name/project_name/api/helloworld/v1"
"github.com/author_name/project_name/internal/biz"
)

// GreeterService is a greeter service.
Expand Down
1 change: 0 additions & 1 deletion openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ paths:
get:
tags:
- Greeter
- subgroup
description: Sends a greeting
operationId: Greeter_SayHello
parameters:
Expand Down