v0.2.7 #29
Workflow file for this run
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
name: Release | |
on: | |
release: | |
types: | |
- created | |
env: | |
GO_VERSION: '1.21' | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
jobs: | |
build_and_upload: | |
runs-on: ubuntu-20.04 | |
strategy: | |
matrix: | |
TARGETS: [ linux/amd64 ] | |
env: | |
GO_BUILD_ENV: GO111MODULE=on CGO_ENABLED=1 | |
DIST_DIRS: find * -type d -exec | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
- name: Get release | |
id: get_release | |
uses: bruceadams/[email protected] | |
- name: Get matrix | |
id: get_matrix | |
run: | | |
TARGETS=${{matrix.TARGETS}} | |
echo "OS=${TARGETS%/*}" >> $GITHUB_OUTPUT | |
echo "ARCH=${TARGETS#*/}" >> $GITHUB_OUTPUT | |
- name: Build | |
run: | | |
cd cmd && \ | |
${{ env.GO_BUILD_ENV }} GOOS=${{ steps.get_matrix.outputs.OS }} GOARCH=${{ steps.get_matrix.outputs.ARCH }} \ | |
go build \ | |
-o _bin/db-archiver/${{ steps.get_matrix.outputs.OS }}-${{ steps.get_matrix.outputs.ARCH }}/db-archiver | |
- name: Compress | |
run: | | |
cd cmd/_bin/db-archiver && \ | |
${{ env.DIST_DIRS }} cp ../../LICENSE {} \; && \ | |
${{ env.DIST_DIRS }} cp ../../README.md {} \; && \ | |
${{ env.DIST_DIRS }} tar -zcf db-archiver-{}-${{ github.ref_name }}.tar.gz {} \; && \ | |
cd .. && \ | |
sha256sum db-archiver/db-archiver-*-${{ github.ref_name }}.tar.gz >> sha256-${{ steps.get_matrix.outputs.OS }}-${{ steps.get_matrix.outputs.ARCH }}.txt | |
- name: Delete existing asset | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const fs = require('fs'); | |
const release = await github.rest.repos.getReleaseByTag({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
tag: '${{ github.ref_name }}' | |
}); | |
const asset_name = 'db-archiver-${{ steps.get_matrix.outputs.OS }}-${{ steps.get_matrix.outputs.ARCH }}-${{ github.ref_name }}.tar.gz'; | |
for (const asset of release.data.assets) { | |
if (asset.name === asset_name) { | |
await github.rest.repos.deleteReleaseAsset({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
asset_id: asset.id | |
}); | |
console.log(`Deleted existing asset: ${asset_name}`); | |
break; | |
} | |
} | |
- name: Upload db-archiver tar.gz | |
uses: actions/[email protected] | |
with: | |
upload_url: ${{ steps.get_release.outputs.upload_url }} | |
asset_path: cmd/_bin/db-archiver/db-archiver-${{ steps.get_matrix.outputs.OS }}-${{ steps.get_matrix.outputs.ARCH }}-${{ github.ref_name }}.tar.gz | |
asset_name: db-archiver-${{ steps.get_matrix.outputs.OS }}-${{ steps.get_matrix.outputs.ARCH }}-${{ github.ref_name }}.tar.gz | |
asset_content_type: application/gzip | |
- name: Post sha256 | |
uses: actions/upload-artifact@v4 | |
with: | |
name: sha256sums-${{ steps.get_matrix.outputs.OS }}-${{ steps.get_matrix.outputs.ARCH }} | |
path: cmd/_bin/sha256-${{ steps.get_matrix.outputs.OS }}-${{ steps.get_matrix.outputs.ARCH }}.txt | |
retention-days: 1 | |
upload-sha256sums: | |
needs: build_and_upload | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get release | |
id: get_release | |
uses: bruceadams/[email protected] | |
- name: Download sha256sums | |
uses: actions/download-artifact@v4 | |
with: | |
pattern: sha256sums-* | |
merge-multiple: true | |
- name: Combine sha256sums | |
run: | | |
cat sha256-*.txt > sha256sums.txt | |
- name: Delete existing sha256sums | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const release = await github.rest.repos.getReleaseByTag({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
tag: '${{ github.ref_name }}' | |
}); | |
for (const asset of release.data.assets) { | |
if (asset.name === 'sha256sums.txt') { | |
await github.rest.repos.deleteReleaseAsset({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
asset_id: asset.id | |
}); | |
console.log('Deleted existing sha256sums.txt'); | |
break; | |
} | |
} | |
- name: Upload Checksums | |
uses: actions/[email protected] | |
with: | |
upload_url: ${{ steps.get_release.outputs.upload_url }} | |
asset_path: sha256sums.txt | |
asset_name: sha256sums.txt | |
asset_content_type: text/plain |