From 7d463bd5ee4d16f6d7b8a06125298cbf6d10e804 Mon Sep 17 00:00:00 2001 From: sunwei Date: Mon, 21 Oct 2024 19:16:06 +0800 Subject: [PATCH] add: github action for release --- .github/workflows/release.yml | 54 +++++++++++++++ .gitignore | 2 + README.md | 7 +- command.sh | 68 ++++++++++++++++++- internal/interfaces/api/handler/handleedit.go | 3 +- internal/interfaces/cli/vercurr.go | 8 +++ internal/interfaces/cli/version.go | 7 -- manifest.json | 7 ++ 8 files changed, 145 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 internal/interfaces/cli/vercurr.go create mode 100644 manifest.json diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..b854318 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,54 @@ +# .github/workflows/release.yaml + +name: Release +on: + push: + tags: + - '**' + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Generate Release Notes + id: generate_release_notes + run: | + release_notes=$(git log $(git describe --tags --abbrev=0)..HEAD --oneline) + echo "RELEASE_NOTES<> $GITHUB_ENV + echo "$release_notes" >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.HUGOVERSE_RELEASE }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + draft: false + prerelease: false + body: ${{ env.RELEASE_NOTES }} + + releases-matrix: + needs: release + name: Release Go Binary + runs-on: ubuntu-latest + strategy: + matrix: + goos: [linux, darwin] + goarch: [amd64, arm64] + exclude: + - goarch: arm64 + goos: windows + steps: + - uses: actions/checkout@v3 + - uses: wangyoucao577/go-release-action@v1 + with: + github_token: ${{ secrets.SP_RELEASE }} + goos: ${{ matrix.goos }} + goarch: ${{ matrix.goarch }} + extra_files: LICENSE README.md manifest.json \ No newline at end of file diff --git a/.gitignore b/.gitignore index 86378af..be5fd0a 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,5 @@ hugov /dddplayer/ /public/ + +release-notes.md diff --git a/README.md b/README.md index 3d207c5..2a9e32f 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,11 @@ Hugo headless CMS server ## Prerequisite -- Go -- Dart Sass +Take MacOS for example: + +- Go: +- Dart Sass: brew install sass/sass/sass +- jq: brew install jq ## PoC diff --git a/command.sh b/command.sh index 3718698..b2b0c62 100755 --- a/command.sh +++ b/command.sh @@ -64,6 +64,70 @@ command_coverage() { go tool cover -func=coverage.out } +# Command Usage: bump +# Command Description: Bump version +command_bump() { + # 定义文件路径 + MANIFEST_FILE="manifest.json" + VERCURR_FILE="./internal/interfaces/cli/vercurr.go" + + # 检查文件是否存在 + if [[ ! -f "$MANIFEST_FILE" ]]; then + echo "Error: $MANIFEST_FILE does not exist." + exit 1 + fi + + if [[ ! -f "$VERCURR_FILE" ]]; then + echo "Error: $VERCURR_FILE does not exist." + exit 1 + fi + + # 读取当前的 version + current_version=$(jq -r '.version' "$MANIFEST_FILE") + + # 分割 version 字符串,提取主版本号、中版本号、修订号 + IFS='.' read -r major minor patch <<< "$current_version" + + # 对最后一位修订号进行递增 + new_patch=$((patch + 1)) + + # 生成新的版本号 + new_version="$major.$minor.$new_patch" + + # 更新 manifest.json 文件中的 version + jq --arg new_version "$new_version" '.version = $new_version' "$MANIFEST_FILE" > tmp.json && mv tmp.json "$MANIFEST_FILE" + + # 更新 vercurr.go 文件的内容 + cat > "$VERCURR_FILE" << EOL +package cli + +var CurrentVersion = Version{ + Major: $major, + Minor: $minor, + PatchLevel: $new_patch, + Suffix: "", +} +EOL + + echo "Version bumped to $new_version and vercurr.go updated" +} + + + +# Command Usage: rn +# Command Description: Get release notes +command_release_notes() { + # 获取最新的 release notes + release_notes=$(git log $(git describe --tags --abbrev=0)..HEAD --oneline) + + # 打印 release notes 到屏幕上 + echo "### Release Notes:" + echo "$release_notes" + + # 保存 release notes 到文件,并添加到 Git 暂存区 + echo "$release_notes" > release-notes.md +} + check_msg() { printf "\xE2\x9C\x94 ${1}\n" } @@ -86,7 +150,7 @@ main() { exit 0 ;; - tag|test|coverage) + tag|test|coverage|bump|rn) set_command "${1}" ;; @@ -106,6 +170,8 @@ main() { coverage) command_coverage;; clean) command_clean;; tag) command_tag;; + bump) command_bump;; + rn) command_release_notes;; *) option_help; exit 1;; esac diff --git a/internal/interfaces/api/handler/handleedit.go b/internal/interfaces/api/handler/handleedit.go index 2cbdb76..996aa14 100644 --- a/internal/interfaces/api/handler/handleedit.go +++ b/internal/interfaces/api/handler/handleedit.go @@ -69,7 +69,8 @@ func (s *Handler) EditHandler(res http.ResponseWriter, req *http.Request) { sel, ok := post.(content.RefSelectable) if ok { selContentTypes := sel.SelectContentTypes() - var data map[string][][]byte + data := make(map[string][][]byte) + for _, ct := range selContentTypes { data[ct] = s.db.AllContent(ct) } diff --git a/internal/interfaces/cli/vercurr.go b/internal/interfaces/cli/vercurr.go new file mode 100644 index 0000000..252c3dc --- /dev/null +++ b/internal/interfaces/cli/vercurr.go @@ -0,0 +1,8 @@ +package cli + +var CurrentVersion = Version{ + Major: 0, + Minor: 0, + PatchLevel: 0, + Suffix: "", +} diff --git a/internal/interfaces/cli/version.go b/internal/interfaces/cli/version.go index bb6fbe5..a052e90 100644 --- a/internal/interfaces/cli/version.go +++ b/internal/interfaces/cli/version.go @@ -108,13 +108,6 @@ func getBuildInfo() *buildInfo { return bInfo } -var CurrentVersion = Version{ - Major: 0, - Minor: 1, - PatchLevel: 0, - Suffix: "-DEV", -} - // Version represents the Hugo build version. type Version struct { Major int diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..41fd394 --- /dev/null +++ b/manifest.json @@ -0,0 +1,7 @@ +{ + "version": "0.0.0", + "name": "Hugoverse", + "description": "Headless CMS for Hugo", + "author": "sunwei", + "authorUrl": "https://github.com/sunwei" +}