Skip to content

Commit 395770c

Browse files
authored
Merge pull request #43 from Staffbase/NFS-000_remove_set-output
chore: adding new autodev action
2 parents 6f97ff6 + b243f23 commit 395770c

File tree

1 file changed

+7
-76
lines changed

1 file changed

+7
-76
lines changed

.github/workflows/autodev.yaml

Lines changed: 7 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
name: Autodev
2-
32
on:
43
push:
54
branches-ignore:
@@ -8,78 +7,10 @@ on:
87
types: [labeled, unlabeled, closed]
98

109
jobs:
11-
dev:
12-
env:
13-
GITHUB_TOKEN: ${{ secrets.DEV_PUSH_TOKEN }}
14-
GITHUB_USER: ${{ secrets.DEV_PUSH_USER }}
15-
BRANCH: dev
16-
runs-on: ubuntu-20.04
17-
steps:
18-
- name: do-checkout
19-
uses: actions/checkout@v1
20-
with:
21-
ref: main
22-
- name: build branch
23-
id: build_branch
24-
run: |
25-
touch successful_merges failed_merges
26-
git checkout -B new-${BRANCH}
27-
git config --global user.email "[email protected]"
28-
git config --global user.name "Merge Bot"
29-
# with both dates set to the last main commit, we get reproducible builds: Whenever the CI Job would produce
30-
# the exact same result as the existing branch (as in, nothing on the staged branches or main changed)
31-
# the new branch ref will have the same commit sha than the old one.
32-
export GIT_COMMITTER_DATE=$(git show -s --format='%ci' HEAD)
33-
export GIT_AUTHOR_DATE=$GIT_COMMITTER_DATE
34-
ghcurl() { curl -s -H "Authorization: token ${GITHUB_TOKEN}" "$@"; }
35-
ghcurl "https://api.github.com/repos/${GITHUB_REPOSITORY}/issues?labels=${BRANCH}" |
36-
jq -r '.[] | (.url + " " + .pull_request.url)' |
37-
while read -r iss pr; do
38-
ref=$(ghcurl "$pr" | jq -r '.head.ref')
39-
echo "merge: $ref"
40-
if git merge -q --no-ff origin/$ref -m "$ref"; then
41-
echo "$iss" >> successful_merges
42-
else
43-
echo "$ref could not be merged. Ignoring"
44-
git merge --abort
45-
echo "$iss" >> failed_merges
46-
fi
47-
done
48-
branch_old=$(git rev-parse origin/${BRANCH} || echo "NONE")
49-
branch_new=$(git rev-parse new-${BRANCH})
50-
echo "${BRANCH}_old: $branch_old"
51-
echo "${BRANCH}_new: $branch_new"
52-
if [[ $branch_old != $branch_new ]]; then
53-
echo "::set-output name=dopush,::true"
54-
else
55-
echo "${BRANCH} unchanged. Nothing to push"
56-
fi
57-
- name: push branch
58-
id: push_branch
59-
if: steps.build_branch.outputs.dopush
60-
# push may fail if multiple invocations of the auto stage workflow run in parallel.
61-
# Github may work on preventing parallel runs of workflows in some future
62-
# (see https://github.community/t5/GitHub-Actions/Prevent-parallel-workflows/td-p/32889)
63-
# however until then we have to do it this way to not mark PRs as failed or something
64-
continue-on-error: true
65-
run: |
66-
: ${GITHUB_USER:=$GITHUB_ACTOR}
67-
echo "::debug::Github user ${GITHUB_USER}"
68-
remote_repo="https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
69-
git push "$remote_repo" HEAD:${BRANCH} -f &&
70-
echo "::set-output name=success,::true"
71-
- name: label PRs
72-
if: steps.push_branch.outputs.success
73-
run: |
74-
ghcurl() { curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "$@"; }
75-
cat failed_merges | while read iss; do
76-
ghcurl -d '{"labels":["'$BRANCH' Failed"]}' -X POST "$iss/labels"
77-
ghcurl -X DELETE "$iss/labels/$BRANCH%20Successful"
78-
echo "label $iss as failed..."
79-
done
80-
echo --
81-
cat successful_merges | while read iss; do
82-
echo "label $iss as successful..."
83-
ghcurl -d '{"labels":["'$BRANCH' Successful"]}' -X POST "$iss/labels"
84-
ghcurl -X DELETE "$iss/labels/$BRANCH%20Failed"
85-
done
10+
autodev:
11+
uses: Staffbase/gha-workflows/.github/workflows/[email protected]
12+
with:
13+
base: main
14+
comments: true
15+
secrets:
16+
token: ${{ secrets.DEV_PUSH_TOKEN }}

0 commit comments

Comments
 (0)