-
Notifications
You must be signed in to change notification settings - Fork 14
139 lines (122 loc) · 4.25 KB
/
release_github.yml
File metadata and controls
139 lines (122 loc) · 4.25 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
name: Draft GitHub Release
on:
workflow_dispatch:
inputs:
version_level:
description: "Semantic version level increase."
required: true
type: choice
options:
- patch
- minor
- major
permissions:
contents: write
pull-requests: write
jobs:
draft_release:
runs-on: "ubuntu-latest"
defaults:
run:
shell: bash -l {0}
strategy:
fail-fast: true
steps:
- name: Display selection
run: |
echo "Branch selected: '${{ github.ref_name }}'"
echo "Release level selected: '${{ github.event.inputs.version_level }}'"
- name: Ensure that permitted release branch was selected
if: ${{ github.ref_name == 'main' || github.ref_name == 'dev' }}
run: |
echo "Branch selected: '${{ github.ref_name }}'"
echo "Releasing from main or dev branch is not permitted, please select a different release branch."
exit 1
- name: Check GitHub Token Validity
run: |
echo "-- Validating GitHub Token"
status_code=$(curl -o /dev/null -s -w "%{http_code}" -H "Authorization: token ${{ secrets.GH_RELEASE }}" https://api.github.com/user)
if [ "$status_code" -ne 200 ]; then
echo "Error: GitHub token is invalid or expired. Please update your token in secrets."
echo "Instructions can be found at: https://github.com/DeepRank/deeprank2/blob/main/README.dev.md#updating-the-token"
exit 1
else
echo "GitHub token is valid."
fi
- name: Checkout repository
uses: actions/checkout@v4
with:
# token with admin priviliges to override brach protection on main and dev
token: ${{ secrets.GH_RELEASE }}
ref: main
fetch-depth: 0
- name: Configure git
run: |
git config user.email "actions@github.com"
git config user.name "GitHub Actions"
git pull
- name: Merge changes into main
run: |
git switch main
git merge origin/${{ github.ref_name }} --no-ff --no-commit
git commit --no-edit
- name: Bump version
id: bump
run: |
echo "-- install bump-my-version"
python3 -m pip install bump-my-version
echo "-- bump the version"
bump-my-version bump ${{ github.event.inputs.version_level }} --commit --tag
echo "-- push bumped version"
echo "RELEASE_TAG=$(git describe --tags --abbrev=0)" >> $GITHUB_OUTPUT
git push --tags -f
git push
- name: Create GitHub Release
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create ${{ steps.bump.outputs.RELEASE_TAG }} \
--title="Release ${{ steps.bump.outputs.RELEASE_TAG }}" \
--generate-notes \
--draft
tidy_workspace:
# only run if action above succeeds
needs: draft_release
runs-on: "ubuntu-latest"
defaults:
run:
shell: bash -l {0}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# token with admin priviliges to override brach protection on main and dev
token: ${{ secrets.GH_RELEASE }}
fetch-depth: 0
- name: Configure git
run: |
git config user.email "actions@github.com"
git config user.name "GitHub Actions"
git pull
- name: Close PR
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "-- searching for associated PR"
pr_number=$(gh pr list --head ${{ github.ref_name }} --json number --jq '.[0].number')
if [ -n "$pr_number" ]; then
echo "-- closing PR #$pr_number"
gh pr close $pr_number
else
echo "-- no open pull request found for branch $branch_name"
fi
- name: Merge updates into dev
run: |
git switch dev
git merge origin/main
git push
- name: Delete release branch other than main or dev
run: |
echo "-- deleting branch '${{ github.ref_name }}'"
git push origin -d ${{ github.ref_name }}