Skip to content

Commit

Permalink
Merge pull request #24 from ty-dc/robot/cp-use-label
Browse files Browse the repository at this point in the history
Optimize robots
  • Loading branch information
weizhoublue authored Mar 4, 2024
2 parents 007b1c7 + 79850e3 commit eed1dd1
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 36 deletions.
41 changes: 27 additions & 14 deletions .github/workflows/auto-cherrypick.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,32 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

# ${{ secrets.GITHUB_TOKEN }} is forbidden to create or approve pull requests
- uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true

- name: cherry pick
env:
GITHUB_TOKEN: ${{ secrets.WELAN_PAT}}
GITHUB_TOKEN: ${{ secrets.WELAN_PAT }}
JSON: ${{ toJSON(github) }}
run: |
set -x
echo "============ print var ======== "
if ${{ github.event_name == 'workflow_dispatch' }}; then
PR_NUMBER=${{ github.event.inputs.prNumber }}
else
grep -Eio "Merge pull request #[0-9]+ " <<< "${JSON}" || true
grep -Eio "Merge pull request #[0-9]+ " <<< "${JSON}" || true
echo "try to get PR from commit"
COMMIT=` echo "${JSON}" | jq '.event.commits[0].id' | tr -d '"' ` || true
if [ -n "${COMMIT}" ]; then
PR_NUMBER=`curl -s -H "Accept: application/vnd.github.groot-preview+json" https://api.github.com/repos/${{ github.repository }}/commits/${COMMIT}/pulls | jq -r '.[].number' `
PR_NUMBER=`curl --retry 10 -s -H "Accept: application/vnd.github.groot-preview+json" https://api.github.com/repos/${{ github.repository }}/commits/${COMMIT}/pulls | jq -r '.[].number' `
else
echo "error, failed to get any commit ID"
fi
Expand All @@ -63,7 +69,7 @@ jobs:
# [ -n "${PR_AUTHOR}" ] || { echo "no PR_AUTHOR, ignore" ; }
#
fi
RP_API_BODY=` curl https://api.github.com/repos/${{ github.repository }}/pulls/${PR_NUMBER} -s -H "Accept: application/vnd.github.groot-preview+json" `
RP_API_BODY=` curl --retry 10 https://api.github.com/repos/${{ github.repository }}/pulls/${PR_NUMBER} -s -H "Accept: application/vnd.github.groot-preview+json" `
PR_COMMITS=` echo "${RP_API_BODY}" | jq ' .merge_commit_sha ' | tr -d '"' `
PR_AUTHOR=` echo "${RP_API_BODY}" | jq ' .user.login ' | tr -d '"' `
PR_URL="https://github.com/${{ github.repository }}/pull/${PR_NUMBER}"
Expand All @@ -90,25 +96,31 @@ jobs:
#
echo "=============================== get dest branch from labels ======== "
WANT_MERGE_BRANCH_LIST=""
INITIAL_LABEL=""
if ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.destBranch != '' }}; then
WANT_MERGE_BRANCH_LIST=${{ github.event.inputs.destBranch }}
else
for LABEL in ${PR_LABEL} ; do
echo "checking label $LABEL "
PREFIX="${{ env.PR_LABEL_PREFIX_CHERRYPICK }}"
grep -E "^${PREFIX}" <<< "${LABEL}" &>/dev/null || continue
if ! grep -E "^${PREFIX}" <<< "${LABEL}" &>/dev/null; then
INITIAL_LABEL+="${LABEL},"
continue
fi
BRANCH_NAME=` sed 's?'"${PREFIX}"'??' <<< "$LABEL" `
WANT_MERGE_BRANCH_LIST+=" $BRANCH_NAME "
done
fi
[ -z "$WANT_MERGE_BRANCH_LIST" ] && echo "no branch to cherry pick" && exit 0
echo "cherry pick to $WANT_MERGE_BRANCH_LIST "
INITIAL_LABEL="${INITIAL_LABEL%,}"
echo "INITIAL_LABEL: ${INITIAL_LABEL}"
#
#
echo "============ begin to cherry pick ============ "
FINAL_FAILURE=false
git branch
git config user.email "robot@example.com"
git config user.email "tao.yang@daocloud.io"
git config user.name "robot"
gh label create ${{ env.CHERRYPICK_LABEL }} || true
for BRANCH in $WANT_MERGE_BRANCH_LIST ; do
Expand Down Expand Up @@ -151,7 +163,7 @@ jobs:
if ! ERROR_MESSAGE=`git cherry-pick -m 1 $COMMIT 2>&1` ; then
echo ">>>>>>>>>>>> fail when cherry pick $COMMIT to branch $BRANCH "
echo "$ERROR_MESSAGE"
echo "---- failure detail"
echo "---- failuire detail"
git status
git diff
echo "<<<<<<<<<<<<<"
Expand All @@ -175,21 +187,22 @@ jobs:
if [ "$FAIL" == "true" ] ; then
echo "failed to cherry pick to branch $BRANCH "
FINAL_FAILURE=true
echo -e "commits $PR_COMMITS conflict when merging to branch $BRANCH, please manually cherry pick it by yourself. \n PR <${PR_URL}> , action <${ACTION_URL}> \n\n \`\`\`\n${ERROR_MESSAGE}\n\`\`\` " | \
echo -e "commits $PR_COMMITS of ${PR_AUTHOR} conflict when merging to branch $BRANCH, please manually cherry pick it by yourself. \n PR <${PR_URL}> , action <${ACTION_URL}> \n\n \`\`\`\n${ERROR_MESSAGE}\n\`\`\` " | \
gh issue create \
--title "failed to auto cherry pick PR ${PR_NUMBER} to branch ${BRANCH}" \
--title "failed to cherry pick PR ${PR_NUMBER} from ${PR_AUTHOR}, to branch ${BRANCH}" \
--label "${{ env.CHERRYPICK_LABEL }}" \
--assignee "${PR_AUTHOR},${{ env.DEFAULT_REVIEWER }}" \
--body-file -
fi
if [ "$UPDATE" == "true" ] ; then
echo "succeeded to cherry pick to branch $BRANCH "
# create a pr
git commit -s -S --amend --no-edit
git push origin ${PR_BRANCH}:${PR_BRANCH} -f
gh pr create --title "${PR_TITLE}" \
--assignee "${PR_AUTHOR},${{ env.DEFAULT_REVIEWER }}" \
--label ${{ env.CHERRYPICK_LABEL }} \
--body "robot cherry pick pr <${PR_URL}> to branch ${BRANCH}, action <${ACTION_URL}> , commits $PR_COMMITS " \
--label "${{ env.CHERRYPICK_LABEL }},${INITIAL_LABEL}" \
--body "robot cherry pick PR <${PR_URL}> from ${PR_AUTHOR},to branch ${BRANCH}, action <${ACTION_URL}> , commits $PR_COMMITS " \
--base ${BRANCH}
else
echo "no changes happened for commits $PR_COMMITS, ignore create pr"
Expand All @@ -198,7 +211,7 @@ jobs:
echo "=========== check result ============"
if [ "$FINAL_FAILURE" == "true" ] ; then
# if failed to create issue or pr, fails
echo "error, failure happened"
echo "error, failuire happened"
else
echo "all done"
fi
17 changes: 13 additions & 4 deletions .github/workflows/call-release-changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ env:
DEST_BRANCH: github_pages
DEST_DIRECTORY: 'changelogs/'
PR_LABEL: pr/robot_update
PR_REVIWER: weizhoublue
PR_REVIEWER: weizhoublue

on:
workflow_call:
Expand Down Expand Up @@ -41,7 +41,7 @@ jobs:
begin_tag: ${{ env.begin_tag }}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down Expand Up @@ -121,7 +121,7 @@ jobs:
needs: [generate_changelog]
steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ env.DEST_BRANCH }}

Expand All @@ -131,16 +131,25 @@ jobs:
name: changelog_artifact
path: ${{ env.DEST_DIRECTORY }}

- uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true

- name: Create Pull Request
id: create_pr
uses: peter-evans/create-pull-request@v6.0.0
with:
title: "robot update changelog with tag ${{ needs.generate_changelog.outputs.dest_tag }} to branch ${{ env.DEST_BRANCH }} "
commit-message: "robot update changelog from tag ${{ needs.generate_changelog.outputs.begin_tag }} to tag ${{ needs.generate_changelog.outputs.dest_tag }} "
committer: ty-dc <tao.yang@daocloud.io>
branch-suffix: timestamp
branch: robot/update_changelog
delete-branch: true
base: ${{ env.DEST_BRANCH }}
signoff: true
token: ${{ secrets.WELAN_PAT }}
token: ${{ secrets.GITHUB_TOKEN }}
labels: ${{ env.PR_LABEL }}
reviewers: ${{ env.PR_REVIEWER }}
16 changes: 12 additions & 4 deletions .github/workflows/call-release-chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Call Release Chart
env:
MERGE_BRANCH: github_pages
PR_LABEL: pr/robot_update
PR_REVIWER: weizhoublue
PR_REVIEWER: weizhoublue
CHART_OUTPUT_PATH: output/chart/*

on:
Expand Down Expand Up @@ -50,7 +50,7 @@ jobs:
fi
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ env.REF }}
Expand Down Expand Up @@ -83,7 +83,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ env.MERGE_BRANCH }}
fetch-depth: 0
Expand All @@ -106,13 +106,21 @@ jobs:
helm repo index ./charts --url ${url}/charts
mv ./charts/index.yaml ./index.yaml
- uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true

# Allow auto-merge on general
- name: Create Pull Request
id: create_pr
uses: peter-evans/create-pull-request@v6.0.0
uses: peter-evans/create-pull-request@v5.0.2
with:
title: "robot update chart from ${{ needs.package.outputs.REF }} to branch ${{ env.MERGE_BRANCH }} "
commit-message: "robot update chart from ${{ needs.package.outputs.REF }} to branch ${{ env.MERGE_BRANCH }} "
committer: ty-dc <tao.yang@daocloud.io>
branch-suffix: timestamp
branch: robot/update_chart
delete-branch: true
Expand Down
58 changes: 44 additions & 14 deletions .github/workflows/call-release-pages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ name: Call Release Pages
env:
MERGE_BRANCH: github_pages
PR_LABEL: pr/robot_update
PR_REVIWER: weizhoublue
PR_REVIEWER: weizhoublue
DEV_DOC_DIRECTORY: dev

on:
workflow_call:
Expand All @@ -26,8 +27,9 @@ jobs:
name: prepare
runs-on: ubuntu-latest
outputs:
ref: ${{ env.RUN_REF }}
skip_all_job: ${{ env.SKIP_ALL_JOB }}
ref: ${{ env.REF }}
publish_docs_to_dev: ${{ env.PUBLISH_DOCS_TO_DEV }}
doc_tag: ${{ env.DOCS_TAG }}
steps:
- name: Get Ref
id: get_ref
Expand All @@ -46,18 +48,36 @@ jobs:
fi
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ env.REF }}

- name: Set main branch docs to dev (latest)
id: main_docs
if: ${{ env.REF == 'main' }}
run: |
echo "DOCS_TAG=${{ env.REF }}" >> $GITHUB_ENV
pip install mkdocs==1.5.2 mike==1.1.2 mkdocs-material==9.2.8 mkdocs-static-i18n==1.0.2
git config user.email "robot@example.com"
git config user.name "robot"
cp ./docs/mkdocs.yml ./
mike deploy --rebase -b ${{ env.MERGE_BRANCH }} ${{ env.DEV_DOC_DIRECTORY }} -t "${{ env.DEV_DOC_DIRECTORY }} (${{ env.REF }})"
rm -rf ./site && rm -rf ./mkdocs.yml
git checkout -f ${{ env.MERGE_BRANCH }}
rm -rf ./charts && rm -rf ./index.yaml && rm -rf ./changelogs
tar -czvf ./site.tar.gz *
ls
echo "push document version ${{ env.DEV_DOC_DIRECTORY }} from branch ${{ env.REF }}."
- name: Extract Version
id: extract
if: ${{ env.REF != 'main' }}
run: |
if ! grep -E "^[[:space:]]*v[0-9]+.[0-9]+.[0-9]+[[:space:]]*$" VERSION &>/dev/null ; then
echo "not a release version, skip generating doc."
echo "It is not a release version. docs for the corresponding version will not be generated. The documents will be published to 'dev' ."
cat VERSION
echo "SKIP_ALL_JOB=true" >> $GITHUB_ENV
echo "PUBLISH_DOCS_TO_DEV=true" >> $GITHUB_ENV
exit 0
fi
# for example v0.6.1, the build's documentation version is v0.6
Expand All @@ -82,16 +102,20 @@ jobs:
- name: build doc site
id: build_doc
if: ${{ env.SKIP_ALL_JOB != 'true' }}
if: ${{ env.REF != 'main' }}
run: |
git checkout ${{ env.REF }}
ls
echo "switch to the release version branch ${{ env.REF }}"
pip install mkdocs==1.5.2 mike==1.1.2 mkdocs-material==9.2.8
pip install mkdocs==1.5.2 mike==1.1.2 mkdocs-material==9.2.8 mkdocs-static-i18n==1.0.2
git config user.email "robot@example.com"
git config user.name "robot"
cp ./docs/mkdocs.yml ./
if ${{ env.SET_LATEST == 'true' }} ;then
if ${{ env.PUBLISH_DOCS_TO_DEV == 'true' }} ; then
echo "publish non-release version of documentation to dev:${{ env.DEV_DOC_DIRECTORY }}"
echo "DOCS_TAG=${{ env.DEV_DOC_DIRECTORY }}" >> $GITHUB_ENV
mike deploy --rebase -b ${{ env.MERGE_BRANCH }} ${{ env.DEV_DOC_DIRECTORY }} -t "${{ env.DEV_DOC_DIRECTORY }} (${{ env.REF }})"
elif ${{ env.SET_LATEST == 'true' }} ;then
echo "generate doc version:${{ env.DOCS_TAG }} and set to latest."
mike deploy --rebase -b ${{ env.MERGE_BRANCH }} --update-aliases ${{env.DOCS_TAG }} latest
mike set-default -b ${{ env.MERGE_BRANCH }} latest
Expand All @@ -110,7 +134,6 @@ jobs:
- name: Upload Artifact
uses: actions/upload-artifact@v3.1.2
if: ${{ env.SKIP_ALL_JOB != 'true' }}
with:
name: site_artifact
path: site.tar.gz
Expand All @@ -120,11 +143,10 @@ jobs:
create_pr:
name: Create PR
needs: [package]
if: ${{ needs.package.outputs.skip_all_job != 'true' }}
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ env.MERGE_BRANCH }}
fetch-depth: 0
Expand All @@ -140,13 +162,21 @@ jobs:
tar -xzvf site.tar.gz
rm -f site.tar.gz
- uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true

# Allow auto-merge on general
- name: Create Pull Request
id: create_pr
uses: peter-evans/create-pull-request@v6.0.0
with:
title: "robot update website from ${{ needs.package.outputs.REF }} to branch ${{ env.MERGE_BRANCH }} "
commit-message: "robot update website from ${{ needs.package.outputs.REF }} to branch ${{ env.MERGE_BRANCH }} "
title: "robot update website from ${{ needs.package.outputs.ref }} to branch ${{ env.MERGE_BRANCH }} with tag ${{ needs.package.outputs.doc_tag }}"
commit-message: "robot update website from ${{ needs.package.outputs.ref }} to branch ${{ env.MERGE_BRANCH }} with tag ${{ needs.package.outputs.doc_tag }} "
committer: ty-dc <tao.yang@daocloud.io>
branch-suffix: timestamp
branch: robot/update_doc
delete-branch: true
Expand Down

0 comments on commit eed1dd1

Please sign in to comment.