Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Github Actions auto release workflow logic #937

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ jobs:

steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v2
- uses: actions/setup-go@v5
with:
go-version: "1.22.0"
go-version: "1.22.x"
- name: Install pcap
run: sudo apt-get install libpcap-dev
- name: Run coverage
run: make test
- name: Codecov
uses: codecov/[email protected].0
uses: codecov/[email protected].5
with:
files: ./coverage_tdengine.out,./coverage.out
name: codecov-shifu
Expand Down
77 changes: 77 additions & 0 deletions .github/workflows/create-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Publish Release

on:
workflow_dispatch:

jobs:
publish_release:
runs-on: ubuntu-latest

steps:
- name: checkout code
uses: actions/checkout@v2

- name: set up Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"

- name: get latest tag
id: get_latest_tag
run: |
git fetch --tags
latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`)
echo "::set-output name=LATEST_TAG::${latest_tag}"
env:
GITHUB_ENV: ${{ env.GITHUB_ENV }}

- name: set version
id: set_version_auto
run: |
current_tag="${{ steps.get_latest_tag.outputs.LATEST_TAG }}"
current_tag=${current_tag#v}
if [[ "$current_tag" == *"-rc1" ]]; then
current_tag=${current_tag%-rc1}
fi
IFS='.' read -r x y z <<< "$current_tag"
y=$((y + 1))
day_of_week=$(date +%u)
if [ "$day_of_week" -eq 1 ]; then
new_tag="v${x}.${y}.${z}"
else
new_tag="v${x}.${y}.${z}-rc1"
fi
echo "NEW_TAG=${new_tag}" >> "$GITHUB_ENV"
env:
GITHUB_ENV: ${{ env.GITHUB_ENV }}

- name: determine if pre-release
id: determine_pre_release
run: |
day_of_week=$(date +%u)
if [ "$day_of_week" -eq 3 ]; then
echo "::set-output name=PRE_RELEASE::true"
else
echo "::set-output name=PRE_RELEASE::false"
fi

- name: create release
run: |
release_tag="${{ env.NEW_TAG }}"
changelog_content="""## See [CHANGELOG-v0.x.0.md](CHANGELOG/CHANGELOG-v0.x.0.md) for details
## 详细内容请查看 [CHANGELOG-v0.x.0-zh.md](CHANGELOG/CHANGELOG-v0.x.0-zh.md)"""
pre_release="${{ steps.determine_pre_release.outputs.PRE_RELEASE }}"
if [ "$pre_release" == "true" ]; then
gh release create "$release_tag" \
--target main \
--title "$release_tag" \
--generate-notes \
--prerelease
else
gh release create "$release_tag" \
--target main \
--title "$release_tag" \
--notes "$changelog_content"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
90 changes: 90 additions & 0 deletions .github/workflows/handle-merge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Create Tag

on:
workflow_dispatch:

jobs:
handle_merged_pr:
runs-on: ubuntu-latest

steps:
- name: checkout code
uses: actions/checkout@v2

- uses: actions/setup-go@v4
with:
go-version: "1.22.x"

- name: set up git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"

- name: get latest tag
id: get_latest_tag
run: |
git fetch --tags
latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`)
echo "::set-output name=LATEST_TAG::${latest_tag}"
env:
GITHUB_ENV: ${{ env.GITHUB_ENV }}

- name: set version
id: set_version_auto
run: |
current_tag="${{ steps.get_latest_tag.outputs.LATEST_TAG }}"
current_tag=${current_tag#v}
if [[ "$current_tag" == *"-rc1" ]]; then
current_tag=${current_tag%-rc1}
fi
IFS='.' read -r x y z <<< "$current_tag"
y=$((y + 1))
day_of_week=$(date +%u)
if [ "$day_of_week" -eq 1 ]; then
new_tag="v${x}.${y}.${z}"
else
new_tag="v${x}.${y}.${z}-rc1"
fi
echo "NEW_TAG=${new_tag}" >> "$GITHUB_ENV"
env:
GITHUB_ENV: ${{ env.GITHUB_ENV }}

- name: read changelog content
id: read_changelog
run: |
changelog_file="CHANGELOG/CHANGELOG-${new_tag}.md"
changelog_file_zh="CHANGELOG/CHANGELOG-${new_tag}-zh.md"
if [ -f "$changelog_file" ]; then
changelog_content=$(cat $changelog_file)
else
echo "Changelog file not found: $changelog_file"
exit 1
fi
if [ -f "$changelog_file_zh" ]; then
changelog_content_zh=$(cat $changelog_file_zh)
else
echo "Changelog file not found: $changelog_file_zh"
exit 1
fi
combined_changelog="${changelog_content}\n\n${changelog_content_zh}"
echo "::set-output name=CHANGELOG_CONTENT::${combined_changelog}"

- name: make tag
run: |
git checkout main
git pull
git checkout -b "local_release${{ env.NEW_TAG }}"
make tag VERSION="${{ env.NEW_TAG }}"
git commit -am "change tag for release ${{ env.NEW_TAG }}"
git push origin HEAD
env:
GITHUB_ENV: ${{ env.GITHUB_ENV }}

- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
commit-message: change tag for release ${{ env.NEW_TAG }}
title: change tag for release ${{ env.NEW_TAG }}
body: change tag for release ${{ env.NEW_TAG }}
branch: local_release${{ env.NEW_TAG }}
base: release_${{ env.NEW_TAG }}
90 changes: 82 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

name: Auto Generate Release Log

on:
Expand All @@ -12,6 +13,8 @@ on:
target_commitish:
required: true
type: string
schedule:
- cron: '30 15 * * 1,3' # 15:30 Mon, Wed

permissions:
contents: write
Expand All @@ -22,33 +25,104 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: actions/setup-go@v4
with:
go-version: "1.22.0"
- name: set version
go-version: "1.22.x"

- name: check correct week
id: check_week
run: |
day_of_week=$(date +%u)
week_number=$(( ($(date +%s) / (60*60*24*7)) % 2 ))
if [ "$day_of_week" -eq 1 ] && [ "$week_number" -eq 0 ]; then
echo "::set-output name=RUN_WORKFLOW::true"
elif [ "$day_of_week" -eq 3 ] && [ "$week_number" -eq 1 ]; then
echo "::set-output name=RUN_WORKFLOW::true"
else
echo "::set-output name=RUN_WORKFLOW::false"
fi

- name: set up git
if: steps.check_week.outputs.RUN_WORKFLOW == 'true'
run: |
echo "VERSION=$(echo "${{inputs.tag_name}}" | cut -d '-' -f1)" >> "$GITHUB_ENV"
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"

- name: get latest tag
if: github.event_name != 'workflow_dispatch' && steps.check_week.outputs.RUN_WORKFLOW == 'true'
id: get_latest_tag
run: |
git fetch --tags
latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`)
echo "::set-output name=LATEST_TAG::${latest_tag}"

- name: manually set version
if: github.event_name == 'workflow_dispatch' && steps.check_week.outputs.RUN_WORKFLOW == 'true'
id: set_version
run: |
new_tag="${{ github.event.inputs.tag_name }}"
current_tag="${{ github.event.inputs.previous_tag_name }}"
echo "NEW_TAG=${new_tag}" >> "$GITHUB_ENV"
env:
GITHUB_ENV: ${{ env.GITHUB_ENV }}

- name: automatically set version
if: github.event_name != 'workflow_dispatch' && steps.check_week.outputs.RUN_WORKFLOW == 'true'
id: set_version_auto
run: |
current_tag="${{ steps.get_latest_tag.outputs.LATEST_TAG }}"
current_tag=${current_tag#v}
if [[ "$current_tag" == *"-rc1" ]]; then
current_tag=${current_tag%-rc1}
fi
IFS='.' read -r x y z <<< "$current_tag"
y=$((y + 1))
day_of_week=$(date +%u)
if [ "$day_of_week" -eq 1 ]; then
new_tag="v${x}.${y}.${z}"
else
new_tag="v${x}.${y}.${z}-rc1"
fi
echo "NEW_TAG=${new_tag}" >> "$GITHUB_ENV"
env:
GITHUB_ENV: ${{ env.GITHUB_ENV }}

- name: generate changelog
if: steps.check_week.outputs.RUN_WORKFLOW == 'true'
run: |
set -e
target_commitish="${{ github.event.inputs.target_commitish || 'main' }}"
response=$(curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/Edgenesis/shifu/releases/generate-notes \
-d '{"tag_name":"${{inputs.tag_name}}","target_commitish":"${{inputs.target_commitish}}","previous_tag_name":"${{inputs.previous_tag_name}}"}')
-d '{"tag_name":"${{ env.NEW_TAG }}","target_commitish":"'"${target_commitish}"'","previous_tag_name":"${{ env.PREVIOUS_TAG }}"}')
echo $response
go run tools/release/release.go "$response"
env:
AZURE_OPENAI_APIKEY: ${{ secrets.AZURE_OPENAI_APIKEY }}
AZURE_OPENAI_HOST: ${{ secrets.AZURE_OPENAI_HOST }}
DEPLOYMENT_NAME: ${{secrets.DEPLOYMENT_NAME}}
GITHUB_ENV: ${{ env.GITHUB_ENV }}

- name: Create Pull Request
if: steps.check_week.outputs.RUN_WORKFLOW == 'true'
uses: peter-evans/create-pull-request@v5
with:
commit-message: add changelog for ${{env.VERSION}}
title: add changelog for ${{env.VERSION}}
body: add changelog for ${{env.VERSION}}
branch: changelog-${{env.VERSION}}
commit-message: add changelog for ${{ env.NEW_TAG }}
title: add changelog for ${{ env.NEW_TAG }}
body: add changelog for ${{ env.NEW_TAG }}
branch: changelog-${{ env.NEW_TAG }}
base: main

- name: make release branch
run: |
git checkout main
git pull
git checkout -b "release_${{ env.NEW_TAG }}"
git push origin HEAD
env:
GITHUB_ENV: ${{ env.GITHUB_ENV }}
Loading