-
Notifications
You must be signed in to change notification settings - Fork 15
131 lines (103 loc) · 4.91 KB
/
release-by-develop-hash.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
name: 🚀 Release by develop hash
on:
workflow_dispatch:
inputs:
commitHash:
description: 'Please supply a commit hash from the develop branch. You can find it in the commit history of develop branch, the first 6 characters are enough, e.g. c388cc. The release will encompass all contributions up to and including the specified head commit hash.'
required: true
type: string
dateSafeGuard:
description: 'Provide the current date in the format YYYY/MM/DD format.'
required: true
type: string
agreement:
description: 'By proceeding, the relevant commit hashes which encompass all commits below them in history will be merged into the main branch. Merging into the main branch should trigger a deployment to production. Please confirm you understand the above by typing: I understand and want to proceed!'
type: string
permissions:
contents: write
jobs:
merge-by-develop-hash:
runs-on: ubuntu-latest
env:
RELEASE_BRANCH: main
PREPARE_RELEASE_BRANCH: prepare_release
steps:
- name: Date safe-guard verification
run: |
currDate=$(date +%Y/%m/%d)
if [[ "$currDate" == "${{ inputs.dateSafeGuard }}" ]]; then
echo "✅ Date safe-guard is ok!"
else
echo "👹 Oops! The date provided ${currDate} doesn't correspond to ${{ inputs.date }}"
exit 1
fi
- name: Agreement verification
run: |
expectText="I understand and want to proceed!"
if [[ "${{ inputs.agreement }}" != "$expectText" ]]; then
echo "👹 Oops! To proceed you have to follow the agreement rule."
exit 1
fi
echo "✅ Agreement verified."
- name: Checkout main branch
uses: actions/checkout@v4
with:
ref: ${{ env.RELEASE_BRANCH }}
fetch-depth: 0
- name: Setup Git Config
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Action"
- name: Verify commit hash in Develop
id: check_commit_hash
run: |
if ! git checkout develop; then
echo "👹 Oops! The develop branch wasn't found"
exit 1
fi
if ! git branch --contains "${{ github.event.inputs.commitHash }}" | grep -q develop > /dev/null; then
echo "👹 Oops! The commit hash wasn't found in the develop branch..."
exit 1
fi
- name: Create temporary release branch
run: |
if ! git checkout -b "${{ env.PREPARE_RELEASE_BRANCH }}" "${{ github.event.inputs.commitHash }}"; then
echo "👹 Oops! Failed to create the release preparation branch with name ${{ env.PREPARE_RELEASE_BRANCH }}. If the branch exists in the repository it's conflicting with the original intent for the goal of this step. You're advised to revise why the branch exists in the repository and do something about it, e.g. delete it or rename the target release branch name here."
exit 1
fi
echo "✅ Created the release preparation branch with name ${{ env.PREPARE_RELEASE_BRANCH }} successfuly"
- name: Merge into main
run: |
if ! git checkout "${{ env.RELEASE_BRANCH }}"; then
echo "👹 Oops! The develop branch wasn't found"
exit 1
fi
if ! git merge --ff-only ${{ github.event.inputs.commitHash }}; then
echo "👹 Oops! Failed to merge into main for some reason..."
exit 1
fi
if ! git push origin "${{ env.RELEASE_BRANCH }}"; then
echo "👹 Oops! Failed to push changes to the ${{ env.RELEASE_BRANCH }} branch for some reason..."
exit 1
fi
- name: Delete temporary release branch
run: |
if ! git branch -D "${{ env.PREPARE_RELEASE_BRANCH }}"; then
echo "👹 Oops! Failed to delete the release preparation branch with name ${{ env.PREPARE_RELEASE_BRANCH }} for some reason. You are advised to look into why this happens as you may have to delete this manually, as the original intent is to use it temporarily per job run."
exit 1
fi
echo "✅ Deleted the release preparation branch with name ${{ env.PREPARE_RELEASE_BRANCH }} successfuly"
- name: Dispatch Event
env:
PAT: ${{ secrets.GITHUB_TOKEN }}
ENDPOINT: 'https://api.github.com/repos/fleek-platform/website/dispatches'
EVENT_NAME: 'Release'
run: |
if ! curl -H "Accept: application/vnd.github+json" \
-H "Authorization: token $PAT" \
--request POST \
--data "{ \"event_type\": \"$EVENT_NAME\" }" $ENDPOINT; then
echo "⚠️ Warning: Failed to dispatch $EVENT_NAME. Since this triggers the indexer listener, you should dispatch the action manually. If this issue persists, report it internally."
else
echo "✅ Dispatched event $EVENT_NAME"
fi