Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
da318ab
Create main.yml
yongleyuan Mar 14, 2021
b9b063e
Update main.yml
yongleyuan Mar 18, 2021
caf9e34
Delete .github/workflows directory
yongleyuan Mar 18, 2021
115e138
Copied and pasted codes from `travis-build.sh` to `github-action-buil…
Mar 19, 2021
1ce9413
added comments in for further changes to migrate to GitHub Actions
Mar 24, 2021
ff8de3d
modified
Mar 31, 2021
cd3dc23
changed commands to corresponding shell commands
Apr 8, 2021
e5e5475
changed github-action-build.sh file
Apr 8, 2021
5796a48
deleted unnecessary comments
Apr 29, 2021
2cf6a93
test_var
Apr 30, 2021
3b7d8a9
double curly braces for github
May 11, 2021
be34e31
added to test env vars
May 11, 2021
a037a53
deleted unexpected eof
May 11, 2021
42e989e
deleted double curly braces
May 11, 2021
e8958e3
added after to avoid unexpected eof
May 11, 2021
89b227c
commented out test section to see what caused unexpected eof error
May 11, 2021
62c670f
changed to
May 11, 2021
ee76878
added quotation marks
May 11, 2021
cd5312e
deleted errornous quotation mark
May 11, 2021
6ac10f5
commit to refresh
May 11, 2021
6e5c05b
commit to refresh
May 11, 2021
15d5946
fixed addition quotation mark
May 11, 2021
bda81c6
restore changes
May 11, 2021
cc7e39d
readded test codes
May 11, 2021
de0782b
added fi
May 11, 2021
9542198
test 15
May 11, 2021
c886918
test 16
May 11, 2021
a95e4de
test pr and repo fork
May 11, 2021
c0f07f1
test
May 17, 2021
2288a61
test
May 17, 2021
be6c634
test
May 17, 2021
5827f64
test
May 17, 2021
a059ddc
test
May 17, 2021
8f1a3ac
test
May 17, 2021
f14f48a
edit python version
May 18, 2021
dc4d9b5
test
May 18, 2021
a99d1f8
edit git_branch
May 18, 2021
edbd689
delete test codes
May 18, 2021
7d87232
delete travis comments
May 18, 2021
3f84113
add test code
May 18, 2021
a0e4229
migrate some travis codes to github-action
May 18, 2021
e6b855e
change pr method (test)
May 18, 2021
2e5531d
change pr method (test)
May 18, 2021
5cefd33
change pr method (test)
May 18, 2021
e3c4798
change pr method (test)
May 18, 2021
a2ee559
change pr method (test)
May 18, 2021
0b59367
change pr method (test)
May 18, 2021
d539a2a
change pr method (test)
May 18, 2021
753bc22
change pr method (test)
May 18, 2021
cc97a0b
change pr method (test)
May 18, 2021
66e348f
change pr method (test)
May 18, 2021
ce2a961
test
May 18, 2021
6a2be7a
test
May 18, 2021
7a1e728
test
May 18, 2021
d43dc21
test git repo
May 25, 2021
2f88d60
,finalize
Jun 7, 2021
87ecc8a
middle
Jun 15, 2021
f01a489
edit
Jun 15, 2021
caca7ef
Use org variables for encrypted key/iv
hinerm Jun 21, 2021
2540ad1
Update github action config script
hinerm Jun 21, 2021
da5437d
Fix git ci -> commit
hinerm Jun 21, 2021
64a48d4
Update github action badge
hinerm Jun 21, 2021
6a05648
Remove square brackets from grep conditions
hinerm Jun 22, 2021
265a345
Capitalize environment variable
hinerm Jun 22, 2021
bca359d
Create separate workflow for PRs
hinerm Jun 22, 2021
4e077c0
Use secrets instead of FROM_PR status
hinerm Jun 22, 2021
d0919b3
Fix path to signing key
hinerm Jun 22, 2021
565dd91
Streamline signing key/iv use
hinerm Jun 22, 2021
19c2fa6
Update decryption command
hinerm Jun 22, 2021
608fa4a
Skip checking if master for deploy
hinerm Jun 22, 2021
9e14cfb
Fix github directory
hinerm Jun 23, 2021
5c06149
Use github-style environment variable access
hinerm Jun 23, 2021
6e49d4f
Properly escape vars in config yml
hinerm Jun 24, 2021
bac542f
Remove check for signing key
hinerm Jun 24, 2021
2bbbb53
Update environment variable use
hinerm Jun 24, 2021
60e4371
Fix settings file creation
hinerm Jun 24, 2021
7f218b4
Restore fork detection
hinerm Jun 24, 2021
fe4f3ed
Split out CI-dependent build code
hinerm Jun 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
210 changes: 210 additions & 0 deletions ci-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
#!/bin/bash

#
# ci-build.sh - A script to build and/or release SciJava-based projects
# automatically using a continuous integration
# service.
#
# Required environment variables:
# BUILD_OS - the operating system running the current build (e.g. macOS)
# BUILD_REPOSITORY - the repository slug (org/repo) running the current build

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

success=0
checkSuccess() {
# Log non-zero exit code.
test $1 -eq 0 || echo "==> FAILED: EXIT CODE $1" 1>&2

# Record the first non-zero exit code.
test $success -eq 0 && success=$1
}

# Build Maven projects.
if [ -f pom.xml ]; then
echo ::group::"= Maven build ="
echo
echo "== Configuring Maven =="

# NB: Suppress "Downloading/Downloaded" messages.
# See: https://stackoverflow.com/a/35653426/1207769
export MAVEN_OPTS="$MAVEN_OPTS -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn"

# Populate the settings.xml configuration.
mkdir -p "$HOME/.m2"
settingsFile="$HOME/.m2/settings.xml"
customSettings=.ci/settings.xml
if [ -f "$customSettings" ]; then
cp "$customSettings" "$settingsFile"
else
cat >"$settingsFile" <<EOL
<settings>
<servers>
<server>
<id>scijava.releases</id>
<username>$MAVEN_USER</username>
<password>$MAVEN_PASS</password>
</server>
<server>
<id>scijava.snapshots</id>
<username>$MAVEN_USER</username>
<password>$MAVEN_PASS</password>
</server>
<server>
<id>sonatype-nexus-releases</id>
<username>scijava-ci</username>
<password>$OSSRH_PASS</password>
</server>
</servers>
EOL
cat >>"$settingsFile" <<EOL
<profiles>
<profile>
<id>gpg</id>
<activation>
<file>
<exists>$HOME/.gnupg</exists>
</file>
</activation>
<properties>
<gpg.keyname>$GPG_KEY_NAME</gpg.keyname>
<gpg.passphrase>$GPG_PASSPHRASE</gpg.passphrase>
</properties>
</profile>
</profiles>
</settings>
EOL
fi

# Determine whether deploying will be possible.
deployOK=
ciURL=$(mvn -q -Denforcer.skip=true -Dexec.executable=echo -Dexec.args='${project.ciManagement.url}' --non-recursive validate exec:exec 2>&1)

if [ $? -ne 0 ]; then
echo "No deploy -- could not extract ciManagement URL"
echo "Output of failed attempt follows:"
echo "$ciURL"
else
ciRepo=${ciURL##*/}
ciPrefix=${ciURL%/*}
ciOrg=${ciPrefix##*/}
if [ ! "$SIGNING_ASC" ] || [ ! "$GPG_KEY_NAME" ] || [ ! "$GPG_PASSPHRASE" ] || [ ! "$MAVEN_PASS" ] || [ ! "$OSSRH_PASS" ]; then
echo "No deploy -- secure environment variables not available"
elif [ "$BUILD_REPOSITORY" != "$ciOrg/$ciRepo" ]; then
echo "No deploy -- repository fork: $BUILD_REPOSITORY != $ciOrg/$ciRepo"
else
echo "All checks passed for artifact deployment"
deployOK=1
fi
fi

# Install GPG on OSX/macOS
if [ $BUILD_OS = 'macOS' ]; then
HOMEBREW_NO_AUTO_UPDATE=1 brew install gnupg2
fi

# Import the GPG signing key.
keyFile=.ci/signingkey.asc
if [ "$deployOK" ]; then
echo "== Importing GPG keypair =="
mkdir -p .ci
echo "$SIGNING_ASC" > "$keyFile"
ls -la "$keyFile"
gpg --batch --fast-import "$keyFile"
checkSuccess $?
fi

# Run the build.
BUILD_ARGS='-B -Djdk.tls.client.protocols="TLSv1,TLSv1.1,TLSv1.2"'
if [ "$deployOK" ]; then
echo
echo "== Building and deploying master SNAPSHOT =="
mvn -Pdeploy-to-scijava $BUILD_ARGS deploy
checkSuccess $?
elif [ "$deployOK" -a -f release.properties ]; then
echo
echo "== Cutting and deploying release version =="
mvn -B $BUILD_ARGS release:perform
checkSuccess $?
echo "== Invalidating SciJava Maven repository cache =="
curl -fsLO https://raw.githubusercontent.com/scijava/scijava-scripts/master/maven-helper.sh &&
gav=$(sh maven-helper.sh gav-from-pom pom.xml) &&
ga=${gav%:*} &&
echo "--> Artifact to invalidate = $ga" &&
echo "machine maven.scijava.org" >"$HOME/.netrc" &&
echo " login $MAVEN_USER" >>"$HOME/.netrc" &&
echo " password $MAVEN_PASS" >>"$HOME/.netrc" &&
sh maven-helper.sh invalidate-cache "$ga"
checkSuccess $?
else
echo
echo "== Building the artifact locally only =="
mvn $BUILD_ARGS install javadoc:javadoc
checkSuccess $?
fi
echo ::endgroup::
fi

# Configure conda environment, if one is needed.
if [ -f environment.yml ]; then
echo ::group::"= Conda setup ="

condaDir=$HOME/miniconda
condaSh=$condaDir/etc/profile.d/conda.sh
if [ ! -f "$condaSh" ]; then
echo
echo "== Installing conda =="
python_version=${python -V}
python_version=${python_version:7:3} # get python version in the format like '2.7'
if [ "${python_version}" = "2.7" ]; then
wget https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh -O miniconda.sh
else
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh
fi
rm -rf "$condaDir"
bash miniconda.sh -b -p "$condaDir"
checkSuccess $?
fi

echo
echo "== Updating conda =="
. "$condaSh" &&
conda config --set always_yes yes --set changeps1 no &&
conda update -q conda &&
conda info -a
checkSuccess $?

echo
echo "== Configuring environment =="
condaEnv=ci-scijava
test -d "$condaDir/envs/$condaEnv" && condaAction=update || condaAction=create
conda env "$condaAction" -n "$condaEnv" -f environment.yml &&
conda activate "$condaEnv"
checkSuccess $?

echo ::endgroup::
fi

# Execute Jupyter notebooks.
if which jupyter >/dev/null 2>/dev/null; then
echo ::group::"= Jupyter notebooks ="
# NB: This part is fiddly. We want to loop over files even with spaces,
# so we use the "find ... -print0 | while read $'\0' ..." idiom.
# However, that runs the piped expression in a subshell, which means
# that any updates to the success variable will not persist outside
# the loop. So we suppress all stdout inside the loop, echoing only
# the final value of success upon completion, and then capture the
# echoed value back into the parent shell's success variable.
success=$(find . -name '*.ipynb' -print0 | {
while read -d $'\0' nbf; do
echo 1>&2
echo "== $nbf ==" 1>&2
jupyter nbconvert --execute --stdout "$nbf" >/dev/null
checkSuccess $?
done
echo $success
})
echo ::endgroup::
fi

exit $success
11 changes: 11 additions & 0 deletions github-action-ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

#
# github-action-ci.sh - A script to set up ci-related environment variables from GitHub Actions
#

echo "BUILD_REPOSITORY=${GITHUB_REPOSITORY}"
echo "BUILD_OS=${RUNNER_OS}"

echo "BUILD_REPOSITORY=${GITHUB_REPOSITORY}" >> $GITHUB_ENV
echo "BUILD_OS=${RUNNER_OS}" >> $GITHUB_ENV
Loading