Skip to content

Commit b361033

Browse files
authored
Add Release Action to Github Workflow (#330)
1 parent 34d5b1b commit b361033

File tree

4 files changed

+99
-0
lines changed

4 files changed

+99
-0
lines changed

.github/workflows/release.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
workflow_dispatch: { }
8+
9+
env:
10+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
name: build
16+
strategy:
17+
matrix:
18+
TARGETS: [ linux/amd64, darwin/amd64, windows/amd64, linux/arm64, darwin/arm64 ]
19+
env:
20+
BACKUP_RESTORE_TOOL_VERSION_KEY: github.com/kubevela/terraform-controller/version.BackupRestoreToolVersion
21+
BACKUP_RESTORE_TOOL_VERSION: cat hack/tool/backup_restore/VERSION
22+
GO_BUILD_ENV: GO111MODULE=on CGO_ENABLED=0
23+
DIST_DIRS: find * -type d -exec
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v2
27+
- name: Set up Go
28+
uses: actions/setup-go@v2
29+
with:
30+
go-version: 1.17
31+
- name: Get release
32+
id: get_release
33+
uses: bruceadams/[email protected]
34+
- name: Get matrix
35+
id: get_matrix
36+
run: |
37+
TARGETS=${{matrix.TARGETS}}
38+
echo ::set-output name=OS::${TARGETS%/*}
39+
echo ::set-output name=ARCH::${TARGETS#*/}
40+
- name: Get ldflags
41+
id: get_ldflags
42+
run: |
43+
LDFLAGS="-s -w -X ${{ env.BACKUP_RESTORE_TOOL_VERSION_KEY }}=${{ env.BACKUP_RESTORE_TOOL_VERSION }}"
44+
echo "LDFLAGS=${LDFLAGS}" >> $GITHUB_ENV
45+
- name: Build
46+
run: |
47+
${{ env.GO_BUILD_ENV }} GOOS=${{ steps.get_matrix.outputs.OS }} GOARCH=${{ steps.get_matrix.outputs.ARCH }} \
48+
go build -ldflags "${{ env.LDFLAGS }}" \
49+
-o _bin/backup_restore/${{ steps.get_matrix.outputs.OS }}-${{ steps.get_matrix.outputs.ARCH }}/backup_restore -v \
50+
./hack/tool/backup_restore/main.go
51+
- name: Compress
52+
run: |
53+
cd _bin/backup_restore && \
54+
${{ env.DIST_DIRS }} cp ../../LICENSE {} \; && \
55+
${{ env.DIST_DIRS }} cp ../../README.md {} \; && \
56+
${{ env.DIST_DIRS }} tar -zcf backup-restore-{}.tar.gz {} \; && \
57+
${{ env.DIST_DIRS }} zip -r backup-restore-{}.zip {} \; && \
58+
cd .. && \
59+
sha256sum backup_restore/backup-restore-* >> sha256-${{ steps.get_matrix.outputs.OS }}-${{ steps.get_matrix.outputs.ARCH }}.txt \
60+
- name: Upload backup-restore tar.gz
61+
uses: actions/[email protected]
62+
with:
63+
upload_url: ${{ steps.get_release.outputs.upload_url }}
64+
asset_path: ./_bin/backup_restore/backup-restore-${{ steps.get_matrix.outputs.OS }}-${{ steps.get_matrix.outputs.ARCH }}.tar.gz
65+
asset_name: backup-restore-${{ env.BACKUP_RESTORE_TOOL_VERSION }}-${{ steps.get_matrix.outputs.OS }}-${{ steps.get_matrix.outputs.ARCH }}.tar.gz
66+
asset_content_type: binary/octet-stream
67+
- name: Upload backup-restore zip
68+
uses: actions/[email protected]
69+
with:
70+
upload_url: ${{ steps.get_release.outputs.upload_url }}
71+
asset_path: ./_bin/backup_restore/backup-restore-${{ steps.get_matrix.outputs.OS }}-${{ steps.get_matrix.outputs.ARCH }}.zip
72+
asset_name: backup-restore-${{ env.BACKUP_RESTORE_TOOL_VERSION }}-${{ steps.get_matrix.outputs.OS }}-${{ steps.get_matrix.outputs.ARCH }}.zip
73+
asset_content_type: binary/octet-stream

hack/tool/backup_restore/VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v0.1.0

hack/tool/backup_restore/cmd/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func Execute() {
3535
kubeConfigFlags.AddFlags(rootCmd.PersistentFlags())
3636
rootCmd.AddCommand(newRestoreCmd(kubeConfigFlags))
3737
rootCmd.AddCommand(newBackupCmd(kubeConfigFlags))
38+
rootCmd.AddCommand(newVersionCmd())
3839
err := rootCmd.Execute()
3940
if err != nil {
4041
os.Exit(1)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/spf13/cobra"
7+
)
8+
9+
const (
10+
selfVersion = "v0.1.0"
11+
tfVersion = "v0.7.4"
12+
)
13+
14+
// newVersionCmd represents the version command
15+
func newVersionCmd() *cobra.Command {
16+
versionCmd := &cobra.Command{
17+
Use: "version",
18+
Run: func(cmd *cobra.Command, args []string) {
19+
fmt.Printf("version: %s\n", selfVersion)
20+
fmt.Printf("compatible with the latest terraform-controller version: %s\n", tfVersion)
21+
},
22+
}
23+
return versionCmd
24+
}

0 commit comments

Comments
 (0)