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 2 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
45 changes: 45 additions & 0 deletions .github/workflows/build.yml
David-Han48 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# 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: build

on:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.22.x'
cache-dependency-path: go.sum
- name: Install dependencies
run: |
go mod tidy -v
sudo apt-get install libpcap-dev docker docker-compose
- name: Build executable files
run: |
make build
- name: build images
run: |
make buildx-build-image-deviceshifu
make buildx-push-image-deviceshifu
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: Build artifacts
path: |

- name: Create Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
body: ${{ github.event.head_commit.message }}
draft: false
prerelease: false
8 changes: 4 additions & 4 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ 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
fail_ci_if_error: true
verbose: true
verbose: true
194 changes: 186 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ on:
target_commitish:
required: true
type: string
schedule:
- cron: '30 15 * * 1' # 15:30 Mon
David-Han48 marked this conversation as resolved.
Show resolved Hide resolved
- cron: '30 15 * * 4' # 15:30 Thu
David-Han48 marked this conversation as resolved.
Show resolved Hide resolved

permissions:
contents: write
Expand All @@ -22,33 +25,208 @@ 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"
else if [ "$day_of_week" -eq 4 ] && [ "$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: |
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: set version by manual
David-Han48 marked this conversation as resolved.
Show resolved Hide resolved
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"
echo "PREVIOUS_TAG=${current_tag}" >> "$GITHUB_ENV"
env:
GITHUB_ENV: ${{ env.GITHUB_ENV }}

- name: set version by automatic
David-Han48 marked this conversation as resolved.
Show resolved Hide resolved
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_version=$(echo "${current_tag}" | cut -d'.' -f2)
next_version=$((current_version + 1))
day_of_week=$(date +%u)
if [ "$day_of_week" -eq 1 ]; then
new_tag="v0.${next_version}.0-rc1"
else
new_tag="v0.${next_version}.0"
fi
echo "NEW_TAG=${new_tag}" >> "$GITHUB_ENV"
echo "PREVIOUS_TAG=${current_tag}" >> "$GITHUB_ENV"
env:
GITHUB_ENV: ${{ env.GITHUB_ENV }}

- name: parse env (for scheduled runs)
if: github.event_name != 'workflow_dispatch' && steps.check_week.outputs.RUN_WORKFLOW == 'true'
run: |
echo "VERSION=$(echo "${{inputs.tag_name}}" | cut -d '-' -f1)" >> "$GITHUB_ENV"
current_tag="${{ steps.get_latest_tag.outputs.LATEST_TAG }}"
current_version=$(echo "${current_tag}" | cut -d'.' -f2)
next_version=$((current_version + 1))
new_tag="v0.${next_version}.0"
David-Han48 marked this conversation as resolved.
Show resolved Hide resolved
echo "VERSION=${new_tag}" >> "$GITHUB_ENV"
echo "PREVIOUS_TAG=${current_tag}" >> "$GITHUB_ENV"
echo "Print env:VERSION and env:PREVIOUS_TAG"
echo "VERSION=${new_tag}"
echo "PREVIOUS_TAG=${current_tag}"
- 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: Fetch Pull Request Number
if: steps.check_week.outputs.RUN_WORKFLOW == 'true'
id: get-pr
run: |
PR_NUMBER=$(gh pr list --base main --head changelog-${{ env.NEW_TAG }} --json number --jq '.[0].number')
echo $PR_NUMBER
echo "PR_NUMBER=${PR_NUMBER}" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Merge Pull Request
David-Han48 marked this conversation as resolved.
Show resolved Hide resolved
if: steps.check_week.outputs.RUN_WORKFLOW == 'true'
run: |
gh pr merge ${{ env.PR_NUMBER }} --auto --merge
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: read changelog content
if: steps.check_week.outputs.RUN_WORKFLOW == 'true'
id: read_changelog
run: |
echo ${{ env.NEW_TAG }}
changelog_file="CHANGELOG/testChangelog"
David-Han48 marked this conversation as resolved.
Show resolved Hide resolved
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: checkout main branch
if: steps.check_week.outputs.RUN_WORKFLOW == 'true'
run: |
git checkout main
git pull

- name: create local branch
if: steps.check_week.outputs.RUN_WORKFLOW == 'true'
run: |
new_tag="${{ env.NEW_TAG }}"
branch_name="release_${new_tag}"
git checkout -b $branch_name
echo "BRANCH_NAME=${branch_name}" >> "$GITHUB_ENV"

- name: make tag
if: steps.check_week.outputs.RUN_WORKFLOW == 'true'
run: |
new_tag="${{ env.NEW_TAG }}"
make tag VERSION="${new_tag}"
echo "BRANCH NAME = ${{ env.BRANCH_NAME }}"
git commit -am "change tag for release ${new_tag}"
echo "BEFORE TAG"
git show-ref
git tag ${new_tag}
echo "AFTER TAG"
git show-ref
git push origin ${new_tag}
David-Han48 marked this conversation as resolved.
Show resolved Hide resolved
git push origin "release_${new_tag}"

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

- name: create release
if: steps.check_week.outputs.RUN_WORKFLOW == 'true'
run: |
release_tag="${{ env.NEW_TAG }}"
echo ${release_tag}
changelog_content="${{ steps.read_changelog.outputs.CHANGELOG_CONTENT }}"
echo ${changelog_content}
pre_release="${{ steps.determine_pre_release.outputs.PRE_RELEASE }}"
if [ "$pre_release" == "true" ]; then
gh release create $release_tag \
--target main \
--title "$release_tag" \
--notes "$changelog_content" \
--prerelease
else
gh release create $release_tag \
--target main \
--title "$release_tag" \
--notes "$changelog_content"
David-Han48 marked this conversation as resolved.
Show resolved Hide resolved
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Loading