Skip to content

Commit

Permalink
refactor(template): import partials template
Browse files Browse the repository at this point in the history
  • Loading branch information
cage1016 committed Sep 6, 2023
1 parent 5e46be8 commit 7021975
Show file tree
Hide file tree
Showing 10 changed files with 251 additions and 143 deletions.
42 changes: 25 additions & 17 deletions _example/.github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,35 @@ jobs:
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v2
- name: Parse Event
run: |
echo "tag=$(jq -r '.release.tag_name' "${GITHUB_EVENT_PATH}" | sed s/^v//)" >> $GITHUB_ENV
- name: Install Go
if: success()
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Run unit tests
go test -v -race -cover -coverprofile coverage.txt -covermode=atomic ./...
run: go test -v -race -cover -coverprofile coverage.txt -covermode=atomic ./...
- name: update codecov
run: |
CODECOV_TOKEN="${{ secrets.CODECOV_TOKEN }}" bash <(curl -s https://codecov.io/bash)
- name: Parse Event
CODECOV_TOKEN="${{ secrets.CODECOV_TOKEN }}" bash <(curl -s https://codecov.io/bash)
- name: Build and pack
run: |
echo "tag=$(jq -r '.release.tag_name' "${GITHUB_EVENT_PATH}" | sed s/^v//)" >> $GITHUB_ENV
# build package
GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w -X github.com/xxx/ak-test/cmd.EnabledAutoUpdate=false" -o exe_amd64
GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w -X github.com/xxx/ak-test/cmd.EnabledAutoUpdate=false" -o exe_arm64
lipo -create -output .workflow/exe exe_amd64 exe_arm64
rm exe_amd64
rm exe_arm64
# pack
cd .workflow
plutil -replace version -string "${{ env.tag }}" info.plist
zip -r ../"AkTest-${{ env.tag }}.alfredworkflow_" .
cd ..
echo "artifact=$(echo "AkTest-${{ env.tag }}.alfredworkflow_")" >> $GITHUB_ENV
- name: Import Code-Signing Certificates
uses: Apple-Actions/import-codesign-certs@v1
with:
Expand All @@ -37,14 +53,6 @@ jobs:
run: |
brew tap mitchellh/gon
brew install mitchellh/gon/gon
- name: Build and pack
run: |
# build package
GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w -X github.com/xxx/ak-test/cmd.EnabledAutoUpdate=false" -o exe_amd64
GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w -X github.com/xxx/ak-test/cmd.EnabledAutoUpdate=false" -o exe_arm64
lipo -create -output .workflow/exe exe_amd64 exe_arm64
rm exe_amd64
rm exe_arm64
- name: code sign and notarize
env:
AC_USERNAME: "${{ secrets.AC_USERNAME }}"
Expand All @@ -61,16 +69,16 @@ jobs:
}
EOF
gon -log-level=debug -log-json ./gon.json
# pack alfredworkflow
cd .workflow
plutil -replace version -string "${{ env.tag }}" info.plist
zip -r ../"AkTest-${{ env.tag }}.alfredworkflow_" .
cd ..
# zip alfredworkflow as zip archive for notarize
zip -r "AkTest-${{ env.tag }}.alfredworkflow.zip" "AkTest-${{ env.tag }}.alfredworkflow_"
# gon notarize
cat <<EOF >> notarize.json
{
Expand All @@ -82,8 +90,8 @@ jobs:
}
EOF
gon -log-level=debug -log-json ./notarize.json
echo "artifact=$(echo "AkTest-${{ env.tag }}.alfredworkflow_")" >> $GITHUB_ENV
echo "artifact=$(echo "AkTest-${{ env.tag }}.alfredworkflow_")" >> $GITHUB_ENV
- uses: shogo82148/actions-upload-release-asset@v1
with:
upload_url: ${{ github.event.release.upload_url }}
Expand Down
42 changes: 25 additions & 17 deletions _example/.github/workflows/release_auto_update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,35 @@ jobs:
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v2
- name: Parse Event
run: |
echo "tag=$(jq -r '.release.tag_name' "${GITHUB_EVENT_PATH}" | sed s/^v//)" >> $GITHUB_ENV
- name: Install Go
if: success()
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Run unit tests
go test -v -race -cover -coverprofile coverage.txt -covermode=atomic ./...
run: go test -v -race -cover -coverprofile coverage.txt -covermode=atomic ./...
- name: update codecov
run: |
CODECOV_TOKEN="${{ secrets.CODECOV_TOKEN }}" bash <(curl -s https://codecov.io/bash)
- name: Parse Event
CODECOV_TOKEN="${{ secrets.CODECOV_TOKEN }}" bash <(curl -s https://codecov.io/bash)
- name: Build and pack
run: |
echo "tag=$(jq -r '.release.tag_name' "${GITHUB_EVENT_PATH}" | sed s/^v//)" >> $GITHUB_ENV
# build package
GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w -X github.com/xxx/ak-test/cmd.EnabledAutoUpdate=true" -o exe_amd64
GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w -X github.com/xxx/ak-test/cmd.EnabledAutoUpdate=true" -o exe_arm64
lipo -create -output .workflow/exe exe_amd64 exe_arm64
rm exe_amd64
rm exe_arm64
# pack
cd .workflow
plutil -replace version -string "${{ env.tag }}" info.plist
zip -r ../"AkTest_auto_update-${{ env.tag }}.alfredworkflow" .
cd ..
echo "artifact=$(echo "AkTest_auto_update-${{ env.tag }}.alfredworkflow")" >> $GITHUB_ENV
- name: Import Code-Signing Certificates
uses: Apple-Actions/import-codesign-certs@v1
with:
Expand All @@ -37,14 +53,6 @@ jobs:
run: |
brew tap mitchellh/gon
brew install mitchellh/gon/gon
- name: Build and pack
run: |
# build package
GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w -X github.com/xxx/ak-test/cmd.EnabledAutoUpdate=true" -o exe_amd64
GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w -X github.com/xxx/ak-test/cmd.EnabledAutoUpdate=true" -o exe_arm64
lipo -create -output .workflow/exe exe_amd64 exe_arm64
rm exe_amd64
rm exe_arm64
- name: code sign and notarize
env:
AC_USERNAME: "${{ secrets.AC_USERNAME }}"
Expand All @@ -61,16 +69,16 @@ jobs:
}
EOF
gon -log-level=debug -log-json ./gon.json
# pack alfredworkflow
cd .workflow
plutil -replace version -string "${{ env.tag }}" info.plist
zip -r ../"AkTest_auto_update-${{ env.tag }}.alfredworkflow" .
cd ..
# zip alfredworkflow as zip archive for notarize
zip -r "AkTest_auto_update-${{ env.tag }}.alfredworkflow.zip" "AkTest_auto_update-${{ env.tag }}.alfredworkflow"
# gon notarize
cat <<EOF >> notarize.json
{
Expand All @@ -82,8 +90,8 @@ jobs:
}
EOF
gon -log-level=debug -log-json ./notarize.json
echo "artifact=$(echo "AkTest_auto_update-${{ env.tag }}.alfredworkflow")" >> $GITHUB_ENV
echo "artifact=$(echo "AkTest_auto_update-${{ env.tag }}.alfredworkflow")" >> $GITHUB_ENV
- uses: shogo82148/actions-upload-release-asset@v1
with:
upload_url: ${{ github.event.release.upload_url }}
Expand Down
3 changes: 3 additions & 0 deletions cmd/githubAction.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ var githubActionCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
s, _ := cmd.Flags().GetBool("sign")
c, _ := cmd.Flags().GetBool("codecov")
g, _ := cmd.Flags().GetBool("golang")

if err := generator.NewGithubActionGenerator(
generator.WithEnabled_Code_Sign_Notarize(s),
generator.WithEnabled_Codecov(c),
generator.WithEnabled_Golang(g),
).Generate(); err != nil {
logrus.Fatal(err)
}
Expand All @@ -32,4 +34,5 @@ func init() {
addCmd.AddCommand(githubActionCmd)
githubActionCmd.PersistentFlags().BoolP("sign", "s", false, "enable code sign and notarize")
githubActionCmd.PersistentFlags().BoolP("codecov", "c", false, "enable codecov")
githubActionCmd.PersistentFlags().BoolP("golang", "g", false, "enable goland")
}
9 changes: 9 additions & 0 deletions generator/githubactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
type GithubActionGenerator struct {
Enabled_Code_Sign_Notarize bool
Enabled_Codecov bool
Enabled_Golang bool
}

func WithEnabled_Code_Sign_Notarize(enabled bool) func(*GithubActionGenerator) {
Expand All @@ -32,6 +33,12 @@ func WithEnabled_Codecov(enabled bool) func(*GithubActionGenerator) {
}
}

func WithEnabled_Golang(enabled bool) func(*GithubActionGenerator) {
return func(g *GithubActionGenerator) {
g.Enabled_Golang = enabled
}
}

func (gg *GithubActionGenerator) Generate() error {
te := template.NewEngine()
defaultFs := fs.Get()
Expand All @@ -48,6 +55,7 @@ func (gg *GithubActionGenerator) Generate() error {
"ReleaseName": "Release",
"EnabledCodeSign": gg.Enabled_Code_Sign_Notarize,
"EnabledCodecov": gg.Enabled_Codecov,
"EnabledGolang": gg.Enabled_Golang,
"WorkflowName": strings.ReplaceAll(viper.GetString("workflow.name"), " ", ""),
"Ldflags": fmt.Sprintf("-X %s/cmd.EnabledAutoUpdate=false", viper.GetString("go_mod_package")),
"BundleID": viper.GetString("workflow.bundle_id"),
Expand All @@ -71,6 +79,7 @@ func (gg *GithubActionGenerator) Generate() error {
"ReleaseName": "Release_auto_update",
"EnabledCodeSign": gg.Enabled_Code_Sign_Notarize,
"EnabledCodecov": gg.Enabled_Codecov,
"EnabledGolang": gg.Enabled_Golang,
"WorkflowName": fmt.Sprintf("%s_auto_update", strings.ReplaceAll(viper.GetString("workflow.name"), " ", "")),
"Ldflags": fmt.Sprintf("-X %s/cmd.EnabledAutoUpdate=true", viper.GetString("go_mod_package")),
"BundleID": viper.GetString("workflow.bundle_id"),
Expand Down
Loading

0 comments on commit 7021975

Please sign in to comment.