From 8997f1e6173587f89894802539e32e66bbb66bfa Mon Sep 17 00:00:00 2001 From: Marcel Seidel <47413751+m-seidel@users.noreply.github.com> Date: Tue, 2 May 2023 09:44:52 +0200 Subject: [PATCH 1/2] chore: adding new autodev action --- .github/workflows/autodev.yaml | 83 +++------------------------------- 1 file changed, 7 insertions(+), 76 deletions(-) diff --git a/.github/workflows/autodev.yaml b/.github/workflows/autodev.yaml index 821cc7e..e5a85a1 100644 --- a/.github/workflows/autodev.yaml +++ b/.github/workflows/autodev.yaml @@ -1,5 +1,4 @@ name: Autodev - on: push: branches-ignore: @@ -8,78 +7,10 @@ on: types: [labeled, unlabeled, closed] jobs: - dev: - env: - GITHUB_TOKEN: ${{ secrets.DEV_PUSH_TOKEN }} - GITHUB_USER: ${{ secrets.DEV_PUSH_USER }} - BRANCH: dev - runs-on: ubuntu-20.04 - steps: - - name: do-checkout - uses: actions/checkout@v1 - with: - ref: main - - name: build branch - id: build_branch - run: | - touch successful_merges failed_merges - git checkout -B new-${BRANCH} - git config --global user.email "staffbot@staffbase.com" - git config --global user.name "Merge Bot" - # with both dates set to the last main commit, we get reproducible builds: Whenever the CI Job would produce - # the exact same result as the existing branch (as in, nothing on the staged branches or main changed) - # the new branch ref will have the same commit sha than the old one. - export GIT_COMMITTER_DATE=$(git show -s --format='%ci' HEAD) - export GIT_AUTHOR_DATE=$GIT_COMMITTER_DATE - ghcurl() { curl -s -H "Authorization: token ${GITHUB_TOKEN}" "$@"; } - ghcurl "https://api.github.com/repos/${GITHUB_REPOSITORY}/issues?labels=${BRANCH}" | - jq -r '.[] | (.url + " " + .pull_request.url)' | - while read -r iss pr; do - ref=$(ghcurl "$pr" | jq -r '.head.ref') - echo "merge: $ref" - if git merge -q --no-ff origin/$ref -m "$ref"; then - echo "$iss" >> successful_merges - else - echo "$ref could not be merged. Ignoring" - git merge --abort - echo "$iss" >> failed_merges - fi - done - branch_old=$(git rev-parse origin/${BRANCH} || echo "NONE") - branch_new=$(git rev-parse new-${BRANCH}) - echo "${BRANCH}_old: $branch_old" - echo "${BRANCH}_new: $branch_new" - if [[ $branch_old != $branch_new ]]; then - echo "::set-output name=dopush,::true" - else - echo "${BRANCH} unchanged. Nothing to push" - fi - - name: push branch - id: push_branch - if: steps.build_branch.outputs.dopush - # push may fail if multiple invocations of the auto stage workflow run in parallel. - # Github may work on preventing parallel runs of workflows in some future - # (see https://github.community/t5/GitHub-Actions/Prevent-parallel-workflows/td-p/32889) - # however until then we have to do it this way to not mark PRs as failed or something - continue-on-error: true - run: | - : ${GITHUB_USER:=$GITHUB_ACTOR} - echo "::debug::Github user ${GITHUB_USER}" - remote_repo="https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" - git push "$remote_repo" HEAD:${BRANCH} -f && - echo "::set-output name=success,::true" - - name: label PRs - if: steps.push_branch.outputs.success - run: | - ghcurl() { curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "$@"; } - cat failed_merges | while read iss; do - ghcurl -d '{"labels":["'$BRANCH' Failed"]}' -X POST "$iss/labels" - ghcurl -X DELETE "$iss/labels/$BRANCH%20Successful" - echo "label $iss as failed..." - done - echo -- - cat successful_merges | while read iss; do - echo "label $iss as successful..." - ghcurl -d '{"labels":["'$BRANCH' Successful"]}' -X POST "$iss/labels" - ghcurl -X DELETE "$iss/labels/$BRANCH%20Failed" - done + autodev: + uses: Staffbase/gha-workflows/.github/workflows/template_autodev.yml@v1.14.0 + with: + base: master + comments: true + secrets: + token: ${{ secrets.DEV_PUSH_TOKEN }} \ No newline at end of file From b243f23f23840f0975b1c27382ee6a45bcc44a6d Mon Sep 17 00:00:00 2001 From: Marcel Seidel <47413751+m-seidel@users.noreply.github.com> Date: Tue, 2 May 2023 09:47:32 +0200 Subject: [PATCH 2/2] chore: changed base branch to main --- .github/workflows/autodev.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/autodev.yaml b/.github/workflows/autodev.yaml index e5a85a1..4af2dd9 100644 --- a/.github/workflows/autodev.yaml +++ b/.github/workflows/autodev.yaml @@ -10,7 +10,7 @@ jobs: autodev: uses: Staffbase/gha-workflows/.github/workflows/template_autodev.yml@v1.14.0 with: - base: master + base: main comments: true secrets: token: ${{ secrets.DEV_PUSH_TOKEN }} \ No newline at end of file