-
Notifications
You must be signed in to change notification settings - Fork 0
125 lines (115 loc) · 4.9 KB
/
Copy pathpullrequest-close.yml
File metadata and controls
125 lines (115 loc) · 4.9 KB
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
name: PR close
on:
pull_request:
types:
- closed
defaults:
run:
shell: bash
env:
S3_DOCKER_CACHE_BUCKET: ${{ secrets.S3_DOCKER_CACHE_BUCKET }}
RUNS_ON_S3_BUCKET_CACHE: ${{ secrets.S3_DOCKER_CACHE_BUCKET }}
AWS_REGION: eu-west-1
YARN_ENABLE_HARDENED_MODE: '0'
jobs:
check-unicorn:
name: Is this a unicorn PR
if: github.event.pull_request.merged == true
runs-on: arc-shared
timeout-minutes: 10
outputs:
IS_UNICORN: ${{ steps.unicorn_affected.outputs.IS_UNICORN }}
LATEST_RELEASE: ${{ steps.get_latest_release.outputs.LATEST_RELEASE }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup yarn
uses: ./.github/actions/setup-yarn
with:
RUNS_ON_S3_BUCKET_CACHE: ${{ secrets.S3_DOCKER_CACHE_BUCKET }}
- name: Derive appropriate SHAs
uses: nrwl/nx-set-shas@v4
- run: |
echo "BASE: ${{ env.NX_BASE }}"
echo "HEAD: ${{ env.NX_HEAD }}"
- name: Check unicorn affected
id: unicorn_affected
run: |
echo "Comparing nx affected for ${{ env.NX_HEAD }} using ${{ env.NX_BASE }} as base branch"
echo IS_UNICORN=$(node scripts/ci/unicorn-utils.mjs is-unicorn "{\"head\": \"${{ env.NX_HEAD }}\", \"base\": \"${{ env.NX_BASE }}\" }") >> "$GITHUB_OUTPUT"
- name: Results
run: |
echo "Unicorn = ${{ steps.unicorn_affected.outputs.IS_UNICORN }}"
- name: Find Latest Release Branch
if: ${{ steps.unicorn_affected.outputs.IS_UNICORN == 'true' }}
id: get_latest_release
run: |
LATEST_RELEASE="$(node scripts/ci/get-last-release.mjs $(git branch -r))"
echo LATEST_RELEASE=$LATEST_RELEASE >> "$GITHUB_OUTPUT"
- run: "echo 'latest release: ${{ steps.get_latest_release.outputs.LATEST_RELEASE }}'"
- name: Create a PR
if: ${{ steps.unicorn_affected.outputs.IS_UNICORN == 'true' }}
id: create_pr
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_BRANCH: cherry-picks/${{ github.head_ref}}
TARGET_BRANCH: release/${{ steps.get_latest_release.outputs.LATEST_RELEASE }}
run: |
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
git config --global user.name "${{ github.actor }} (automated)"
echo ${{ github.event.pull_request.merge_commit_sha }}
echo ${{ github.head_ref}}
git checkout $TARGET_BRANCH
git checkout -b $PR_BRANCH
git cherry-pick -x ${{ github.event.pull_request.merge_commit_sha }}
git commit --allow-empty -am "chore: automated cherry-pick of ${{ github.event.pull_request.merge_commit_sha }}"
git push --set-upstream origin $PR_BRANCH
echo "new branch created"
PR=$(gh pr create -B $TARGET_BRANCH -H $PR_BRANCH --title "chore: automated cherry-pick of ${{ github.event.pull_request.merge_commit_sha }}" --body "Automated cherry-pick of ${{ github.event.pull_request.merge_commit_sha }}")
echo "$PR created"
echo PR=$PR >> "$GITHUB_OUTPUT"
- name: Send slack message
if: ${{ steps.unicorn_affected.outputs.IS_UNICORN == 'true' }}
uses: slackapi/slack-github-action@v2.0.0
with:
method: chat.postMessage
token: ${{ secrets.SLACK_BOT_TOKEN }}
payload: |
channel: ${{ secrets.SLACK_CHANNEL_ID }}
text: "A new PR has been created: ${{ steps.create_pr.outputs.PR }}"
cleanup:
name: Clean up feature deployment
runs-on: arc-shared
steps:
- name: Get git branch
run: |
set -euo pipefail
GIT_BRANCH="${GITHUB_HEAD_REF:-${GITHUB_REF/refs\/heads\//}}"
echo "GIT_BRANCH=$GIT_BRANCH" >> "$GITHUB_ENV"
- name: Generate deployment branch name
id: git-branch-deploy
run: |
set -euo pipefail
GIT_BRANCH_DEPLOY="$GIT_BRANCH"
if [[ ! ("$GIT_BRANCH_DEPLOY" =~ "feature/") ]]; then
# If event is pull request but branch is not prefixed with feature/
GIT_BRANCH_DEPLOY=feature/$GIT_BRANCH_DEPLOY
fi
# Avoid too long resource names
GIT_BRANCH_DEPLOY="${GIT_BRANCH_DEPLOY:0:50}"
echo "GIT_BRANCH_DEPLOY=$GIT_BRANCH_DEPLOY" >> "$GITHUB_ENV"
- name: Clean up feature
env:
SPINNAKER_WEBHOOK_TOKEN: ${{ secrets.SPINNAKER_WEBHOOK_TOKEN }}
SPINNAKER_URL: https://spinnaker-gate.shared.devland.is
run: |
set -euo pipefail
curl "$SPINNAKER_URL/webhooks/webhook/feature-cleanup" -H "content-type: application/json" --data-binary @- <<BODY
{
"token": "$SPINNAKER_WEBHOOK_TOKEN",
"parameters": {
"feature_name": "$(echo "$GIT_BRANCH_DEPLOY" | cut -d"/" -f2- | tr -cd '[:alnum:]-' | tr '[:upper:]' '[:lower:]' | cut -c1-50)"
}
}
BODY