Skip to content

Commit

Permalink
add: github action for release
Browse files Browse the repository at this point in the history
  • Loading branch information
sunwei committed Oct 21, 2024
1 parent 53a206f commit 7d463bd
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 11 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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<<EOF" >> $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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ hugov

/dddplayer/
/public/

release-notes.md
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
68 changes: 67 additions & 1 deletion command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -86,7 +150,7 @@ main() {
exit 0
;;

tag|test|coverage)
tag|test|coverage|bump|rn)
set_command "${1}"
;;

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion internal/interfaces/api/handler/handleedit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 8 additions & 0 deletions internal/interfaces/cli/vercurr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package cli

var CurrentVersion = Version{
Major: 0,
Minor: 0,
PatchLevel: 0,
Suffix: "",
}
7 changes: 0 additions & 7 deletions internal/interfaces/cli/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"version": "0.0.0",
"name": "Hugoverse",
"description": "Headless CMS for Hugo",
"author": "sunwei",
"authorUrl": "https://github.com/sunwei"
}

0 comments on commit 7d463bd

Please sign in to comment.