-
Notifications
You must be signed in to change notification settings - Fork 0
101 lines (91 loc) · 3.81 KB
/
release-pr.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
name: release-pr
on:
workflow_call:
inputs:
git_pr_release_branch_staging:
type: string
description: 'The branch name that the feature branches are merged into and is going to be merged into the "production" branch.'
default: "release"
required: false
git_pr_release_branch_production:
type: string
description: "The branch name that is deployed in production environment."
default: "main"
required: false
git_pr_release_template:
type: string
description: "The template file path (relative to the workidir top) for pull requests created. Its first line is used for the PR title, the rest for the body. This is an ERB template."
default: ".git-pr-release-template"
required: false
override:
type: boolean
description: "If this value is true, this action overrides an existing branch and a pull request."
default: false
required: false
secrets:
token:
required: true
slack_webhook:
required: true
jobs:
job:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.token }}
GIT_PR_RELEASE_TOKEN: ${{ secrets.token }}
GIT_PR_RELEASE_BRANCH_STAGING: ${{ inputs.git_pr_release_branch_staging }}
GIT_PR_RELEASE_BRANCH_PRODUCTION: ${{ inputs.git_pr_release_branch_production }}
GIT_PR_RELEASE_TEMPLATE: ${{ inputs.git_pr_release_template }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0 # Need to fetch merge history
ref: ${{ github.event.inputs.branch_name }} # checkout branch
- name: Check if release target exists by comparing the production branch and the default branch
run: |
git log --merges origin/$GIT_PR_RELEASE_BRANCH_PRODUCTION..origin/$(git branch --show-current) --pretty=format:%h > commits.txt
test -s commits.txt # if file is not empty, it goes to the next step
- name: Check if release branch exists
if: ${{ !inputs.override }}
run: |
! (git branch -a --format="%(refname:short)" | grep -cx "origin/$GIT_PR_RELEASE_BRANCH_STAGING")
- name: Create new Branch
run: |
git switch -c $GIT_PR_RELEASE_BRANCH_STAGING
git push origin $GIT_PR_RELEASE_BRANCH_STAGING
- name: Determine which Ruby version to use
id: ruby-version-check
run: |
if [ -e ".ruby-version" ]; then
echo "version=.ruby-version" >> $GITHUB_OUTPUT
else
echo "version=3.1.2" >> $GITHUB_OUTPUT
fi
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ steps.ruby-version-check.outputs.version }}
bundler-cache: true
- name: Create a release pull request
run: |
gem install -N git-pr-release
git-pr-release
- name: Fetch created pull request info
id: fetch
run: |
gh pr view $GIT_PR_RELEASE_BRANCH_STAGING --json "body,number" -t '{{ .number }}{{ printf "\n" }}{{ .body }}' > pr.txt
users=$(grep -o -E "@[a-zA-Z0-9]([a-zA-Z0-9]?|[\-]?([a-zA-Z0-9])){0,38}" pr.txt | sort -u | xargs echo)
number=$(head -n 1 pr.txt)
echo "users=${users}" >> $GITHUB_OUTPUT
echo "number=${number}" >> $GITHUB_OUTPUT
- name: Notify of Slack
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.slack_webhook }}
SLACK_COLOR: "#1DD0B0"
SLACK_TITLE: "${{ github.repository }} has changes to be released!"
SLACK_MESSAGE: "Check https://github.com/${{ github.repository }}/pull/${{ steps.fetch.outputs.number }} ${{ steps.fetch.outputs.users }} "
SLACK_FOOTER: ""
SLACK_LINK_NAMES: true
MSG_MINIMAL: true