forked from async-profiler/async-profiler
-
Notifications
You must be signed in to change notification settings - Fork 2
155 lines (152 loc) · 5.63 KB
/
test-and-publish-nightly.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
name: Test and Publish Nightly Builds
on:
push:
branches:
- master
pull_request:
branches:
- master
env:
JAVA_DISTRIBUTION: 'corretto'
JAVA_VERSION: '11'
jobs:
build-jars:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Build jars
run: make jar
- name: Upload async-profiler.jar
uses: actions/upload-artifact@v4
with:
name: async-profiler.jar
path: build/jar/async-profiler.jar
- name: Upload jfr-converter.jar
uses: actions/upload-artifact@v4
with:
name: jfr-converter.jar
path: build/jar/jfr-converter.jar
build-binaries-and-test:
strategy:
matrix:
include:
- runson: macos-14 # mac arm
- runson: codebuild-async-profiler-nightly-builds-x86-${{ github.run_id }}-${{ github.run_attempt }}
- runson: codebuild-async-profiler-nightly-builds-${{ github.run_id }}-${{ github.run_attempt }}
runs-on: ${{ matrix.runson }}
steps:
- name: Setup Java for macOS x64
uses: actions/setup-java@v4
if: ${{ matrix.runson == 'macos-14' }}
with:
distribution: ${{ env.JAVA_DISTRIBUTION }}
java-version: ${{ env.JAVA_VERSION }}
architecture: x64 # set up for x64, as the default arm one will override this later
- name: Setup Java for default architecture
uses: actions/setup-java@v4
with:
distribution: ${{ env.JAVA_DISTRIBUTION }}
java-version: ${{ env.JAVA_VERSION }}
# architecture: not specifying this defaults to architecture of the runner
- name: Checkout sources
uses: actions/checkout@v4
- name: Build and test
id: build
run: |
# there is no git on the codebuild runner, so it's easier to get it from github.sha
HASH=$(echo ${{ github.sha }} | cut -c-7)
case "${{ matrix.runson }}" in
macos*) make COMMIT_TAG=$HASH FAT_BINARY=true release test -j
;;
*) make COMMIT_TAG=$HASH CC=/usr/local/musl/bin/musl-gcc release test -j
;;
esac
echo "archive=$(basename $(find . -type f -iname "async-profiler-*" ))" >> $GITHUB_OUTPUT
- name: Upload test logs for default architecture
uses: actions/upload-artifact@v4
if: always() # we always want to upload test logs, especially when tests fail
with:
name: test-logs-${{ matrix.runson }}
path: |
build/test/logs/
hs_err*.log
- name: Test macOS x64
if: ${{ matrix.runson == 'macos-14' }}
run: JAVA_HOME=$JAVA_HOME_${{ env.JAVA_VERSION }}_X64 make test
- name: Upload async-profiler binaries to workflow
uses: actions/upload-artifact@v4
with:
name: ${{ steps.build.outputs.archive }}
path: ${{ steps.build.outputs.archive }}
- name: Upload test logs for macOS x64
uses: actions/upload-artifact@v4
if: matrix.runson == 'macos-14' && always()
with:
name: test-logs-macos-14-x64
path: |
build/test/logs/
hs_err*.log
publish-only-on-push:
if: github.event_name == 'push'
runs-on: ubuntu-latest
needs: [build-jars, build-binaries-and-test]
steps:
- name: Download async-profiler binaries and jars
uses: actions/download-artifact@v4
with:
pattern: '*.*' # download everything except test logs
merge-multiple: 'true'
- name: Delete previous release and publish new release
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const fs = require('fs').promises;
const commonOptions = {
owner: "async-profiler",
repo: "async-profiler",
};
let previousRelease = undefined;
try {
previousRelease = await github.rest.repos.getReleaseByTag({
...commonOptions,
tag: "nightly",
});
} catch (e) {
console.log("No previous nightly release");
// ignore, there was no previous nightly release
}
if (previousRelease !== undefined) {
// delete previous release and nightly tag
await github.rest.repos.deleteRelease({
...commonOptions,
release_id: previousRelease.data.id,
});
await github.rest.git.deleteRef({...commonOptions, ref: "tags/nightly"});
}
// create draft release
const newReleaseId = (await github.rest.repos.createRelease({
...commonOptions,
tag_name: "nightly",
target_commitish: "${{ github.sha }}",
name: "Nightly builds",
body: "Async-profiler binaries published automatically from the latest sources in `master` upon a successful build.",
prerelease: true,
draft: true,
})).data.id;
// upload binaries and jars to draft release
for (const archiveName of await fs.readdir(process.cwd())) {
await github.rest.repos.uploadReleaseAsset({
...commonOptions,
release_id: newReleaseId,
name: archiveName,
data: await fs.readFile(archiveName),
});
}
// publish release
await github.rest.repos.updateRelease({
...commonOptions,
release_id: newReleaseId,
draft: false,
});