|
4 | 4 | push: |
5 | 5 | branches: [ develop ] |
6 | 6 |
|
7 | | -env: |
8 | | - GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }} |
9 | | - RELEASE_BRANCH: main |
| 7 | +permissions: |
| 8 | + contents: read |
| 9 | + pull-requests: write |
10 | 10 |
|
11 | 11 | jobs: |
12 | 12 | release-prepare: |
| 13 | + |
13 | 14 | runs-on: ubuntu-latest |
14 | 15 | steps: |
15 | 16 |
|
16 | | - - uses: actions/checkout@v2 |
| 17 | + - uses: JarvusInnovations/infra-components@channels/github-actions/release-prepare/latest |
17 | 18 | with: |
18 | | - fetch-depth: 0 |
19 | | - |
20 | | - # - uses: mxschmitt/action-tmate@v3 |
21 | | - |
22 | | - - name: Create/update pull request |
23 | | - run: | |
24 | | - # get latest release tag |
25 | | - latest_release=$(git describe --tags --abbrev=0 origin/${{ env.RELEASE_BRANCH }}) |
26 | | - latest_release_bumped=$(echo $latest_release | awk -F. -v OFS=. '{$NF++;print}') |
27 | | -
|
28 | | -
|
29 | | - # create or update PR |
30 | | - pr_body="$(cat <<EOF |
31 | | - Release: ${latest_release_bumped} |
32 | | -
|
33 | | - ## Improvements |
34 | | -
|
35 | | - ## Technical |
36 | | -
|
37 | | - EOF |
38 | | - )" |
39 | | -
|
40 | | - pr_number=$(hub pr list -h develop -f '%I') |
41 | | -
|
42 | | - if [ -n "${pr_number}" ]; then |
43 | | - echo "Updating PR #${pr_number}" |
44 | | - existing_comment_id=$(hub api "/repos/${GITHUB_REPOSITORY}/issues/${pr_number}/comments" | jq '.[] | select(.user.login=="jarvus-bot") | .id') |
45 | | - else |
46 | | - echo "Opening PR" |
47 | | - hub pull-request -b "${RELEASE_BRANCH}" -h develop -F <(echo "${pr_body}") > /tmp/pr.json |
48 | | - pr_number=$(hub pr list -h develop -f '%I') |
49 | | - echo "Opened PR #${pr_number}" |
50 | | - fi |
51 | | -
|
52 | | -
|
53 | | - # build changelog |
54 | | - commits=$( |
55 | | - git log \ |
56 | | - --first-parent \ |
57 | | - --reverse \ |
58 | | - --format="%H" \ |
59 | | - "origin/${RELEASE_BRANCH}..develop" |
60 | | - ) |
61 | | -
|
62 | | - changelog=() |
63 | | -
|
64 | | - while read -r commit; do |
65 | | - subject="$(git show -s --format=%s "${commit}")" |
66 | | - line="" |
67 | | -
|
68 | | - if [[ "${subject}" =~ Merge\ pull\ request\ \#([0-9]+) ]]; then |
69 | | - line="$(hub pr show -f '%t [%i] @%au' "${BASH_REMATCH[1]}" || true)" |
70 | | - fi |
71 | | -
|
72 | | - if [ -z "${line}" ]; then |
73 | | - author="$(hub api "/repos/${GITHUB_REPOSITORY}/commits/${commit}" -H Accept:application/vnd.github.v3+json | jq -r '.author.login')" |
74 | | - if [ -n "${author}" ]; then |
75 | | - author="@${author}" |
76 | | - else |
77 | | - author="$(git show -s --format=%ae "${commit}")" |
78 | | - fi |
79 | | -
|
80 | | - line="${subject} ${author}" |
81 | | - fi |
82 | | -
|
83 | | - # move ticket number prefix into to existing square brackets at end |
84 | | - line="$(echo "${line}" | perl -pe 's/^([A-Z]+-[0-9]+):?\s*(.*?)\s*\[([^]]+)\]\s*(\S+)$/\2 [\3, \1] \4/')" |
85 | | -
|
86 | | - # move ticket number prefix into to new square brackets at end |
87 | | - line="$(echo "${line}" | perl -pe 's/^([A-Z]+-[0-9]+):?\s*(.*?)\s*(\S+)$/\2 [\1] \3/')" |
88 | | -
|
89 | | - # combine doubled square brackets at the end |
90 | | - line="$(echo "${line}" | perl -pe 's/^\s*(.*?)\s*\[([A-Z]+-[0-9]+)\]\s*\[([^]]+)\]\s*(\S+)$/\1 [\3, \2] \4/')" |
91 | | -
|
92 | | - changelog+=("- ${line}") |
93 | | - done <<< "${commits}" |
94 | | -
|
95 | | -
|
96 | | - # create or update comment |
97 | | - comment_body="$(cat <<EOF |
98 | | - ## Changelog |
99 | | -
|
100 | | - \`\`\`markdown |
101 | | - $(IFS=$'\n'; echo "${changelog[*]}") |
102 | | - \`\`\` |
103 | | - EOF |
104 | | - )" |
105 | | -
|
106 | | - if [ -n "${existing_comment_id}" ]; then |
107 | | - echo "Updating comment #${existing_comment_id}" |
108 | | - hub api "/repos/${GITHUB_REPOSITORY}/issues/comments/${existing_comment_id}" -f body="${comment_body}" |
109 | | - else |
110 | | - echo "Creating comment" |
111 | | - hub api "/repos/${GITHUB_REPOSITORY}/issues/${pr_number}/comments" -f body="${comment_body}" |
112 | | - fi |
| 19 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 20 | + release-branch: main |
0 commit comments