generated from block/oss-project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
130 lines (114 loc) · 4.33 KB
/
build.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
# Runs on every commit. This is the main CI job; it runs in MacOS and Ubuntu environments which:
# * Build
# * Run tests
#
# In the Ubuntu environment only, to avoid double uploads from MacOS, it also:
# * Uploads Coverage reports to CodeCov
# * Publishes (deploys) to Block's SaaS Artifactory instance as version commit-$shortSHA-SNAPSHOT
#
# If triggered from workflow_dispatch, you may select a branch or tag to
# deploy as an internal "release" (or SNAPSHOT, depending upon the version in the POM)
# to Block's SaaS Artifactory instance by not specifying a version.
name: Build, Test & Deploy Snapshot
on:
workflow_dispatch:
inputs:
version:
description: 'Version to publish. For example "1.0.0-SNAPSHOT". If not supplied, will default to version specified in the POM. Must end in "-SNAPSHOT".'
required: false
default: "0.0.0-SNAPSHOT"
push:
branches:
- main
pull_request:
branches:
- main
jobs:
# On MacOS we only build, test, and verify
build-test-macos:
runs-on: macOS-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
# https://cashapp.github.io/hermit/usage/ci/
- name: Init Hermit
uses: cashapp/activate-hermit@v1
with:
cache: true
- name: Build, Test, and Verify
run: |
# Maven "test" lifecycle will build and test only on MacOS
mvn test
# On Ubuntu we build, test, verify, and deploy: Code Coverage, Test Vectors, and SNAPSHOT artifacts to Block Artifactory
build-test-deploy-snapshot-ubuntu:
permissions:
id-token: write
contents: read
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
# https://cashapp.github.io/hermit/usage/ci/
- name: Init Hermit
uses: cashapp/activate-hermit@v1
with:
cache: true
- name: Resolve Snapshot Version
id: resolve_version
run: |
# Version resolution: use provided
if [ -n "${{ github.event.inputs.version }}" ]; then
resolvedVersion=${{ github.event.inputs.version }}
# Otherwise, construct a version for deployment in form X.Y.Z-commit-$shortSHA-SNAPSHOT
else
longSHA=$(git rev-parse --verify HEAD)
shortSHA=$(echo "${longSHA:0:7}")
resolvedVersion="commit-$shortSHA-SNAPSHOT"
echo "Requesting deployment as version: $resolvedVersion"
fi
# Postcondition check; only allow this to proceed if we have a version ending in "-SNAPSHOT"
if [[ ! "$resolvedVersion" =~ -SNAPSHOT$ ]]; then
echo "Error: The version does not end with \"-SNAPSHOT\": $resolvedVersion"
exit 1
fi
echo "Resolved SNAPSHOT Version: $resolvedVersion"
echo "resolved_version=$resolvedVersion" >> $GITHUB_OUTPUT
- name: Build, Test, and Deploy to Block SaaS Artifactory
run: |
set -exuo pipefail
# Set newly resolved version in POM config
mvn \
versions:set \
--batch-mode \
-DnewVersion=${{ steps.resolve_version.outputs.resolved_version }}
# Maven deploy lifecycle will build, run tests, verify, sign, and deploy
mvn deploy --batch-mode --settings .maven_settings.xml -P sign-artifacts,ossrh
env:
SIGN_KEY_PASS: ${{ secrets.GPG_SECRET_PASSPHRASE }}
SIGN_KEY: ${{ secrets.GPG_SECRET_KEY }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
flags: ${{ runner.os }}
use_oidc: true
- name: Upload JUnit tests report
uses: actions/upload-artifact@v4
with:
name: tests-report-junit
path: |
**/target/surefire-reports/*.xml
# Ensure both MacOS and Ubuntu build/test jobs succeeded
confirm-successful-build-and-tests:
# Wait on both jobs to succeed
needs: [build-test-macos, build-test-deploy-snapshot-ubuntu]
runs-on: ubuntu-latest
steps:
- name: Log Success
run: |
echo "Builds for MacOS and Ubuntu succeeded."