-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Release Action to Github Workflow (#330)
- Loading branch information
Showing
4 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v0.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |