feat: add github action (#2)

Co-authored-by: fengcaiwen <fengcaiwen@bytedance.com>
This commit is contained in:
naison 2023-05-29 17:32:28 +08:00 committed by GitHub
parent 929cd70212
commit 2ae4f52b93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 218 additions and 5 deletions

14
.github/release-note.sh vendored Executable file
View File

@ -0,0 +1,14 @@
#!/usr/bin/env bash
RELEASE=${RELEASE:-$2}
PREVIOUS_RELEASE=${PREVIOUS_RELEASE:-$1}
# ref https://stackoverflow.com/questions/1441010/the-shortest-possible-output-from-git-log-containing-author-and-date
CHANGELOG=$(git log --no-merges --date=short --pretty=format:'- %h %an %ad %s' "${PREVIOUS_RELEASE}".."${RELEASE}")
cat <<EOF
## ${RELEASE}
Bioos ${RELEASE} is available now ! 🎉
## Changelog
${CHANGELOG}
EOF

75
.github/workflows/release.yml vendored Normal file
View File

@ -0,0 +1,75 @@
name: Release
on:
push:
tags:
- "v*"
permissions: write-all
jobs:
build:
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.19
check-latest: true
cache: true
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Release Note
run: |
RELEASE_VERSION=${GITHUB_REF#refs/*/}
PREVERSION=$(git for-each-ref --sort='-creatordate' --format='%(refname:lstrip=2)' --count=50 'refs/tags/*' | grep -v 'rc' | awk 'NR==2')
echo ${PREVERSION}
echo ${PREVERSION}
echo "$(./.github/release-note.sh ${PREVERSION} ${RELEASE_VERSION})" > release_note.md
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
body_path: release_note.md
- name: Collect Release Info
run: |
echo "${{ steps.create_release.outputs.upload_url }}" >> UPLOAD_URL
echo ${{ env.RELEASE_VERSION }} >> RELEASE_VERSION
git reset --hard
- name: Upload RELEASE_VERSION
uses: actions/upload-artifact@v2
with:
name: RELEASE_VERSION
path: RELEASE_VERSION
- name: Upload UPLOAD_URL
uses: actions/upload-artifact@v2
with:
name: UPLOAD_URL
path: UPLOAD_URL
- name: Push image to docker hub
run: |
echo ${{ secrets.DOCKER_HUB_TOKEN }} | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin
docker buildx create --use
make tools.install
make install.womtool
make image.buildx
- name: Repository Dispatch
uses: aurelien-baudet/workflow-dispatch@v2
with:
workflow: Upload_release
token: ${{ secrets.REPOSITORYDISPATCH }}
inputs: '{"url": "${{ steps.create_release.outputs.upload_url }}", "tag": "${{ github.ref_name }}"}'

58
.github/workflows/upload_release.yml vendored Normal file
View File

@ -0,0 +1,58 @@
name: Upload_release
on:
workflow_dispatch:
inputs:
url:
description: 'github release url'
required: true
tag:
description: 'latest tag'
required: true
permissions: write-all
jobs:
build:
name: Create Release
runs-on: ubuntu-latest
strategy:
matrix:
os: [ darwin, windows, linux ]
arch: [ amd64, arm64 ]
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.19
check-latest: true
cache: true
- name: Checkout code
uses: actions/checkout@v2
- name: Build bioctl
run: |
git tag ${{ github.event.inputs.tag }} || true
GO_OUT_EXT=""
if [ "${{ matrix.os }}" = "windows" ]; then
GO_OUT_EXT=".exe"
fi
export PLATFORM=${{ matrix.os }}_${{ matrix.arch }}
make tools.install
make install.womtool
make web.install
make go.build
shasum -a 256 ./_output/platforms/${{ matrix.os }}/${{ matrix.arch }}/bioctl${GO_OUT_EXT} | awk '{print $1}' > checksums.txt
zip -r bioos_${{ github.event.inputs.tag }}_${{ matrix.os }}_${{ matrix.arch }}.zip ./_output/platforms/${{ matrix.os }}/${{ matrix.arch }}/bioctl${GO_OUT_EXT} ./_output/platforms/${{ matrix.os }}/${{ matrix.arch }}/apiserver${GO_OUT_EXT} LICENSE README.md README_ZH.md checksums.txt
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.inputs.url }}
asset_path: ./bioos_${{ github.event.inputs.tag }}_${{ matrix.os }}_${{ matrix.arch }}.zip
asset_name: bioos_${{ github.event.inputs.tag }}_${{ matrix.os }}_${{ matrix.arch }}.zip
asset_content_type: application/zip

View File

@ -8,7 +8,7 @@ include hack/make-rules/tools.mk
ROOT_PACKAGE=github.com/Bio-OS/bioos
VERSION ?= $(shell git describe --tags --always --dirty)
GIT_BRANCH ?= $(shell git branch | grep \* | cut -d ' ' -f2)
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
GIT_COMMIT ?= $(shell git rev-parse HEAD)
GIT_TREE_STATE ?= $(if $(shell git status --porcelain),dirty,clean)
GIT_BUILD_TIME ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")

View File

@ -1,6 +1,7 @@
FROM node:16-alpine3.16 as build
WORKDIR /usr/app
COPY /web /usr/app/
COPY /conf/nginx.conf /usr/app/nginx.conf
RUN npm install && npm run build
FROM nginx:1.21-alpine

View File

@ -1,7 +1,7 @@
DOCKER := docker
IMAGES_DIR ?= $(wildcard ${ROOT_DIR}/build/*)
IMAGES ?= $(foreach image,${IMAGES_DIR},$(notdir ${image}))
IMAGE_REGISTRY ?= quay.io/bioos
IMAGE_REGISTRY ?= docker.io/howardshaw
.PHONY: image.verify
image.verify:

View File

@ -1,4 +1,4 @@
//go:build 386
//go:build windows
package prompt

View File

@ -14,7 +14,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !linux
//go:build !linux && !windows
package exec
@ -53,7 +53,7 @@ func Exec(ctx context.Context, timeout time.Duration, name string, arg ...string
select {
case <-ctx.Done():
// Command was timeout
syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL) // Kill process group
cmd.Process.Kill() // Kill process group
return nil, fmt.Errorf("command timeout:%w", ctx.Err())
case err := <-done:
if err != nil {

View File

@ -0,0 +1,65 @@
//
// Copyright 2023 Beijing Volcano Engine Technology Ltd.
// Copyright 2023 Guangzhou Laboratory
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build windows
package exec
import (
"bytes"
"context"
"fmt"
"os/exec"
"syscall"
"time"
)
func Exec(ctx context.Context, timeout time.Duration, name string, arg ...string) ([]byte, error) {
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
cmd := exec.CommandContext(ctx, name, arg...)
cmd.SysProcAttr = &syscall.SysProcAttr{
HideWindow: true,
}
var b bytes.Buffer
// Set process IO
cmd.Stdout = &b
cmd.Stderr = &b
// Start process
if err := cmd.Start(); err != nil {
return nil, err
}
// Wait for process to complete or timeout
done := make(chan error, 1)
go func() {
done <- cmd.Wait()
}()
select {
case <-ctx.Done():
// Command was timeout
cmd.Process.Kill() // Kill process group
return nil, fmt.Errorf("command timeout:%w", ctx.Err())
case err := <-done:
if err != nil {
return nil, err
}
}
return b.Bytes(), nil
}