diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..73dfffe5 --- /dev/null +++ b/.github/workflows/release.yml @@ -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/get-release@v1.2.2 + - 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/upload-release-asset@v1.0.2 + 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/upload-release-asset@v1.0.2 + 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 diff --git a/hack/tool/backup_restore/VERSION b/hack/tool/backup_restore/VERSION new file mode 100644 index 00000000..b82608c0 --- /dev/null +++ b/hack/tool/backup_restore/VERSION @@ -0,0 +1 @@ +v0.1.0 diff --git a/hack/tool/backup_restore/cmd/root.go b/hack/tool/backup_restore/cmd/root.go index a6d48802..821f066b 100644 --- a/hack/tool/backup_restore/cmd/root.go +++ b/hack/tool/backup_restore/cmd/root.go @@ -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) diff --git a/hack/tool/backup_restore/cmd/version.go b/hack/tool/backup_restore/cmd/version.go new file mode 100644 index 00000000..2026f808 --- /dev/null +++ b/hack/tool/backup_restore/cmd/version.go @@ -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 +}