forked from yalesites-org/yalesites-project
-
Notifications
You must be signed in to change notification settings - Fork 0
140 lines (126 loc) · 4.29 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
name: Release pull request
on:
pull_request:
types:
- synchronize
branches:
- master
workflow_dispatch:
env:
YALESITES_BUILD_TOKEN: ${{ secrets.YALESITES_BUILD_TOKEN }}
GH_TOKEN: ${{ secrets.YALESITES_BUILD_TOKEN }}
ACCESS_TOKEN: ${{ secrets.YALESITES_BUILD_TOKEN }}
REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.number }}
RELEASE_PR_URL: ${{ github.event.pull_request._links.html.href }}
jobs:
get_next_release_version:
runs-on: ubuntu-latest
if: ${{ github.event.action != 'synchronize' }}
outputs:
release_branch: ${{ steps.get_release_number.outputs.release_branch }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: master
fetch-depth: 0
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Git setup
run: |
git config user.name github-actions
git config user.email [email protected]
- name: Get next release number
id: get_release_number
run: |
if [[ "$PR_NUMBER" ]]; then
release_branch=$(gh pr view "$PR_NUMBER" --json headRefName --jq '.[]')
else
git merge origin/develop --no-edit -X theirs
npm install --force
unset GITHUB_ACTIONS
unset GITHUB_EVENT_NAME
semantic_release=$(npx --no-install semantic-release --no-ci --dry-run 2>/dev/null)
next_version=$(echo "$semantic_release" | sed -nE 's/.*The next release version is ([0-9]+)\.([0-9]+)\.([0-9]+).*/\1\2\3/p')
if [ -z "$next_version" ]; then
exit 1
else
release_branch="v${next_version//.}"
fi
fi
echo release_branch="$release_branch" >> "$GITHUB_OUTPUT"
- name: Create release branch
if: ${{ github.event.number == '' }}
env:
RELEASE_BRANCH: ${{ steps.get_release_number.outputs.release_branch }}
run: |
echo "The release branch is: $RELEASE_BRANCH"
git checkout -b "$RELEASE_BRANCH"
git push origin "$RELEASE_BRANCH"
create_pull_request:
needs: [get_next_release_version]
if: ${{ always() }}
env:
RELEASE_BRANCH: ${{ needs.get_next_release_version.outputs.release_branch }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Create pull request
run: ./.ci/github/create_release_pull_request
release_sites:
needs: [get_next_release_version, create_pull_request]
runs-on: ubuntu-latest
env:
RELEASE_BRANCH: ${{ needs.get_next_release_version.outputs.release_branch }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ env.RELEASE_BRANCH }}
- name: Determine Terminus version
shell: bash
run: |
TERMINUS_RELEASE=$(
curl --silent \
--header 'authorization: Bearer ${{ github.token }}' \
"https://api.github.com/repos/pantheon-systems/terminus/releases/latest" \
| perl -nle'print $& while m#"tag_name": "\K[^"]*#g'
)
echo "TERMINUS_RELEASE=$TERMINUS_RELEASE" >> $GITHUB_ENV
- name: Install Terminus
shell: bash
run: |
mkdir ~/terminus && cd ~/terminus
echo "Installing Terminus v$TERMINUS_RELEASE"
curl -L https://github.com/pantheon-systems/terminus/releases/download/$TERMINUS_RELEASE/terminus.phar -o /usr/local/bin/terminus
chmod +x /usr/local/bin/terminus
- name: Authenticate to Terminus
env:
TERMINUS_TOKEN: ${{ secrets.TERMINUS_TOKEN }}
run: |
terminus auth:login --machine-token="${TERMINUS_TOKEN}"
- name: Install SSH key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_PRIVATE_KEY }}
known_hosts: unnecessary
config: ${{ secrets.SSH_CONFIG }}
- name: Cache terminus
uses: actions/cache@v4
id: terminus-cache
with:
path: |
/usr/local/bin/terminus
~/.terminus
~/.ssh
key: ${{ runner.os }}-terminus-cache-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-terminus-cache-
- name: Deploy to environments
env:
RUNNER_TEMP: ${{ runner.temp }}
run: ./.ci/github/deploy_release_sites