-
Notifications
You must be signed in to change notification settings - Fork 11
148 lines (132 loc) · 5.94 KB
/
build_and_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
137
138
139
140
141
142
143
144
145
146
147
148
name: Full CI Build (and Release)
on:
push:
pull_request:
jobs:
build-project:
runs-on: ubuntu-20.04
env:
# Static env vars
# Github runners limited to 2 cores, 7Gb RAM
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
MAX_WORKERS: 3
# Fixed ssh-agent socket so multiple steps can use the same agent
# if needs be
SSH_AUTH_SOCK: "/tmp/ssh-agent-release-it.sock"
steps:
- name: Checkout code
id: checkout_code
uses: actions/checkout@v2
with:
# Set this so it gets the annotated commit, not the commit being tagged.
# Which means we can get the release msg
# See /~https://github.com/actions/runner/issues/712
ref: ${{ github.ref }}
- name: Setup Java
id: setup_java
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '11.0.23+9'
cache: 'gradle'
# Make sure the wrapper jar has not been tampered with
- name: Validate gradle wrapper jar
id: validate_gradle_wrapper
uses: gradle/wrapper-validation-action@v1
# Set variables in github's special env file which are then automatically
# read into env vars in each subsequent step
- name: Set Environment Variables
id: set_env_var
run: |
{
# Map the GITHUB env vars to our own
echo "BUILD_DIR=${GITHUB_WORKSPACE}"
echo "BUILD_COMMIT=${GITHUB_SHA}"
echo "ACTIONS_SCRIPTS_DIR=${GITHUB_WORKSPACE}/.github/workflows/scripts"
if [[ ${GITHUB_REF} =~ ^refs/tags/ ]]; then
# strip off the 'refs/tags/' bit
tag="${GITHUB_REF#refs/tags/}"
echo "BUILD_TAG=${tag}"
fi
if [[ ${GITHUB_REF} =~ ^refs/heads/ ]]; then
# strip off the 'ref/heads/' bit
echo "BUILD_BRANCH=${GITHUB_REF#refs/heads/}"
fi
if [[ ${GITHUB_REF} =~ ^refs/pulls/ ]]; then
echo "BUILD_IS_PULL_REQUEST=true"
else
echo "BUILD_IS_PULL_REQUEST=false"
fi
if [[ ${GITHUB_REF} =~ ^refs/tags/v ]]; then
echo "BUILD_IS_RELEASE=true"
else
echo "BUILD_IS_RELEASE=false"
fi
} >> $GITHUB_ENV
# Separate step to show what is visible across steps
- name: Build Environment Info
id: build_info
run: |
"${ACTIONS_SCRIPTS_DIR}/echo_variables.sh" \
"docker version" "$(docker --version)" \
"docker-compose version" "$(docker-compose --version)" \
"git version" "$(git --version)" \
"GITHUB_WORKSPACE" "$GITHUB_WORKSPACE" \
"GITHUB_REF" "$GITHUB_REF" \
"GITHUB_SHA" "$GITHUB_SHA" \
"BUILD_DIR" "$BUILD_DIR" \
"BUILD_TAG" "$BUILD_TAG" \
"BUILD_BRANCH" "$BUILD_BRANCH" \
"BUILD_COMMIT" "$BUILD_COMMIT" \
"BUILD_IS_PULL_REQUEST" "$BUILD_IS_PULL_REQUEST" \
"BUILD_IS_RELEASE" "$BUILD_IS_RELEASE" \
"ACTIONS_SCRIPTS_DIR" "$ACTIONS_SCRIPTS_DIR" \
"PWD" "$PWD" \
"HOME" "$HOME"
- name: Run full build
id: run_build
env:
# Map the Github secrets into env vars that gradle can see
# GH is case insensitive, gradle is case sensitive
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGKEY }}
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGPASSWORD }}
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.ORG_GRADLE_PROJECT_SONATYPEPASSWORD }}
ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.ORG_GRADLE_PROJECT_SONATYPEUSERNAME }}
run: |
pushd "${BUILD_DIR}" > /dev/null
echo -e "${GREEN}Running ${BLUE}ci_build.sh${NC}"
./ci_build.sh
echo -e "${GREEN}Finished running build script${NC}"
- name: Release to GitHub
id: create_release
if: ${{ env.BUILD_IS_RELEASE == 'true' }}
env:
# Github provided secret. To set it up do:
# Use this to generate the pub/priv key pair
# ssh-keygen -t rsa -b 4096 -f <repo>_deploy_key
# Create a repo deploy key with the public key, name 'Actions Deploy Key' and with write access
# /~https://github.com/<namespace>/<repo>/settings/keys/new
# Create a repo secret with the private key, name 'SSH_DEPLOY_KEY'
# /~https://github.com/<namespace>/<repo>/settings/secrets/actions/new
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: "${ACTIONS_SCRIPTS_DIR}/create_github_release.sh"
- name: Cleanup Gradle Cache
# Remove some files from the Gradle cache, so they aren't cached by GitHub Actions.
# Restoring these files from a GitHub Actions cache might cause problems for future builds.
# See https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
run: |
rm -f ~/.gradle/caches/modules-2/modules-2.lock
rm -f ~/.gradle/caches/modules-2/gc.properties
- name: Update gh-pages
id: update_gh-pages
if: ${{ env.BUILD_IS_RELEASE == 'true' }}
env:
# Github provided secret. To set it up do:
# Use this to generate the pub/priv key pair
# ssh-keygen -t rsa -b 4096 -f <repo>_deploy_key
# Create a repo deploy key with the public key, name 'Actions Deploy Key' and with write access
# /~https://github.com/<namespace>/<repo>/settings/keys/new
# Create a repo secret with the private key, name 'SSH_DEPLOY_KEY'
# /~https://github.com/<namespace>/<repo>/settings/secrets/actions/new
SSH_DEPLOY_KEY: ${{ secrets.SSH_DEPLOY_KEY }}
run: "${ACTIONS_SCRIPTS_DIR}/update_gh_pages.sh"