Skip to content

Commit fe4f3ed

Browse files
committed
Split out CI-dependent build code
1 parent 7f218b4 commit fe4f3ed

File tree

3 files changed

+41
-10
lines changed

3 files changed

+41
-10
lines changed

github-action-build.sh renamed to ci-build.sh

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#!/bin/bash
22

33
#
4-
# github-action-build.sh - A script to build and/or release SciJava-based projects
5-
# automatically using GitHub Actions.
4+
# ci-build.sh - A script to build and/or release SciJava-based projects
5+
# automatically using a continuous integration
6+
# service.
67
#
8+
# Required environment variables:
9+
# BUILD_OS - the operating system running the current build (e.g. macOS)
10+
# BUILD_REPOSITORY - the repository slug (org/repo) running the current build
711

812
dir="$(dirname "$0")"
913

@@ -29,7 +33,7 @@ if [ -f pom.xml ]; then
2933
# Populate the settings.xml configuration.
3034
mkdir -p "$HOME/.m2"
3135
settingsFile="$HOME/.m2/settings.xml"
32-
customSettings=.github/settings.xml
36+
customSettings=.ci/settings.xml
3337
if [ -f "$customSettings" ]; then
3438
cp "$customSettings" "$settingsFile"
3539
else
@@ -86,23 +90,24 @@ EOL
8690
ciOrg=${ciPrefix##*/}
8791
if [ ! "$SIGNING_ASC" ] || [ ! "$GPG_KEY_NAME" ] || [ ! "$GPG_PASSPHRASE" ] || [ ! "$MAVEN_PASS" ] || [ ! "$OSSRH_PASS" ]; then
8892
echo "No deploy -- secure environment variables not available"
89-
elif [ "${GITHUB_REPOSITORY}" != "$ciOrg/$ciRepo" ]; then
90-
echo "No deploy -- repository fork: ${GITHUB_REPOSITORY} != $ciOrg/$ciRepo"
93+
elif [ "$BUILD_REPOSITORY" != "$ciOrg/$ciRepo" ]; then
94+
echo "No deploy -- repository fork: $BUILD_REPOSITORY != $ciOrg/$ciRepo"
9195
else
9296
echo "All checks passed for artifact deployment"
9397
deployOK=1
9498
fi
9599
fi
96100

97101
# Install GPG on OSX/macOS
98-
if [ ${RUNNER_OS} = 'macOS' ]; then
102+
if [ $BUILD_OS = 'macOS' ]; then
99103
HOMEBREW_NO_AUTO_UPDATE=1 brew install gnupg2
100104
fi
101105

102106
# Import the GPG signing key.
103-
keyFile=.github/signingkey.asc
107+
keyFile=.ci/signingkey.asc
104108
if [ "$deployOK" ]; then
105109
echo "== Importing GPG keypair =="
110+
mkdir -p .ci
106111
echo "$SIGNING_ASC" > "$keyFile"
107112
ls -la "$keyFile"
108113
gpg --batch --fast-import "$keyFile"
@@ -171,7 +176,7 @@ if [ -f environment.yml ]; then
171176

172177
echo
173178
echo "== Configuring environment =="
174-
condaEnv=github-scijava
179+
condaEnv=ci-scijava
175180
test -d "$condaDir/envs/$condaEnv" && condaAction=update || condaAction=create
176181
conda env "$condaAction" -n "$condaEnv" -f environment.yml &&
177182
conda activate "$condaEnv"

github-action-ci.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
#
4+
# github-action-ci.sh - A script to set up ci-related environment variables from GitHub Actions
5+
#
6+
7+
echo "BUILD_REPOSITORY=${GITHUB_REPOSITORY}"
8+
echo "BUILD_OS=${RUNNER_OS}"
9+
10+
echo "BUILD_REPOSITORY=${GITHUB_REPOSITORY}" >> $GITHUB_ENV
11+
echo "BUILD_OS=${RUNNER_OS}" >> $GITHUB_ENV

github-actionify.sh

100644100755
Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ gitactionDir=.github
1717
gitactionConfigRoot=/workflows/.gitaction.yml
1818
gitactionConfig=$gitactionDir$gitactionConfigRoot
1919
gitactionPRConfig=$gitactionDir/workflows/.gitaction-pr.yml
20+
gitactionSetupScript=$gitactionDir/setup.sh
2021
gitactionBuildScript=$gitactionDir/build.sh
2122
gitactionSettingsFile=$gitactionDir/settings.xml
2223
gitactionNotifyScript=$gitactionDir/notify.sh
@@ -118,6 +119,7 @@ process() {
118119
test -e "$gitactionPRConfig" -a ! -f "$gitactionPRConfig" && die "$gitactionPRConfig is not a regular file"
119120
test -e "$gitactionConfig" && warn "$gitactionConfig already exists"
120121
test -e "$gitactionBuildScript" && warn "$gitactionBuildScript already exists"
122+
test -e "$gitactionSetupScript" && warn "$gitactionSetupScript already exists"
121123

122124
# -- Do things --
123125

@@ -154,6 +156,8 @@ jobs:
154156
with:
155157
java-version: '8'
156158
distribution: 'zulu'
159+
- name: Set up CI environment
160+
run: ./$gitactionSetupScript
157161
- name: Build with Maven
158162
run: ./$gitactionBuildScript
159163
env:
@@ -199,16 +203,27 @@ jobs:
199203
with:
200204
java-version: '8'
201205
distribution: 'zulu'
206+
- name: Set up CI environment
207+
run: ./$gitactionSetupScript
202208
- name: Build with Maven
203209
run: ./$gitactionBuildScript
204210
EOL
205211
update "$gitactionPRConfig"
206212

213+
# Add/update the GitHub Action setup script.
214+
cat >"$tmpFile" <<EOL
215+
#!/bin/sh
216+
curl -fsLO https://raw.githubusercontent.com/scijava/scijava-scripts/master/github-action-ci.sh
217+
sh github-action-ci.sh
218+
EOL
219+
chmod +x "$tmpFile"
220+
update "$gitactionSetupScript" "GitHub Action: add executable script $gitactionSetupScript" "true"
221+
207222
# Add/update the GitHub Action build script.
208223
cat >"$tmpFile" <<EOL
209224
#!/bin/sh
210-
curl -fsLO https://raw.githubusercontent.com/scijava/scijava-scripts/master/github-action-build.sh
211-
sh github-action-build.sh
225+
curl -fsLO https://raw.githubusercontent.com/scijava/scijava-scripts/master/ci-build.sh
226+
sh ci-build.sh
212227
EOL
213228
chmod +x "$tmpFile"
214229
update "$gitactionBuildScript" "GitHub Action: add executable script $gitactionBuildScript" "true"

0 commit comments

Comments
 (0)