|
| 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 | + |
| 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 | + |
| 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 |
0 commit comments