Skip to content

Commit ffdfdfa

Browse files
feat(ci): upgrade to reusable release actions
1 parent e7845fa commit ffdfdfa

File tree

4 files changed

+25
-211
lines changed

4 files changed

+25
-211
lines changed

.github/workflows/release-deploy.yml

Lines changed: 0 additions & 90 deletions
This file was deleted.

.github/workflows/release-prepare.yml

Lines changed: 6 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -4,111 +4,17 @@ on:
44
push:
55
branches: [ develop ]
66

7-
env:
8-
GITHUB_USERNAME: codeforphilly-bot
9-
GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
10-
RELEASE_BRANCH: releases/v3
7+
permissions:
8+
contents: read
9+
pull-requests: write
1110

1211
jobs:
1312
release-prepare:
1413

1514
runs-on: ubuntu-latest
1615
steps:
1716

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

.github/workflows/release-publish.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: 'Release: Publish PR'
2+
3+
on:
4+
pull_request:
5+
branches: [ releases/v3 ]
6+
types: [ closed ]
7+
8+
jobs:
9+
release-publish:
10+
11+
runs-on: ubuntu-latest
12+
steps:
13+
14+
- uses: JarvusInnovations/infra-components@channels/github-actions/release-publish/latest
15+
with:
16+
github-token: ${{ secrets.BOT_GITHUB_TOKEN }}

.github/workflows/release-validate.yml

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,12 @@ on:
55
branches: [ 'releases/v*' ]
66
types: [ opened, edited, reopened, synchronize ]
77

8-
env:
9-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
10-
118
jobs:
129
release-validate:
1310

1411
runs-on: ubuntu-latest
1512
steps:
1613

17-
- name: Validate PR title
18-
run: |
19-
PR_TITLE=$(jq -r ".pull_request.title" $GITHUB_EVENT_PATH)
20-
21-
# check title format and extract tag
22-
if [[ "${PR_TITLE}" =~ ^Release:\ v[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$ ]]; then
23-
RELEASE_TAG="${PR_TITLE:9}"
24-
echo "RELEASE_TAG=${RELEASE_TAG}" >> $GITHUB_ENV
25-
else
26-
echo 'PR title must match format "Release: vX.Y.Z(-rc.#)?"'
27-
exit 1
28-
fi
29-
30-
# check that tag doesn't exist
31-
if git ls-remote --exit-code "https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}" "refs/tags/${RELEASE_TAG}"; then
32-
echo "The PR title's version exists already"
33-
exit 1
34-
fi
14+
- uses: JarvusInnovations/infra-components@channels/github-actions/release-validate/latest
15+
with:
16+
github-token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)