From e143c73d187f1de0e4a7d3921c71b8c9ab327d69 Mon Sep 17 00:00:00 2001 From: WMYeah_Mac Date: Tue, 11 Jun 2024 18:05:41 +0800 Subject: [PATCH] cju --- .github/workflows/check.yml | 2 - .github/workflows/generate-libs.yml | 66 ------------- .github/workflows/release.yml | 137 ++++++++++++++++++++++++++ .github/workflows/static-analysis.yml | 41 -------- config/config.go | 2 +- 5 files changed, 138 insertions(+), 110 deletions(-) delete mode 100644 .github/workflows/generate-libs.yml create mode 100644 .github/workflows/release.yml delete mode 100644 .github/workflows/static-analysis.yml diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index a1992b6..5fd3686 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -1,8 +1,6 @@ name: Check on: - push: - branches: [ "main" ] pull_request: branches: [ "main" ] diff --git a/.github/workflows/generate-libs.yml b/.github/workflows/generate-libs.yml deleted file mode 100644 index 9e040d8..0000000 --- a/.github/workflows/generate-libs.yml +++ /dev/null @@ -1,66 +0,0 @@ -name: Generate libraries - -on: - workflow_dispatch: - -jobs: - generate: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [macos-latest, ubuntu-latest, windows-latest] - - steps: - - name: Determine library paths - id: lib-paths - shell: bash - run: | - if [[ "$RUNNER_OS" == "Windows" ]]; then - OS="windows" - elif [[ "$RUNNER_OS" == "Linux" ]]; then - OS="linux" - elif [[ "$RUNNER_OS" == "macOS" ]]; then - OS="darwin" - else - echo "Unknown RUNNER_OS: $RUNNER_OS" - exit 1 - fi - if [[ "$RUNNER_ARCH" == "X86" ]]; then - ARCH="386" - elif [[ "$RUNNER_ARCH" == "X64" ]]; then - ARCH="amd64" - elif [[ "$RUNNER_ARCH" == "ARM" ]]; then - ARCH="arm" - elif [[ "$RUNNER_ARCH" == "ARM64" ]]; then - ARCH="arm64" - else - echo "Unknown RUNNER_ARCH: $RUNNER_ARCH" - exit 1 - fi - echo "cgo_path=cgo_${OS}_${ARCH}.go" >> $GITHUB_OUTPUT - echo "lib_path=lib/${OS}/${ARCH}" >> $GITHUB_OUTPUT - - - name: Install dependencies - if: matrix.os == 'ubuntu-latest' - run: sudo apt-get update && sudo apt-get install -y libx11-dev libxext-dev libxft-dev libxinerama-dev libxcursor-dev libxrender-dev libxfixes-dev libgl1-mesa-dev libglu1-mesa-dev - - - name: Check out code - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: "1.20.x" - - - name: Run go generate - run: go generate - - - name: Archive generated files - uses: actions/upload-artifact@v3 - with: - name: libs - path: | - ${{ steps.lib-paths.outputs.lib_path }}/*.a - ${{ steps.lib-paths.outputs.lib_path }}/FL/fl_config.h - include - ${{ steps.lib-paths.outputs.cgo_path }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..4e2f5a5 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,137 @@ +# This workflow will build a golang project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go + +name: Go build + +env: + ProductName: fltk_go + +on: + push: + tags: + - 'v*' + +jobs: + Testing: + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + arch: [amd64, arm64] + exclude: + - os: windows-latest + arch: arm64 + runs-on: ${{ matrix.os }} + + steps: + - name: CheckOut + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '>=1.18.0' + + - name: Set BUILD envs for Linux + if: matrix.os == 'ubuntu-latest' + run: | + sudo apt-get update && sudo apt-get install -y libpango1.0-dev libx11-dev libxext-dev libxft-dev libxinerama-dev libxcursor-dev libxrender-dev libxfixes-dev libpng-dev libgl1-mesa-dev libglu1-mesa-dev + + - name: Set BUILD envs for Windows + if: matrix.os == 'windows-latest' + shell: bash + run: | + choco install mingw --version 11.2.0.07112021 --allow-downgrade + + - name: do testing + shell: bash + run: | + go test + + Release: + runs-on: ubuntu-latest + needs: Testing + outputs: + UPLOAD_URL: ${{ steps.stepCreateRelease.outputs.upload_url }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Get latest tag + run: | + echo "LATEST_TAG=$(git tag | grep -v '^latest$' | sort -V | tail -n1)" >> $GITHUB_ENV + + - name: Bump version and push tag + id: tag-version + uses: mathieudutour/github-tag-action@v6.2 + with: + tag_prefix: "" + custom_tag: ${{ env.LATEST_TAG }} + github_token: ${{ secrets.GITHUB_TOKEN }} + + - name: Step GitHub release + id: stepCreateRelease + uses: ncipollo/release-action@v1 + with: + skipIfReleaseExists: 'true' + tag: ${{ env.LATEST_TAG }} + name: ${{ env.LATEST_TAG }} + + RemoveOldRelease: + runs-on: ubuntu-latest + needs: Release + steps: + - name: install github-cli + run: | + type -p curl >/dev/null || sudo apt install curl -y + curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \ + && sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \ + && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \ + && sudo apt update \ + && sudo apt install gh -y + + - name: CheckOut + uses: actions/checkout@v4 + + - name: Set APP_VERSION env + run: | + APP_VERSION=$(echo ${GITHUB_REF} | rev | cut -d'/' -f 1 | rev ) \ + + function get_pre_del_tag { + local v_str=$1 + baseStr=$(echo $v_str | cut -d'.' -f1) + base=${baseStr//v/} + major=$(echo $v_str | cut -d'.' -f2) + minor=$(echo $v_str | cut -d'.' -f3) + + if ((minor>0)); then + minor=$((minor-1)) + else + minor=999 + if ((major>0)); then + major=$((major-1)) + else + major=999 + if ((base>0)); then + base=$((base-1)) + else + echo "Error: Version cannot be decremented." + exit 1 + fi + fi + fi + + pre_v_no="v${base}.${major}.${minor}" + echo $pre_v_no + } + + APP_OLD_VERSION=$(get_pre_del_tag $(get_pre_del_tag $APP_VERSION)) + + echo "Old version to remove: ${APP_OLD_VERSION}" + echo APP_OLD_VERSION=${APP_OLD_VERSION} >> ${GITHUB_ENV} + + - name: Remove Old Release + run: | + gh release delete ${{ env.APP_OLD_VERSION }} -y + git push origin --delete ${{ env.APP_OLD_VERSION }} + env: + GH_TOKEN: ${{ github.token }} \ No newline at end of file diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml deleted file mode 100644 index fa8a413..0000000 --- a/.github/workflows/static-analysis.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Static analysis - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -jobs: - - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: '1.20.x' - - - name: Download deps - run: | - if [ "$RUNNER_OS" == "Linux" ]; then - sudo apt-get update && sudo apt-get install -y libpango1.0-dev libx11-dev libxext-dev libxft-dev libxinerama-dev libxcursor-dev libxrender-dev libxfixes-dev libpng-dev libgl1-mesa-dev libglu1-mesa-dev - fi - shell: bash - - - name: Install analysis tools - run: | - go install golang.org/x/tools/cmd/goimports@latest - go install honnef.co/go/tools/cmd/staticcheck@latest - - - name: Vet - run: go vet ./... - - - name: Goimports - run: test -z "$(goimports -e -d . | tee /dev/stderr)" - - - name: Staticcheck - run: staticcheck ./... diff --git a/config/config.go b/config/config.go index 4bfea3e..e2e0b31 100644 --- a/config/config.go +++ b/config/config.go @@ -2,5 +2,5 @@ package config const ( ProjectName = "fltk_go" - ProjectVersion = "v0.0.1" + ProjectVersion = "v0.0.2" )