-
Notifications
You must be signed in to change notification settings - Fork 3
162 lines (149 loc) · 6.56 KB
/
release.yml
File metadata and controls
162 lines (149 loc) · 6.56 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: Create release
# example: gh workflow run release.yml -f tag_name=v1.1.4
on:
workflow_dispatch:
inputs:
tag_name:
type: string
required: true
description: Tag name with v prefix
splunk_versions:
type: string
required: true
description: Splunk compatible versions
default: 9.4,9.3,9.2,9.1,9.0,8.2,8.1,8.0,7.3,7.2,7.1,7.0
publish-to-splunkbase:
type: boolean
description: Publish to Splunkbase
default: true
jobs:
create-release:
name: Create release
runs-on: ubuntu-latest
permissions:
contents: write
env:
PACKAGE_NAME: "crowdsec-splunk-app.tar.gz"
steps:
- name: Check naming convention
run: |
VERIF=$(echo ${{ github.event.inputs.tag_name }} | grep -E "^v([0-9]{1,}\.)([0-9]{1,}\.)([0-9]{1,})(-(alpha|beta)\.[0-9]{1,})?$")
if [ ! ${VERIF} ]
then
echo "Tag name '${{ github.event.inputs.tag_name }}' does not comply with naming convention vX.Y.Z"
exit 1
fi
- name: Set version number without v
run: |
echo "VERSION_NUMBER=$(echo ${{ github.event.inputs.tag_name }} | sed 's/v//g' )" >> $GITHUB_ENV
- name: Clone sources
uses: actions/checkout@v4
- name: Check version ${{ env.VERSION_NUMBER }} consistency in files
# CHANGELOG.md, app.manifest, default/app.conf, appserver/static/javascript/setup_page.js
run: |
# Check top ## [VERSION_NUMBER](GITHUB_URL/releases/tag/vVERSION_NUMBER) - yyyy-mm-dd in CHANGELOG.md
# Example: ## [0.0.2](https://github.com/crowdsecurity/crowdsec-splunk-app/releases/tag/v0.0.2) - 2024-02-07
CURRENT_DATE=$(date +'%Y-%m-%d')
echo $CURRENT_DATE
CHANGELOG_VERSION=$(grep -o -E "## \[(.*)\].* - $CURRENT_DATE" CHANGELOG.md | head -1 | sed 's/ //g')
echo $CHANGELOG_VERSION
if [[ $CHANGELOG_VERSION == "##[${{ env.VERSION_NUMBER }}]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/tag/v${{ env.VERSION_NUMBER }})-$CURRENT_DATE" ]]
then
echo "CHANGELOG VERSION OK"
else
echo "CHANGELOG VERSION KO"
echo $CHANGELOG_VERSION
exit 1
fi
# Check top [_Compare with previous release_](GITHUB_URL/compare/vLAST_TAG...vVERSION_NUMBER) in CHANGELOG.md
# Example: [_Compare with previous release_](https://github.com/crowdsecurity/crowdsec-splunk-app/compare/v0.0.1...v0.0.2)
COMPARISON=$(grep -oP "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/compare/\K(.*)$" CHANGELOG.md | head -1)
LAST_TAG=$(curl -Ls -o /dev/null -w %{url_effective} $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/latest | grep -oP "\/tag\/\K(.*)$")
if [[ $COMPARISON == "$LAST_TAG...v${{ env.VERSION_NUMBER }})" ]]
then
echo "VERSION COMPARISON OK"
else
echo "VERSION COMPARISON KO"
echo $COMPARISON
echo "$LAST_TAG...v${{ env.VERSION_NUMBER }})"
exit 1
fi
# Check in app.manifest
# Example: "version": "0.0.2"
MANIFEST_VERSION=$(grep -oP '"version": "\K(.*)(?=")' app.manifest | head -1)
if [[ $MANIFEST_VERSION == "${{ env.VERSION_NUMBER }}" ]]
then
echo "MANIFEST VERSION OK"
else
echo "MANIFEST VERSION KO"
echo $MANIFEST_VERSION
exit 1
fi
# Check in default/app.conf
# Example: version=1.0.6
APP_CONF_VERSION=$(sed -n 's/^version=\(.*\)/\1/p' default/app.conf | tr -d '\r' )
if [[ $APP_CONF_VERSION == "${{ env.VERSION_NUMBER }}" ]]
then
echo "app.conf VERSION OK"
else
echo "app.conf VERSION KO"
echo $APP_CONF_VERSION
exit 1
fi
# Check in appserver/static/javascript/setup_page.js
# Example: v=v1.0.6
JS_VERSION=$(sed -n 's/urlArgs\: "v=v\(.*\)"/\1/p' appserver/static/javascript/setup_page.js | sed 's/ //g' | tr -d '\r')
if [[ $JS_VERSION == "${{ env.VERSION_NUMBER }}" ]]
then
echo "appserver/static/javascript/setup_page.js VERSION OK"
else
echo "appserver/static/javascript/setup_page.js VERSION KO"
echo $JS_VERSION
exit 1
fi
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.9.16'
- name: Install splunk toolkit
run: |
curl https://download.splunk.com/misc/packaging-toolkit/splunk-packaging-toolkit-1.0.1.tar.gz -o /tmp/spl.tar.gz
pip install /tmp/spl.tar.gz
- name: Make package
run: |
# @see https://dev.splunk.com/enterprise/reference/packagingtoolkit/packagingtoolkitcli/
slim package .
cp crowdsec-splunk-app-*.tar.gz ./${{ env.PACKAGE_NAME }}
- name: Create Tag ${{ github.event.inputs.tag_name }}
uses: actions/github-script@v7
with:
github-token: ${{ github.token }}
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: "refs/tags/${{ github.event.inputs.tag_name }}",
sha: context.sha
})
- name: Prepare release notes
run: |
# Retrieve release body and remove ---
VERSION_RELEASE_NOTES=$(awk -v ver="[${{ env.VERSION_NUMBER }}]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/tag/v${{ env.VERSION_NUMBER }})" '/^## / { if (p) { exit }; if ($2 == ver) { p=1; next} } p && NF' CHANGELOG.md | sed ':a;N;$!ba;s/\n---/ /g')
echo "$VERSION_RELEASE_NOTES" >> CHANGELOG.txt
- name: Create release ${{ env.VERSION_NUMBER }}
uses: softprops/action-gh-release@v2
with:
files: ${{ env.PACKAGE_NAME }}
body_path: CHANGELOG.txt
name: ${{ env.VERSION_NUMBER }}
tag_name: ${{ github.event.inputs.tag_name }}
- name: Upload to SplunkBase
if: github.event.inputs.publish-to-splunkbase == 'true'
run: |
curl -u "${{ secrets.SPLUNKBASE_USERNAME }}:${{ secrets.SPLUNKBASE_PASSWORD }}" --request POST \
"https://splunkbase.splunk.com/api/v1/app/6800/new_release/" \
-F "files[]=@${{ env.PACKAGE_NAME }}" \
-F "filename=${{ env.PACKAGE_NAME }}" \
-F "cim_versions=5.x" \
-F "splunk_versions=${{ github.event.inputs.splunk_versions }}" \
-F "visibility=true"