forked from nanocurrency/nano-node
-
Notifications
You must be signed in to change notification settings - Fork 0
71 lines (65 loc) · 3.47 KB
/
prepare_release.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
name: Prepare Release
on:
workflow_dispatch:
jobs:
promote_reference:
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/[email protected]
with:
ref: ${{ github.ref }}
fetch-depth: 0
- name: Confifigure git user and email
run: |
git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
- name: Fetch Major and Minor versions
id: fetch-versions
run: |
current_version_major=$(grep "CPACK_PACKAGE_VERSION_MAJOR" CMakeLists.txt | grep -o "[0-9]\+")
current_version_minor=$(grep "CPACK_PACKAGE_VERSION_MINOR" CMakeLists.txt | grep -o "[0-9]\+")
echo "Current major version: $current_version_major"
echo "Current minor version: $current_version_minor"
echo "major=${current_version_major}" >> $GITHUB_OUTPUT
echo "minor=${current_version_minor}" >> $GITHUB_OUTPUT
- name: Check for existence of release branch
id: check-release-branch
run: |
release_branch_name="releases/v${{ steps.fetch-versions.outputs.major }}"
if git show-ref --verify --quiet refs/remotes/origin/$release_branch_name; then
echo "Release branch $release_branch_name already exists. Aborting..."
exit 1
else
echo "Release branch does not exist. Continuing with preparation..."
echo "release-branch-name=${release_branch_name}" >> $GITHUB_OUTPUT
fi
- name: Get default branch
id: get-default-branch
run: |
DEFAULT_BRANCH=$(curl --silent --show-error --header "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}" | jq .default_branch --raw-output)
echo "Default branch is $DEFAULT_BRANCH"
echo "default-branch=${DEFAULT_BRANCH}" >> $GITHUB_OUTPUT
- name: Increment Major version on default branch
run: |
git checkout ${{ steps.get-default-branch.outputs.default-branch }}
NEW_BRANCH="prs/temp-increment-major-$(date +%Y%m%d%H%M%S)"
git checkout -b $NEW_BRANCH
new_version_major=$((${{ steps.fetch-versions.outputs.major }} + 1))
sed -i.bak "s/set(CPACK_PACKAGE_VERSION_MAJOR \"[0-9]*\")/set(CPACK_PACKAGE_VERSION_MAJOR \"$new_version_major\")/g" CMakeLists.txt
rm CMakeLists.txt.bak
git add CMakeLists.txt
git commit -m "Update CPACK_PACKAGE_VERSION_MAJOR to $new_version_major"
git push origin $NEW_BRANCH
# Create pull request
export GH_TOKEN=${{ secrets.GITHUB_TOKEN }}
gh pr create --base ${{ steps.get-default-branch.outputs.default-branch }} --head $NEW_BRANCH --title "Update CPACK_PACKAGE_VERSION_MAJOR to $new_version_major" --body "Auto-generated PR to update CPACK_PACKAGE_VERSION_MAJOR"
git reset --hard HEAD~1
- name: Prepare release branch and set pre-release to 0
run: |
git checkout -b ${{ steps.check-release-branch.outputs.release-branch-name }}
sed -i.bak "s/set(CPACK_PACKAGE_VERSION_PRE_RELEASE \"[0-9]*\")/set(CPACK_PACKAGE_VERSION_PRE_RELEASE \"0\")/g" CMakeLists.txt
rm CMakeLists.txt.bak
git add CMakeLists.txt
git commit -m "Update CPACK_PACKAGE_VERSION_PRE_RELEASE to 0"
git push origin ${{ steps.check-release-branch.outputs.release-branch-name }}