Skip to content

Commit

Permalink
feat: add oss upload to cd (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShuhaoQing authored Aug 1, 2024
1 parent d1f138f commit 5cead37
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ concurrency:
cancel-in-progress: true

jobs:
upload-cli-artifact-to-oss:
build-and-upload-cli-artifact:
strategy:
matrix:
include:
Expand All @@ -27,17 +27,62 @@ jobs:
permissions:
contents: write
steps:
# Check version
- name: Check if version is semantic
run: echo "${{ github.ref_name }}" | grep -q -E '^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-((0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$'
- name: Check if version is release or beta
run: |
if echo "${{ github.ref_name }}" | grep -q -E '^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$'; then
echo "IS_RELEASE=true" >> $GITHUB_ENV
else
echo "IS_RELEASE=false" >> $GITHUB_ENV
fi
# Build
- name: Checkout
uses: actions/checkout@v3
- name: Set up go
uses: actions/setup-go@v4
- name: Build cocli
run: |
GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} make build-binary
mv bin/cocli bin/cocli-${{ matrix.os }}-${{ matrix.arch }}
cp bin/cocli cocli
cp bin/cocli bin/cocli-${{ matrix.os }}-${{ matrix.arch }}
# Upload to GitHub release
- name: Upload release artifact
uses: softprops/action-gh-release@v2
with:
files: bin/cocli-${{ matrix.os }}-${{ matrix.arch }}

# Upload to oss
- name: Install gzip
run: sudo apt-get update && sudo apt-get install -y gzip
- name: Build release metadata files
if: env.IS_RELEASE == 'true'
run: |
SHA256SUM=$(sha256sum cocli | awk '{print $1}' | xxd -r -p | base64)
echo "{\"Version\": \"${{ github.ref_name }}\", \"Sha256\": \"$SHA256SUM\"}" > ${{ matrix.os }}-${{ matrix.arch }}.json
- name: gzip cocli
run: gzip cocli
- name: Upload cocli to oss corresponding version
uses: tvrcgo/oss-action@master
with:
key-id: ${{ secrets.OSS_ACCESS_KEY_ID }}
key-secret: ${{ secrets.OSS_ACCESS_KEY_SECRET }}
region: oss-cn-hangzhou
bucket: coscene-download
assets: |
cocli.gz:/cocli/${{ github.ref_name }}/${{ matrix.os }}-${{ matrix.arch }}.gz
- name: Upload cocli to oss latest
if: env.IS_RELEASE == 'true'
uses: tvrcgo/oss-action@master
with:
key-id: ${{ secrets.OSS_ACCESS_KEY_ID }}
key-secret: ${{ secrets.OSS_ACCESS_KEY_SECRET }}
region: oss-cn-hangzhou
bucket: coscene-download
assets: |
cocli.gz:/cocli/latest/${{ matrix.os }}-${{ matrix.arch }}.gz
${{ matrix.os }}-${{ matrix.arch }}.json:/cocli/${{ matrix.os }}-${{ matrix.arch }}.json

0 comments on commit 5cead37

Please sign in to comment.