forked from DefectDojo/django-DefectDojo
-
Notifications
You must be signed in to change notification settings - Fork 0
83 lines (80 loc) · 3.57 KB
/
new-release-pr.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
name: "Release: 1. create branch + PR"
env:
GIT_USERNAME: "DefectDojo release bot"
GIT_EMAIL: "[email protected]"
on:
workflow_dispatch:
inputs:
# the actual branch that can be chosen on the UI is made irrelevant by further steps
# because someone will forget one day to change it.
from_branch:
description: "Select branch to release from (feature release: 'dev', bugfix or hotfix release: 'release/x.y.z')"
required: true
release_number:
description: "Release version (x.y.z format)"
required: true
jobs:
create_pr:
runs-on: ubuntu-latest
steps:
- name: Checkout from_branch branch
uses: actions/checkout@v2
with:
ref: ${{ github.event.inputs.from_branch }}
- name: Create release branch
if: ${{ !startsWith(github.event.inputs.from_branch, 'release/') }}
run: |
echo "NEW_BRANCH=release/${{ github.event.inputs.release_number }}" >> $GITHUB_ENV
- name: Use existing release branch
if: startsWith(github.event.inputs.from_branch, 'release/')
run: |
echo "NEW_BRANCH=${{ github.event.inputs.from_branch }}" >> $GITHUB_ENV
- name: Configure git
run: |
git config --global user.name "${{ env.GIT_USERNAME }}"
git config --global user.email "${{ env.GIT_EMAIL }}"
- name: Push branch
if: "!startsWith('${{ github.event.inputs.from_branch }}', 'release/')"
run: git push origin HEAD:${NEW_BRANCH}
- name: Checkout release branch
uses: actions/checkout@v2
with:
ref: ${{ env.NEW_BRANCH }}
- name: Update version numbers in key files
run: |
sed -ri "s/__version__ = '.*'/__version__ = '${{ github.event.inputs.release_number }}'/" dojo/__init__.py
sed -ri "s/appVersion: \".*\"/appVersion: \"${{ github.event.inputs.release_number }}\"/" helm/defectdojo/Chart.yaml
sed -ri "s/\"version\": \".*\"/\"version\": \"${{ github.event.inputs.release_number }}\"/" components/package.json
# remove the -dev suffix to make it the new final version in master
CURRENT_CHART_VERSION=$(grep -oP 'version: (\K\S*)?' helm/defectdojo/Chart.yaml)
sed -ri "s/version: \S+/version: ${CURRENT_CHART_VERSION%-*}/" helm/defectdojo/Chart.yaml
- name: Check numbers
run: |
grep version dojo/__init__.py
grep appVersion helm/defectdojo/Chart.yaml
grep version components/package.json
- name: Push version changes
uses: stefanzweifel/[email protected]
with:
commit_user_name: "${{ env.GIT_USERNAME }}"
commit_user_email: "${{ env.GIT_EMAIL }}"
commit_author: "${{ env.GIT_USERNAME }} <${{ env.GIT_EMAIL }}>"
commit_message: "Update versions in application files"
branch: ${{ env.NEW_BRANCH }}
- id: set-repo-org
run: echo ::set-output name=repoorg::${GITHUB_REPOSITORY%%/*}
- name: Create Pull Request
env:
REPO_ORG: ${{ steps.set-repo-org.outputs.repoorg }}
uses: actions/github-script@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.pulls.create({
owner: '${{ env.REPO_ORG }}',
repo: 'django-DefectDojo',
title: 'Release: Merge release into master from: ${{ env.NEW_BRANCH }}',
body: `Release triggered by \`${ process.env.GITHUB_ACTOR }\``,
head: '${{ env.NEW_BRANCH }}',
base: 'master'
})