-
Notifications
You must be signed in to change notification settings - Fork 7
136 lines (114 loc) · 4.6 KB
/
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
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
---
name: Release Version
on:
workflow_dispatch:
pull_request_target:
types:
- closed
branches:
- 'main'
push:
branches:
- 'main'
jobs:
deploy:
runs-on: ubuntu-latest
name: Deploy release
environment: staging
# only trigger the workflow on the base repository and if the merged branch name starts with release.
if: (github.repository_owner == 'RHEcosystemAppEng' && github.event.pull_request.merged == true && startsWith(github.head_ref, 'release/') ) || (github.repository_owner == 'RHEcosystemAppEng' && github.ref_name == 'main' && contains(github.event.commits[0].message, 'release/directly'))
outputs:
project_version: ${{ steps.project.outputs.version }}
last_release_tag: ${{ steps.last-release.outputs.tag-name }}
steps:
- name: Checkout sources
uses: actions/checkout@v3
with:
ssh-key: ${{ secrets.DEPLOY_KEY }}
fetch-depth: 0
- name: Setup Java 11
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 11
cache: maven
- name: create ssh agent
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.DEPLOY_KEY }}
- name: Configure git
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
- name: get previous released annotated tag
id: last-release
run: |
echo "tag-name=$(git describe | awk -F '-' '{print $1}')" >> "$GITHUB_OUTPUT"
- name: Deploy release to GitHub
run: |
mvn release:prepare release:perform -B -ff
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Get pom version of released artifact
id: project
run: |
git checkout HEAD^ pom.xml
echo "version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> "$GITHUB_OUTPUT"
git restore pom.xml --staged --worktree
release:
runs-on: ubuntu-latest
name: Release
if: (github.repository_owner == 'RHEcosystemAppEng' && startsWith(github.head_ref, 'release/')) || (github.repository_owner == 'RHEcosystemAppEng' && github.ref_name == 'main' && contains(github.event.commits[0].message, 'release/directly'))
environment: staging
needs: deploy
steps:
- name: Create release notes for ${{ needs.deploy.outputs.project_version }} release
uses: actions/github-script@v6
id: release-notes
with:
github-token: ${{ secrets.STAGING_PAT }}
script: |
const repo_name = context.payload.repository.full_name
const response = await github.request('POST /repos/' + repo_name + '/releases' + '/generate-notes', {
tag_name: '${{ needs.deploy.outputs.project_version }}',
previous_tag_name: '${{ needs.deploy.outputs.last_release_tag }}'
})
return response.data.body
- name: Create new ${{ needs.deploy.outputs.project_version }} release
uses: actions/github-script@v6
with:
github-token: ${{ secrets.STAGING_PAT }}
script: |
const repo_name = context.payload.repository.full_name
const response = await github.request('POST /repos/' + repo_name + '/releases', {
tag_name: '${{ needs.deploy.outputs.project_version }}',
name: '${{ needs.deploy.outputs.project_version }}',
body: ${{ steps.release-notes.outputs.result }},
draft: false,
prerelease: false,
make_latest: 'true'
})
- name: Checkout sources
uses: actions/checkout@v3
with:
ssh-key: ${{ secrets.DEPLOY_KEY }}
fetch-depth: 0
- name: Configure git
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
- name: Get pom version of new snapshot artifact
id: project_snapshot
run: |
git pull
echo "version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> "$GITHUB_OUTPUT"
- name: Update readme usage section
run: >
sed -i
's/<version>.*<\/version>/<version>${{ steps.project_snapshot.outputs.version }}<\/version>/g'
README.md
- name: Push modifications
run: |
git add README.md
git commit -m "docs: updated usage section with version ${{ steps.project_snapshot.outputs.version }} [skip ci]"
git push