Skip to content

Commit

Permalink
Add Release Action to Github Workflow (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
loheagn authored Aug 18, 2022
1 parent 34d5b1b commit b361033
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 0 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Release

on:
push:
tags:
- "v*"
workflow_dispatch: { }

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
build:
runs-on: ubuntu-latest
name: build
strategy:
matrix:
TARGETS: [ linux/amd64, darwin/amd64, windows/amd64, linux/arm64, darwin/arm64 ]
env:
BACKUP_RESTORE_TOOL_VERSION_KEY: github.com/kubevela/terraform-controller/version.BackupRestoreToolVersion
BACKUP_RESTORE_TOOL_VERSION: cat hack/tool/backup_restore/VERSION
GO_BUILD_ENV: GO111MODULE=on CGO_ENABLED=0
DIST_DIRS: find * -type d -exec
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Get release
id: get_release
uses: bruceadams/[email protected]
- name: Get matrix
id: get_matrix
run: |
TARGETS=${{matrix.TARGETS}}
echo ::set-output name=OS::${TARGETS%/*}
echo ::set-output name=ARCH::${TARGETS#*/}
- name: Get ldflags
id: get_ldflags
run: |
LDFLAGS="-s -w -X ${{ env.BACKUP_RESTORE_TOOL_VERSION_KEY }}=${{ env.BACKUP_RESTORE_TOOL_VERSION }}"
echo "LDFLAGS=${LDFLAGS}" >> $GITHUB_ENV
- name: Build
run: |
${{ env.GO_BUILD_ENV }} GOOS=${{ steps.get_matrix.outputs.OS }} GOARCH=${{ steps.get_matrix.outputs.ARCH }} \
go build -ldflags "${{ env.LDFLAGS }}" \
-o _bin/backup_restore/${{ steps.get_matrix.outputs.OS }}-${{ steps.get_matrix.outputs.ARCH }}/backup_restore -v \
./hack/tool/backup_restore/main.go
- name: Compress
run: |
cd _bin/backup_restore && \
${{ env.DIST_DIRS }} cp ../../LICENSE {} \; && \
${{ env.DIST_DIRS }} cp ../../README.md {} \; && \
${{ env.DIST_DIRS }} tar -zcf backup-restore-{}.tar.gz {} \; && \
${{ env.DIST_DIRS }} zip -r backup-restore-{}.zip {} \; && \
cd .. && \
sha256sum backup_restore/backup-restore-* >> sha256-${{ steps.get_matrix.outputs.OS }}-${{ steps.get_matrix.outputs.ARCH }}.txt \
- name: Upload backup-restore tar.gz
uses: actions/[email protected]
with:
upload_url: ${{ steps.get_release.outputs.upload_url }}
asset_path: ./_bin/backup_restore/backup-restore-${{ steps.get_matrix.outputs.OS }}-${{ steps.get_matrix.outputs.ARCH }}.tar.gz
asset_name: backup-restore-${{ env.BACKUP_RESTORE_TOOL_VERSION }}-${{ steps.get_matrix.outputs.OS }}-${{ steps.get_matrix.outputs.ARCH }}.tar.gz
asset_content_type: binary/octet-stream
- name: Upload backup-restore zip
uses: actions/[email protected]
with:
upload_url: ${{ steps.get_release.outputs.upload_url }}
asset_path: ./_bin/backup_restore/backup-restore-${{ steps.get_matrix.outputs.OS }}-${{ steps.get_matrix.outputs.ARCH }}.zip
asset_name: backup-restore-${{ env.BACKUP_RESTORE_TOOL_VERSION }}-${{ steps.get_matrix.outputs.OS }}-${{ steps.get_matrix.outputs.ARCH }}.zip
asset_content_type: binary/octet-stream
1 change: 1 addition & 0 deletions hack/tool/backup_restore/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v0.1.0
1 change: 1 addition & 0 deletions hack/tool/backup_restore/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func Execute() {
kubeConfigFlags.AddFlags(rootCmd.PersistentFlags())
rootCmd.AddCommand(newRestoreCmd(kubeConfigFlags))
rootCmd.AddCommand(newBackupCmd(kubeConfigFlags))
rootCmd.AddCommand(newVersionCmd())
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
Expand Down
24 changes: 24 additions & 0 deletions hack/tool/backup_restore/cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

const (
selfVersion = "v0.1.0"
tfVersion = "v0.7.4"
)

// newVersionCmd represents the version command
func newVersionCmd() *cobra.Command {
versionCmd := &cobra.Command{
Use: "version",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("version: %s\n", selfVersion)
fmt.Printf("compatible with the latest terraform-controller version: %s\n", tfVersion)
},
}
return versionCmd
}

0 comments on commit b361033

Please sign in to comment.