-
Notifications
You must be signed in to change notification settings - Fork 45
145 lines (137 loc) · 5.21 KB
/
create-dev-branch.yaml
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
141
142
143
144
145
name: "Create Development Branch"
run-name: Create a new development branch
on:
workflow_dispatch:
inputs:
bump-type:
description: "bump type"
required: true
type: choice
default: "major"
options:
- "major"
- "minor"
jobs:
create-branch:
runs-on: ubuntu-24.04
steps:
# validate branch
- name: Validate running branch
run: |
# we want to stop if this is not running on development branch
[[ "${{github.ref_name}}" =~ ^development/[0-9.]+$ ]] || exit 1
# create app token
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.ACTIONS_APP_ID }}
private-key: ${{ secrets.ACTIONS_APP_PRIVATE_KEY }}
# checkout
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
# calculate new version
- name: Calculate new version
run: |
source VERSION
if [[ "${{ inputs.bump-type }}" == "major" ]]; then
NEW_VERSION_MAJOR=$(($VERSION_MAJOR+1))
NEW_VERSION_MINOR=0
else
NEW_VERSION_MAJOR=$VERSION_MAJOR
NEW_VERSION_MINOR=$(($VERSION_MINOR+1))
fi
NEW_SHORT_VERSION="$NEW_VERSION_MAJOR.$NEW_VERSION_MINOR"
echo "NEW_SHORT_VERSION=$NEW_SHORT_VERSION" >> $GITHUB_ENV
echo "NEW_VERSION_MAJOR=$NEW_VERSION_MAJOR" >> $GITHUB_ENV
echo "NEW_VERSION_MINOR=$NEW_VERSION_MINOR" >> $GITHUB_ENV
# calculate new branch name
- name: Calculate new branch name
run: |
NEW_BRANCH_NAME="development/${{ env.NEW_SHORT_VERSION }}"
INIT_BRANCH_NAME="feature/init-dev-${{ env.NEW_SHORT_VERSION }}"
echo "NEW_BRANCH_NAME=$NEW_BRANCH_NAME" >> $GITHUB_ENV
echo "INIT_BRANCH_NAME=$INIT_BRANCH_NAME" >> $GITHUB_ENV
# create development branch
- name: Create new branch
run: |
if git ls-remote --exit-code --heads origin refs/heads/${{ env.NEW_BRANCH_NAME }}; then
echo "${{ env.NEW_BRANCH_NAME }} already exists, exiting"
exit 1
fi
git checkout -b "${{ env.NEW_BRANCH_NAME }}"
# push development branch
- name: Push new branch
run: |
git config --global user.email ${{ github.actor }}@scality.com
git config --global user.name ${{ github.actor }}
git push --set-upstream origin ${{ env.NEW_BRANCH_NAME }}
# create new branch
- name: Create an init branch
run: |
git checkout -b "${{ env.INIT_BRANCH_NAME }}"
# find mentions of new version: warn user
- name: Look for important messages
id: warn_user
run: |
link="https://github.com/${{ github.repository }}/blob/${{ env.NEW_BRANCH_NAME }}/"
{
echo 'COMMENT<<EOF'
echo "# Mentions of ${{ env.NEW_SHORT_VERSION }} in ${{ env.NEW_BRANCH_NAME }}"
git grep -rHFn "${{ env.NEW_SHORT_VERSION }}" -- ':!*.svg' | sed -E "s;(.*):([0-9]+):.*;$link\1#L\2;"
echo EOF
} >> "$GITHUB_ENV"
# bump version
- name: Bump VERSION
run: |
cat << EOF > VERSION
VERSION_MAJOR=${{ env.NEW_VERSION_MAJOR }}
VERSION_MINOR=${{ env.NEW_VERSION_MINOR }}
VERSION_PATCH=0
VERSION_SUFFIX=-dev
EOF
# edit CHANGELOG
- name: add new entry to changelog
run: |
sed -i "s/# CHANGELOG/# CHANGELOG\n\n## Release ${{ env.NEW_SHORT_VERSION }}.0 (in development)/" CHANGELOG.md
# edit cron jobs
- name: bump version in cron jobs
run: |
current=$(grep current .github/workflows/crons.yaml | sed -E "s/\s*# current=//")
old=$(grep old .github/workflows/crons.yaml | sed -E "s/\s*# old=//")
sed -i "s/$current/${{ env.NEW_SHORT_VERSION }}/g" .github/workflows/crons.yaml
sed -i "s/$old/$current/g" .github/workflows/crons.yaml
# push
- name: push to init branch
run: |
git add VERSION
git add CHANGELOG.md
git add .github/workflows/crons.yaml
git commit -m "Update version to ${{ env.NEW_SHORT_VERSION }}"
git push --set-upstream origin ${{ env.INIT_BRANCH_NAME }}
# create PR
- name: create PR
uses: actions/github-script@v7
with:
script: |
const pr = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
head: "${{ env.INIT_BRANCH_NAME }}",
base: "${{ env.NEW_BRANCH_NAME }}",
title: "Initialize ${{ env.NEW_BRANCH_NAME }} branch"
});
await github.rest.issues.createComment({
issue_number: pr.data.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `/approve`
});
await github.rest.issues.createComment({
issue_number: pr.data.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `${{ env.COMMENT }}`
});