diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 57238f857..8bf7be10e 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -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/codecov-action@v3.1.0 + uses: codecov/codecov-action@v3.1.5 with: files: ./coverage_tdengine.out,./coverage.out name: codecov-shifu diff --git a/.github/workflows/create-release.yaml b/.github/workflows/create-release.yaml new file mode 100644 index 000000000..2527589a0 --- /dev/null +++ b/.github/workflows/create-release.yaml @@ -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 }} diff --git a/.github/workflows/handle-merge.yaml b/.github/workflows/handle-merge.yaml new file mode 100644 index 000000000..40eba1b2e --- /dev/null +++ b/.github/workflows/handle-merge.yaml @@ -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 }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9f8f266ac..7667b23e0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,3 +1,4 @@ + name: Auto Generate Release Log on: @@ -12,6 +13,8 @@ on: target_commitish: required: true type: string + schedule: + - cron: '30 15 * * 1,3' # 15:30 Mon, Wed permissions: contents: write @@ -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 }}