From da318ab82e5d0824b267abc8340b025cdc50d816 Mon Sep 17 00:00:00 2001 From: Jack Yuan <55564584+yongleyuan@users.noreply.github.com> Date: Sun, 14 Mar 2021 01:37:36 -0600 Subject: [PATCH 01/77] Create main.yml Create `main.yml` to adapt `travis-build.sh`, `travisify.sh`, and, `travis-javadoc.sh` to GitHub Actions. --- .github/workflows/main.yml | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..26c56f5 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,46 @@ +# This is a GitHub action that runs the following Travis builds every time a push/commit event occurs. +# +# travis-build.sh +# travisify.sh +# travis-javadoc.sh + +name: CI + +# Triggers the workflow on push for every branch +on: push + +jobs: + build: + # This workflow runs on Windows machines + runs-on: windows-latest + + steps: + # Checks-out the repository under $GITHUB_WORKSPACE, so the job can access it + - uses: actions/checkout@v2 + + # Set up the JDK version + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + + # Build by running travis-build.sh + - name: travis-build + run: | + echo Running travis-build.sh + sh ./travis-build.sh + echo Finished running travis-build.sh + + # Build by running travisify.sh + - name: travisify + run: | + echo Running travisify.sh + sh ./travisify.sh + echo Finished running travisify.sh + + # Build by running travis-javadoc.sh + - name: travis-javadoc + run: | + echo Running travis-javadoc.sh + sh ./travis-javadoc.sh + echo Finished running travis-javadoc.sh From b9b063e688efb436e71e884d4519386158786b5d Mon Sep 17 00:00:00 2001 From: Jack Yuan <55564584+yongleyuan@users.noreply.github.com> Date: Thu, 18 Mar 2021 02:37:29 -0500 Subject: [PATCH 02/77] Update main.yml Commented out `travisify.sh` and `travis-javadoc.sh' to test `travis-build.sh` first. --- .github/workflows/main.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 26c56f5..440ad37 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -31,16 +31,16 @@ jobs: sh ./travis-build.sh echo Finished running travis-build.sh - # Build by running travisify.sh - - name: travisify - run: | - echo Running travisify.sh - sh ./travisify.sh - echo Finished running travisify.sh +# # Build by running travisify.sh +# - name: travisify +# run: | +# echo Running travisify.sh +# sh ./travisify.sh +# echo Finished running travisify.sh - # Build by running travis-javadoc.sh - - name: travis-javadoc - run: | - echo Running travis-javadoc.sh - sh ./travis-javadoc.sh - echo Finished running travis-javadoc.sh +# # Build by running travis-javadoc.sh +# - name: travis-javadoc +# run: | +# echo Running travis-javadoc.sh +# sh ./travis-javadoc.sh +# echo Finished running travis-javadoc.sh From caf9e34162a1c9b266adfa163b3fb836c1fb4460 Mon Sep 17 00:00:00 2001 From: Jack Yuan <55564584+yongleyuan@users.noreply.github.com> Date: Thu, 18 Mar 2021 10:17:02 -0500 Subject: [PATCH 03/77] Delete .github/workflows directory This directory is unnecessary as the goal was not to create a GitHub Action. --- .github/workflows/main.yml | 46 -------------------------------------- 1 file changed, 46 deletions(-) delete mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 440ad37..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,46 +0,0 @@ -# This is a GitHub action that runs the following Travis builds every time a push/commit event occurs. -# -# travis-build.sh -# travisify.sh -# travis-javadoc.sh - -name: CI - -# Triggers the workflow on push for every branch -on: push - -jobs: - build: - # This workflow runs on Windows machines - runs-on: windows-latest - - steps: - # Checks-out the repository under $GITHUB_WORKSPACE, so the job can access it - - uses: actions/checkout@v2 - - # Set up the JDK version - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 - with: - java-version: 1.8 - - # Build by running travis-build.sh - - name: travis-build - run: | - echo Running travis-build.sh - sh ./travis-build.sh - echo Finished running travis-build.sh - -# # Build by running travisify.sh -# - name: travisify -# run: | -# echo Running travisify.sh -# sh ./travisify.sh -# echo Finished running travisify.sh - -# # Build by running travis-javadoc.sh -# - name: travis-javadoc -# run: | -# echo Running travis-javadoc.sh -# sh ./travis-javadoc.sh -# echo Finished running travis-javadoc.sh From 115e13861ad40ee1a13d3f89cba2810ed35b8d4d Mon Sep 17 00:00:00 2001 From: Jack Yuan Date: Fri, 19 Mar 2021 18:10:26 -0500 Subject: [PATCH 04/77] Copied and pasted codes from `travis-build.sh` to `github-action-build.sh`. --- github-action-build.sh | 243 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 243 insertions(+) create mode 100644 github-action-build.sh diff --git a/github-action-build.sh b/github-action-build.sh new file mode 100644 index 0000000..1a759e1 --- /dev/null +++ b/github-action-build.sh @@ -0,0 +1,243 @@ +#!/bin/bash + +# +# travis-build.sh - A script to build and/or release SciJava-based projects. +# + +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 travis_fold:start:scijava-maven + echo "= 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=.travis/settings.xml + if [ -f "$customSettings" ] + then + cp "$customSettings" "$settingsFile" + else + cat >"$settingsFile" < + + + scijava.releases + travis + \${env.MAVEN_PASS} + + + scijava.snapshots + travis + \${env.MAVEN_PASS} + + + sonatype-nexus-releases + scijava-ci + \${env.OSSRH_PASS} + + +EOL + # NB: Use maven.scijava.org instead of Central if defined in repositories. + # This hopefully avoids intermittent "ReasonPhrase:Forbidden" errors + # when the Travis build pings Maven Central; see travis-ci/travis-ci#6593. + grep -A 2 '' pom.xml | grep -q 'maven.scijava.org' && + cat >>"$settingsFile" < + + scijava-mirror + SciJava mirror + https://maven.scijava.org/content/groups/public/ + central + + +EOL + cat >>"$settingsFile" < + + gpg + + + \${env.HOME}/.gnupg + + + + \${env.GPG_KEY_NAME} + \${env.GPG_PASSPHRASE} + + + + +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 [ "$TRAVIS_SECURE_ENV_VARS" != true ] + then + echo "No deploy -- secure environment variables not available" + elif [ "$TRAVIS_PULL_REQUEST" != false ] + then + echo "No deploy -- pull request detected" + elif [ "$TRAVIS_REPO_SLUG" != "$ciOrg/$ciRepo" ] + then + echo "No deploy -- repository fork: $TRAVIS_REPO_SLUG != $ciOrg/$ciRepo" + # TODO: Detect travis-ci.org versus travis-ci.com? + else + echo "All checks passed for artifact deployment" + deployOK=1 + fi + fi + + # Install GPG on OSX/macOS + if [ "$TRAVIS_OS_NAME" = osx ] + then + HOMEBREW_NO_AUTO_UPDATE=1 brew install gnupg2 + fi + + # Import the GPG signing key. + keyFile=.travis/signingkey.asc + key=$1 + iv=$2 + if [ "$key" -a "$iv" -a -f "$keyFile.enc" ] + then + # NB: Key and iv values were given as arguments. + echo + echo "== Decrypting GPG keypair ==" + openssl aes-256-cbc -K "$key" -iv "$iv" -in "$keyFile.enc" -out "$keyFile" -d + checkSuccess $? + fi + if [ "$deployOK" -a -f "$keyFile" ] + then + echo + echo "== Importing GPG keypair ==" + gpg --batch --fast-import "$keyFile" + checkSuccess $? + fi + + # Run the build. + BUILD_ARGS='-B -Djdk.tls.client.protocols="TLSv1,TLSv1.1,TLSv1.2"' + if [ "$deployOK" -a "$TRAVIS_BRANCH" = master ] + 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 travis" >> "$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 travis_fold:end:scijava-maven +fi + +# Configure conda environment, if one is needed. +if [ -f environment.yml ] +then + echo travis_fold:start:scijava-conda + echo "= Conda setup =" + + condaDir=$HOME/miniconda + condaSh=$condaDir/etc/profile.d/conda.sh + if [ ! -f "$condaSh" ]; then + echo + echo "== Installing conda ==" + if [ "$TRAVIS_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=travis-scijava + test -d "$condaDir/envs/$condaEnv" && condaAction=update || condaAction=create + conda env "$condaAction" -n "$condaEnv" -f environment.yml && + conda activate "$condaEnv" + checkSuccess $? + + echo travis_fold:end:scijava-conda +fi + +# Execute Jupyter notebooks. +if which jupyter >/dev/null 2>/dev/null +then + echo travis_fold:start:scijava-jupyter + echo "= 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 travis_fold:end:scijava-jupyter +fi + +exit $success From 1ce941365ddc1c3d22dffd4bf78a006abb62dee4 Mon Sep 17 00:00:00 2001 From: Jack Yuan Date: Wed, 24 Mar 2021 17:58:59 -0500 Subject: [PATCH 05/77] added comments in for further changes to migrate to GitHub Actions --- github-action-build.sh | 77 +++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 43 deletions(-) diff --git a/github-action-build.sh b/github-action-build.sh index 1a759e1..2dcfd6e 100644 --- a/github-action-build.sh +++ b/github-action-build.sh @@ -16,8 +16,7 @@ checkSuccess() { } # Build Maven projects. -if [ -f pom.xml ] -then +if [ -f pom.xml ]; then echo travis_fold:start:scijava-maven echo "= Maven build =" echo @@ -25,16 +24,16 @@ then # 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" + 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=.travis/settings.xml - if [ -f "$customSettings" ] - then + # Since Travis files will be deleted, just manually set $settingsFile + if [ -f "$customSettings" ]; then cp "$customSettings" "$settingsFile" - else + else # Might need to change travis cat >"$settingsFile" < @@ -59,7 +58,7 @@ EOL # This hopefully avoids intermittent "ReasonPhrase:Forbidden" errors # when the Travis build pings Maven Central; see travis-ci/travis-ci#6593. grep -A 2 '' pom.xml | grep -q 'maven.scijava.org' && - cat >>"$settingsFile" <>"$settingsFile" < scijava-mirror @@ -91,25 +90,25 @@ EOL # 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 + if [ $? -ne 0 ]; then echo "No deploy -- could not extract ciManagement URL" echo "Output of failed attempt follows:" echo "$ciURL" else + # https://developer.okta.com/blog/2020/05/18/travis-ci-to-github-actions + # This website specifies Travis environment variables with their + # equivalent GitHub Actions environment variables ciRepo=${ciURL##*/} ciPrefix=${ciURL%/*} ciOrg=${ciPrefix##*/} - if [ "$TRAVIS_SECURE_ENV_VARS" != true ] - then + if [ "$TRAVIS_SECURE_ENV_VARS" != true ]; then # haven't found equivalent env var echo "No deploy -- secure environment variables not available" - elif [ "$TRAVIS_PULL_REQUEST" != false ] - then + elif [ "$TRAVIS_PULL_REQUEST" != false ]; then # ${{ github.event.number }} echo "No deploy -- pull request detected" - elif [ "$TRAVIS_REPO_SLUG" != "$ciOrg/$ciRepo" ] - then + elif [ "$TRAVIS_REPO_SLUG" != "$ciOrg/$ciRepo" ]; then # ${{ github.repository }} echo "No deploy -- repository fork: $TRAVIS_REPO_SLUG != $ciOrg/$ciRepo" # TODO: Detect travis-ci.org versus travis-ci.com? + # Maybe above is not needed else echo "All checks passed for artifact deployment" deployOK=1 @@ -117,8 +116,7 @@ EOL fi # Install GPG on OSX/macOS - if [ "$TRAVIS_OS_NAME" = osx ] - then + if [ "$TRAVIS_OS_NAME" = osx ]; then # $RUNNER_OS == 'macOS' ? HOMEBREW_NO_AUTO_UPDATE=1 brew install gnupg2 fi @@ -126,16 +124,14 @@ EOL keyFile=.travis/signingkey.asc key=$1 iv=$2 - if [ "$key" -a "$iv" -a -f "$keyFile.enc" ] - then + if [ "$key" -a "$iv" -a -f "$keyFile.enc" ]; then # NB: Key and iv values were given as arguments. echo echo "== Decrypting GPG keypair ==" openssl aes-256-cbc -K "$key" -iv "$iv" -in "$keyFile.enc" -out "$keyFile" -d checkSuccess $? fi - if [ "$deployOK" -a -f "$keyFile" ] - then + if [ "$deployOK" -a -f "$keyFile" ]; then echo echo "== Importing GPG keypair ==" gpg --batch --fast-import "$keyFile" @@ -144,27 +140,25 @@ EOL # Run the build. BUILD_ARGS='-B -Djdk.tls.client.protocols="TLSv1,TLSv1.1,TLSv1.2"' - if [ "$deployOK" -a "$TRAVIS_BRANCH" = master ] - then + if [ "$deployOK" -a "$TRAVIS_BRANCH" = master ]; then # on push event, so need further info echo echo "== Building and deploying master SNAPSHOT ==" mvn -Pdeploy-to-scijava $BUILD_ARGS deploy checkSuccess $? - elif [ "$deployOK" -a -f release.properties ] - then + 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 travis" >> "$HOME/.netrc" && - echo " password $MAVEN_PASS" >> "$HOME/.netrc" && - sh maven-helper.sh invalidate-cache "$ga" + 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 travis" >>"$HOME/.netrc" && + echo " password $MAVEN_PASS" >>"$HOME/.netrc" && + sh maven-helper.sh invalidate-cache "$ga" checkSuccess $? else echo @@ -176,8 +170,7 @@ EOL fi # Configure conda environment, if one is needed. -if [ -f environment.yml ] -then +if [ -f environment.yml ]; then echo travis_fold:start:scijava-conda echo "= Conda setup =" @@ -186,7 +179,7 @@ then if [ ! -f "$condaSh" ]; then echo echo "== Installing conda ==" - if [ "$TRAVIS_PYTHON_VERSION" = "2.7" ]; then + if [ "$TRAVIS_PYTHON_VERSION" = "2.7" ]; then # ${{ matrix.python-version }} 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 @@ -199,9 +192,9 @@ then echo echo "== Updating conda ==" . "$condaSh" && - conda config --set always_yes yes --set changeps1 no && - conda update -q conda && - conda info -a + conda config --set always_yes yes --set changeps1 no && + conda update -q conda && + conda info -a checkSuccess $? echo @@ -209,15 +202,14 @@ then condaEnv=travis-scijava test -d "$condaDir/envs/$condaEnv" && condaAction=update || condaAction=create conda env "$condaAction" -n "$condaEnv" -f environment.yml && - conda activate "$condaEnv" + conda activate "$condaEnv" checkSuccess $? echo travis_fold:end:scijava-conda fi # Execute Jupyter notebooks. -if which jupyter >/dev/null 2>/dev/null -then +if which jupyter >/dev/null 2>/dev/null; then echo travis_fold:start:scijava-jupyter echo "= Jupyter notebooks =" # NB: This part is fiddly. We want to loop over files even with spaces, @@ -228,8 +220,7 @@ then # 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 + while read -d $'\0' nbf; do echo 1>&2 echo "== $nbf ==" 1>&2 jupyter nbconvert --execute --stdout "$nbf" >/dev/null From ff8de3d5e0f1a6f90f47d595972c30406a3efce9 Mon Sep 17 00:00:00 2001 From: Jack Yuan Date: Wed, 31 Mar 2021 11:12:11 -0500 Subject: [PATCH 06/77] modified --- github-action-build.sh | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/github-action-build.sh b/github-action-build.sh index 2dcfd6e..9f7fbab 100644 --- a/github-action-build.sh +++ b/github-action-build.sh @@ -29,11 +29,8 @@ if [ -f pom.xml ]; then # Populate the settings.xml configuration. mkdir -p "$HOME/.m2" settingsFile="$HOME/.m2/settings.xml" - customSettings=.travis/settings.xml # Since Travis files will be deleted, just manually set $settingsFile - if [ -f "$customSettings" ]; then - cp "$customSettings" "$settingsFile" - else # Might need to change travis + # Might need to change travis cat >"$settingsFile" < @@ -103,10 +100,10 @@ EOL ciOrg=${ciPrefix##*/} if [ "$TRAVIS_SECURE_ENV_VARS" != true ]; then # haven't found equivalent env var echo "No deploy -- secure environment variables not available" - elif [ "$TRAVIS_PULL_REQUEST" != false ]; then # ${{ github.event.number }} + elif [ ${github.event.number} != false ]; then echo "No deploy -- pull request detected" - elif [ "$TRAVIS_REPO_SLUG" != "$ciOrg/$ciRepo" ]; then # ${{ github.repository }} - echo "No deploy -- repository fork: $TRAVIS_REPO_SLUG != $ciOrg/$ciRepo" + elif [ ${ github.repository } != "$ciOrg/$ciRepo" ]; then + echo "No deploy -- repository fork: ${ github.repository } != $ciOrg/$ciRepo" # TODO: Detect travis-ci.org versus travis-ci.com? # Maybe above is not needed else @@ -116,11 +113,12 @@ EOL fi # Install GPG on OSX/macOS - if [ "$TRAVIS_OS_NAME" = osx ]; then # $RUNNER_OS == 'macOS' ? + if [ "$RUNNER_OS" == 'macOS' ]; then HOMEBREW_NO_AUTO_UPDATE=1 brew install gnupg2 fi # Import the GPG signing key. + # Do we still need this one? keyFile=.travis/signingkey.asc key=$1 iv=$2 @@ -140,7 +138,7 @@ EOL # Run the build. BUILD_ARGS='-B -Djdk.tls.client.protocols="TLSv1,TLSv1.1,TLSv1.2"' - if [ "$deployOK" -a "$TRAVIS_BRANCH" = master ]; then # on push event, so need further info + if [ "$deployOK" -a "$TRAVIS_BRANCH" = master ]; then # TODO: on push event, so need further info echo echo "== Building and deploying master SNAPSHOT ==" mvn -Pdeploy-to-scijava $BUILD_ARGS deploy @@ -179,7 +177,7 @@ if [ -f environment.yml ]; then if [ ! -f "$condaSh" ]; then echo echo "== Installing conda ==" - if [ "$TRAVIS_PYTHON_VERSION" = "2.7" ]; then # ${{ matrix.python-version }} + if [ ${ matrix.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 From cd3dc231d5773bcf989bfeba4cc97fb3cc3f4941 Mon Sep 17 00:00:00 2001 From: Jack Yuan Date: Wed, 7 Apr 2021 23:19:50 -0500 Subject: [PATCH 07/77] changed commands to corresponding shell commands --- github-action-build.sh | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/github-action-build.sh b/github-action-build.sh index 9f7fbab..354d1a2 100644 --- a/github-action-build.sh +++ b/github-action-build.sh @@ -1,7 +1,8 @@ #!/bin/bash # -# travis-build.sh - A script to build and/or release SciJava-based projects. +# github-action-build.sh - A script to build and/or release SciJava-based projects +# automatically using GitHub Actions. # dir="$(dirname "$0")" @@ -17,8 +18,7 @@ checkSuccess() { # Build Maven projects. if [ -f pom.xml ]; then - echo travis_fold:start:scijava-maven - echo "= Maven build =" + echo ::group::"= Maven build =" # beginning of travis_fold (scijava-maven) echo echo "== Configuring Maven ==" @@ -29,8 +29,11 @@ if [ -f pom.xml ]; then # Populate the settings.xml configuration. mkdir -p "$HOME/.m2" settingsFile="$HOME/.m2/settings.xml" + customSettings=.travis/settings.xml # Since Travis files will be deleted, just manually set $settingsFile - # Might need to change travis + if [ -f "$customSettings" ]; then + cp "$customSettings" "$settingsFile" + else # Might need to change travis cat >"$settingsFile" < @@ -100,10 +103,10 @@ EOL ciOrg=${ciPrefix##*/} if [ "$TRAVIS_SECURE_ENV_VARS" != true ]; then # haven't found equivalent env var echo "No deploy -- secure environment variables not available" - elif [ ${github.event.number} != false ]; then + elif [ "$TRAVIS_PULL_REQUEST" != false ]; then # ${{ github.event.number }} echo "No deploy -- pull request detected" - elif [ ${ github.repository } != "$ciOrg/$ciRepo" ]; then - echo "No deploy -- repository fork: ${ github.repository } != $ciOrg/$ciRepo" + elif [ "$TRAVIS_REPO_SLUG" != "$ciOrg/$ciRepo" ]; then # ${{ github.repository }} + echo "No deploy -- repository fork: $TRAVIS_REPO_SLUG != $ciOrg/$ciRepo" # TODO: Detect travis-ci.org versus travis-ci.com? # Maybe above is not needed else @@ -113,12 +116,11 @@ EOL fi # Install GPG on OSX/macOS - if [ "$RUNNER_OS" == 'macOS' ]; then + if [ "$TRAVIS_OS_NAME" = osx ]; then # $RUNNER_OS == 'macOS' ? HOMEBREW_NO_AUTO_UPDATE=1 brew install gnupg2 fi # Import the GPG signing key. - # Do we still need this one? keyFile=.travis/signingkey.asc key=$1 iv=$2 @@ -138,7 +140,7 @@ EOL # Run the build. BUILD_ARGS='-B -Djdk.tls.client.protocols="TLSv1,TLSv1.1,TLSv1.2"' - if [ "$deployOK" -a "$TRAVIS_BRANCH" = master ]; then # TODO: on push event, so need further info + if [ "$deployOK" -a "$TRAVIS_BRANCH" = master ]; then # on push event, so need further info echo echo "== Building and deploying master SNAPSHOT ==" mvn -Pdeploy-to-scijava $BUILD_ARGS deploy @@ -164,20 +166,19 @@ EOL mvn $BUILD_ARGS install javadoc:javadoc checkSuccess $? fi - echo travis_fold:end:scijava-maven + echo ::endgroup:: # end of travis_fold (scijava-maven) fi # Configure conda environment, if one is needed. if [ -f environment.yml ]; then - echo travis_fold:start:scijava-conda - echo "= Conda setup =" + echo ::group::"= Conda setup =" # beginning of travis_fold (scijava-conda) condaDir=$HOME/miniconda condaSh=$condaDir/etc/profile.d/conda.sh if [ ! -f "$condaSh" ]; then echo echo "== Installing conda ==" - if [ ${ matrix.python-version } = "2.7" ]; then + if [ "$TRAVIS_PYTHON_VERSION" = "2.7" ]; then # ${{ matrix.python-version }} 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 @@ -203,13 +204,12 @@ if [ -f environment.yml ]; then conda activate "$condaEnv" checkSuccess $? - echo travis_fold:end:scijava-conda + echo ::endgroup:: # end of scijava-conda fi # Execute Jupyter notebooks. if which jupyter >/dev/null 2>/dev/null; then - echo travis_fold:start:scijava-jupyter - echo "= Jupyter notebooks =" + echo ::group::"= Jupyter notebooks =" # beginning of travis_fold (scijava-jupyter) # 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 @@ -226,7 +226,7 @@ if which jupyter >/dev/null 2>/dev/null; then done echo $success }) - echo travis_fold:end:scijava-jupyter + echo ::endgroup:: # end of travis_fold (scijava-jupyter) fi exit $success From e5e54750ecf96312f4a905d003d93120832c15e4 Mon Sep 17 00:00:00 2001 From: Jack Yuan Date: Thu, 8 Apr 2021 02:41:23 -0500 Subject: [PATCH 08/77] changed github-action-build.sh file --- github-action-build.sh | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/github-action-build.sh b/github-action-build.sh index 354d1a2..bc1b96e 100644 --- a/github-action-build.sh +++ b/github-action-build.sh @@ -29,7 +29,7 @@ if [ -f pom.xml ]; then # Populate the settings.xml configuration. mkdir -p "$HOME/.m2" settingsFile="$HOME/.m2/settings.xml" - customSettings=.travis/settings.xml + customSettings=.gh-action/settings.xml # Since Travis files will be deleted, just manually set $settingsFile if [ -f "$customSettings" ]; then cp "$customSettings" "$settingsFile" @@ -101,14 +101,13 @@ EOL ciRepo=${ciURL##*/} ciPrefix=${ciURL%/*} ciOrg=${ciPrefix##*/} - if [ "$TRAVIS_SECURE_ENV_VARS" != true ]; then # haven't found equivalent env var + if [ "${github.secret.github_token}" != true ]; then echo "No deploy -- secure environment variables not available" - elif [ "$TRAVIS_PULL_REQUEST" != false ]; then # ${{ github.event.number }} + elif [ "${github.event.number}" != false ]; then echo "No deploy -- pull request detected" - elif [ "$TRAVIS_REPO_SLUG" != "$ciOrg/$ciRepo" ]; then # ${{ github.repository }} - echo "No deploy -- repository fork: $TRAVIS_REPO_SLUG != $ciOrg/$ciRepo" + elif [ "${github.repository}" != "$ciOrg/$ciRepo" ]; then + echo "No deploy -- repository fork: ${github.repository} != $ciOrg/$ciRepo" # TODO: Detect travis-ci.org versus travis-ci.com? - # Maybe above is not needed else echo "All checks passed for artifact deployment" deployOK=1 @@ -116,12 +115,12 @@ EOL fi # Install GPG on OSX/macOS - if [ "$TRAVIS_OS_NAME" = osx ]; then # $RUNNER_OS == 'macOS' ? + if [ "${runner.os}" = 'macOS' ]; then HOMEBREW_NO_AUTO_UPDATE=1 brew install gnupg2 fi # Import the GPG signing key. - keyFile=.travis/signingkey.asc + keyFile=.gh-action/signingkey.asc key=$1 iv=$2 if [ "$key" -a "$iv" -a -f "$keyFile.enc" ]; then @@ -140,7 +139,7 @@ EOL # Run the build. BUILD_ARGS='-B -Djdk.tls.client.protocols="TLSv1,TLSv1.1,TLSv1.2"' - if [ "$deployOK" -a "$TRAVIS_BRANCH" = master ]; then # on push event, so need further info + if [ "$deployOK" -a "${github.head_ref}" = master ]; then # on push event, so need further info echo echo "== Building and deploying master SNAPSHOT ==" mvn -Pdeploy-to-scijava $BUILD_ARGS deploy @@ -178,7 +177,7 @@ if [ -f environment.yml ]; then if [ ! -f "$condaSh" ]; then echo echo "== Installing conda ==" - if [ "$TRAVIS_PYTHON_VERSION" = "2.7" ]; then # ${{ matrix.python-version }} + if [ "${matrix.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 From 5796a488845f244abf831e6c0084e2fd9d028f6b Mon Sep 17 00:00:00 2001 From: Jack Yuan Date: Thu, 29 Apr 2021 02:26:57 -0500 Subject: [PATCH 09/77] deleted unnecessary comments --- github-action-build.sh | 25 ++-- github-actionify.sh | 280 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 292 insertions(+), 13 deletions(-) create mode 100644 github-actionify.sh diff --git a/github-action-build.sh b/github-action-build.sh index bc1b96e..ee36bd6 100644 --- a/github-action-build.sh +++ b/github-action-build.sh @@ -18,7 +18,7 @@ checkSuccess() { # Build Maven projects. if [ -f pom.xml ]; then - echo ::group::"= Maven build =" # beginning of travis_fold (scijava-maven) + echo ::group::"= Maven build =" echo echo "== Configuring Maven ==" @@ -30,21 +30,20 @@ if [ -f pom.xml ]; then mkdir -p "$HOME/.m2" settingsFile="$HOME/.m2/settings.xml" customSettings=.gh-action/settings.xml - # Since Travis files will be deleted, just manually set $settingsFile if [ -f "$customSettings" ]; then cp "$customSettings" "$settingsFile" - else # Might need to change travis + else cat >"$settingsFile" < scijava.releases - travis + scijava-ci \${env.MAVEN_PASS} scijava.snapshots - travis + scijava-ci \${env.MAVEN_PASS} @@ -139,7 +138,7 @@ EOL # Run the build. BUILD_ARGS='-B -Djdk.tls.client.protocols="TLSv1,TLSv1.1,TLSv1.2"' - if [ "$deployOK" -a "${github.head_ref}" = master ]; then # on push event, so need further info + if [ "$deployOK" -a "${github.head_ref}" = master ]; then echo echo "== Building and deploying master SNAPSHOT ==" mvn -Pdeploy-to-scijava $BUILD_ARGS deploy @@ -155,7 +154,7 @@ EOL ga=${gav%:*} && echo "--> Artifact to invalidate = $ga" && echo "machine maven.scijava.org" >"$HOME/.netrc" && - echo " login travis" >>"$HOME/.netrc" && + echo " login scijava-ci" >>"$HOME/.netrc" && echo " password $MAVEN_PASS" >>"$HOME/.netrc" && sh maven-helper.sh invalidate-cache "$ga" checkSuccess $? @@ -165,12 +164,12 @@ EOL mvn $BUILD_ARGS install javadoc:javadoc checkSuccess $? fi - echo ::endgroup:: # end of travis_fold (scijava-maven) + echo ::endgroup:: fi # Configure conda environment, if one is needed. if [ -f environment.yml ]; then - echo ::group::"= Conda setup =" # beginning of travis_fold (scijava-conda) + echo ::group::"= Conda setup =" condaDir=$HOME/miniconda condaSh=$condaDir/etc/profile.d/conda.sh @@ -197,18 +196,18 @@ if [ -f environment.yml ]; then echo echo "== Configuring environment ==" - condaEnv=travis-scijava + condaEnv=github-scijava test -d "$condaDir/envs/$condaEnv" && condaAction=update || condaAction=create conda env "$condaAction" -n "$condaEnv" -f environment.yml && conda activate "$condaEnv" checkSuccess $? - echo ::endgroup:: # end of scijava-conda + echo ::endgroup:: fi # Execute Jupyter notebooks. if which jupyter >/dev/null 2>/dev/null; then - echo ::group::"= Jupyter notebooks =" # beginning of travis_fold (scijava-jupyter) + 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 @@ -225,7 +224,7 @@ if which jupyter >/dev/null 2>/dev/null; then done echo $success }) - echo ::endgroup:: # end of travis_fold (scijava-jupyter) + echo ::endgroup:: fi exit $success diff --git a/github-actionify.sh b/github-actionify.sh new file mode 100644 index 0000000..87e4ab2 --- /dev/null +++ b/github-actionify.sh @@ -0,0 +1,280 @@ +#!/bin/sh + +# travisify.sh +# +# Script for enabling or updating Travis CI builds for a given repository. + +#set -e + +dir="$(dirname "$0")" + +travisDir=.travis +travisConfig=.travis.yml +travisBuildScript=$travisDir/build.sh +travisSettingsFile=$travisDir/settings.xml +travisNotifyScript=$travisDir/notify.sh +credentialsDir=$HOME/.scijava/credentials +varsFile=$credentialsDir/vars +signingKeySourceFile=$credentialsDir/scijava-ci-signing.asc +signingKeyDestFile=$travisDir/signingkey.asc +pomMinVersion='17.1.1' +tmpFile=travisify.tmp + +info() { echo "- $@"; } +warn() { echo "[WARNING] $@" 1>&2; } +err() { echo "[ERROR] $@" 1>&2; } +die() { err "$@"; exit 1; } + +check() { + for tool in $@ + do + which "$tool" >/dev/null || + die "The '$tool' utility is required but not found" + done +} + +var() { + grep "^$1=" "$varsFile" || + die "$1 not found in $varsFile" +} + +update() { + file=$1 + msg=$2 + exe=$3 + test "$msg" || msg="Travis: update $file" + if [ -e "$file" ] + then + if diff -q "$file" "$tmpFile" >/dev/null + then + info "$file is already OK" + else + info "Updating $file" + $EXEC rm -rf "$file" + $EXEC mv -f "$tmpFile" "$file" + fi + else + info "Creating $file" + $EXEC mkdir -p "$(dirname "$file")" + $EXEC mv "$tmpFile" "$file" + fi + rm -rf "$tmpFile" + $EXEC git add "$file" + if [ -n "$exe" ] + then + info "Adding execute permission to $file" + $EXEC git update-index --chmod=+x "$file" + fi + $EXEC git diff-index --quiet HEAD -- || $EXEC git commit -m "$msg" +} + +process() { + cd "$1" + + # -- Git sanity checks -- + + repoSlug=$(xmllint --xpath '//*[local-name()="project"]/*[local-name()="scm"]/*[local-name()="connection"]' pom.xml|sed 's_.*github.com[:/]\(.*\)<.*_\1_') + test "$repoSlug" && info "Repository = $repoSlug" || die 'Could not determine GitHub repository slug' + case "$repoSlug" in + *.git) + die "GitHub repository slug ('$repoSlug') ends in '.git'; please fix the POM" + ;; + esac + git fetch >/dev/null + git diff-index --quiet HEAD -- || die "Dirty working copy" + currentBranch=$(git rev-parse --abbrev-ref HEAD) + upstreamBranch=$(git rev-parse --abbrev-ref --symbolic-full-name @{u}) + remote=${upstreamBranch%/*} + defaultBranch=$(git remote show "$remote" | grep "HEAD branch" | sed 's/.*: //') + test "$currentBranch" = "$defaultBranch" || die "Non-default branch: $currentBranch" + git merge --ff --ff-only 'HEAD@{u}' >/dev/null || + die "Cannot fast forward (local diverging?)" +# test "$(git rev-parse HEAD)" = "$(git rev-parse 'HEAD@{u}')" || +# die "Mismatch with upstream branch (local ahead?)" + + # -- POM sanity checks -- + + parent=$(xmllint --xpath '//*[local-name()="project"]/*[local-name()="parent"]/*[local-name()="artifactId"]' pom.xml|sed 's/[^>]*>//'|sed 's/<.*//') + if [ -z "$SKIP_PARENT_CHECK" ] + then + test "$parent" = "pom-scijava" || + die "Not pom-scijava parent: $parent. Run with -p flag to skip this check." + fi + + domain=$(grep "travis-ci\.[a-z]*/$repoSlug" pom.xml 2>/dev/null | sed 's/.*\(travis-ci\.[a-z]*\).*/\1/') + test "$domain" && + info "Detected domain from pom.xml: $domain" || + die "No valid ciManagement section in pom.xml. Please add one, then try again." + + case $domain in + travis-ci.com) mode=pro;; + travis-ci.org) mode=org;; + *) die "Unsupported domain: $domain";; + esac + + # -- Travis sanity checks -- + + test -e "$travisDir" -a ! -d "$travisDir" && die "$travisDir is not a directory" + test -e "$travisConfig" -a ! -f "$travisConfig" && die "$travisConfig is not a regular file" + test -e "$travisConfig" && warn "$travisConfig already exists" + test -e "$travisBuildScript" && warn "$travisBuildScript already exists" + + # -- Do things -- + + # Add/update the Travis configuration file. + cat >"$tmpFile" <"$tmpFile" <]*>//'|sed 's/<.*//') + # HACK: Using a lexicographic comparison here is imperfect. + if [ "$version" \< "$pomMinVersion" ] + then + info 'Upgrading pom-scijava version' + sed "s|^ $version$| $pomMinVersion|" pom.xml >"$tmpFile" + update pom.xml "POM: update pom-scijava parent to $pomMinVersion" + else + info "Version of pom-scijava ($version) is OK" + fi + fi + + # ensure section is present + releaseProfile=$(grep '' pom.xml 2>/dev/null | sed 's/[^>]*>//' | sed 's/<.*//') + if [ "$releaseProfile" ] + then + test "$releaseProfile" = 'deploy-to-scijava' || + warn "Unknown release profile: $releaseProfile" + else + info 'Adding property' + cp pom.xml "$tmpFile" + perl -0777 -i -pe 's/(\n\t<\/properties>\n)/\n\n\t\t\n\t\tdeploy-to-scijava<\/releaseProfiles>\1/igs' "$tmpFile" + update pom.xml 'POM: deploy releases to the SciJava repository' + fi + + # update the README + if grep -q "travis-ci\.[a-zA-Z0-9/_-]*\.svg" README.md >/dev/null 2>&1 + then + info "Updating README.md Travis badge" + sed "s|travis-ci\.[a-zA-Z0-9/_-]*|$domain/$repoSlug|g" README.md >"$tmpFile" + update README.md 'Travis: fix README.md badge link' + else + info "Adding Travis badge to README.md" + echo "[![](https://$domain/$repoSlug.svg?branch=$defaultBranch)](https://$domain/$repoSlug)" >"$tmpFile" + echo >>"$tmpFile" + test -f README.md && cat README.md >>"$tmpFile" + update README.md 'Travis: add badge to README.md' + fi + + # encrypt key/value pairs in variables file + if [ -f "$varsFile" ] + then + while read p; do + # Skip comments. (Cannot use ${p:0:1} because it's bash-specific.) + case "$p" in + '#'*) continue;; + esac + info "Encrypting ${p%%=*}" + yes | $EXEC travis encrypt --$mode "$p" --add env.global --repo "$repoSlug" + test $? -eq 0 || die "Failed to encrypt variable '$p'" + done <"$varsFile" + $EXEC git commit "$travisConfig" -m "Travis: add encrypted environment variables" + else + warn "No $varsFile found. Travis will not have any environment variables set!" + fi + + # encrypt GPG keypair + if [ -f "$signingKeySourceFile" ] + then + info "Encrypting $signingKeyDestFile" + if [ -z "$EXEC" ] + then + rm -f "$signingKeyDestFile.enc" + encryptOutput=$(travis encrypt-file --$mode "$signingKeySourceFile" "$signingKeyDestFile.enc" --repo "$repoSlug") + test $? -eq 0 || die "Failed to encrypt signing key." + encryptResult=$(echo "$encryptOutput" | grep openssl) + test "$encryptResult" || die "No openssl variables emitted." + key=$(echo "$encryptResult" | cut -d' ' -f4) + iv=$(echo "$encryptResult" | cut -d' ' -f6) + sed -i.bak "s/\(sh travis-build.sh\)/\1 $key $iv/" "$travisBuildScript" + rm -f "$travisBuildScript.bak" + git add "$travisBuildScript" "$signingKeyDestFile.enc" + git commit -m "Travis: add encrypted GPG signing keypair" + fi + else + warn "No $signingKeySourceFile found. Travis will not be able to do GPG signing!" + fi +} + +test -d "$credentialsDir" || + die "This script requires configuration stored in $credentialsDir,\n" \ + "including $varsFile for needed environment variables,\n" \ + "and $signingKeySourceFile for signing of artifacts.\n" \ + "Please contact a SciJava administrator to receive a copy of this content." + +# check prerequisites +check git sed cut perl xmllint travis + +# parse arguments +EXEC=: +SKIP_PARENT_CHECK= +while test $# -gt 0 +do + case "$1" in + -f) EXEC=;; + -p) SKIP_PARENT_CHECK=true;; + --) break;; + -*) echo "Ignoring unknown option: $1" >&2; break;; + *) break;; + esac + shift +done + +test "$EXEC" && warn "Simulation only. Run with -f flag to go for real." + +# process arguments +if [ $# -gt 0 ] +then + for d in $@ + do ( + echo "[$d]" + process "$d" + ) done +else + process . +fi From 2cf6a93015223f86b6b0e9c9d3dc882b20e44433 Mon Sep 17 00:00:00 2001 From: Jack Yuan Date: Fri, 30 Apr 2021 09:07:18 -0500 Subject: [PATCH 10/77] test_var --- github-action-build.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/github-action-build.sh b/github-action-build.sh index ee36bd6..3b487dd 100644 --- a/github-action-build.sh +++ b/github-action-build.sh @@ -56,6 +56,7 @@ EOL # NB: Use maven.scijava.org instead of Central if defined in repositories. # This hopefully avoids intermittent "ReasonPhrase:Forbidden" errors # when the Travis build pings Maven Central; see travis-ci/travis-ci#6593. + # TODO: Try removing and see if error comes up grep -A 2 '' pom.xml | grep -q 'maven.scijava.org' && cat >>"$settingsFile" < @@ -100,7 +101,10 @@ EOL ciRepo=${ciURL##*/} ciPrefix=${ciURL%/*} ciOrg=${ciPrefix##*/} - if [ "${github.secret.github_token}" != true ]; then + if [ $test_var == true ]; then + echo "----TEST COMPLETE----" + # TODO: try ${ secret.GITHUB_TOKEN } / double braces? + if [ "${ github.secret.github_token}" != true ]; then echo "No deploy -- secure environment variables not available" elif [ "${github.event.number}" != false ]; then echo "No deploy -- pull request detected" From 3b7d8a9defd8bf38935aa1d717c9bd2ab6cc7783 Mon Sep 17 00:00:00 2001 From: Jack Yuan Date: Tue, 11 May 2021 02:40:03 -0500 Subject: [PATCH 11/77] double curly braces for github --- github-action-build.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/github-action-build.sh b/github-action-build.sh index ee36bd6..8468617 100644 --- a/github-action-build.sh +++ b/github-action-build.sh @@ -100,12 +100,12 @@ EOL ciRepo=${ciURL##*/} ciPrefix=${ciURL%/*} ciOrg=${ciPrefix##*/} - if [ "${github.secret.github_token}" != true ]; then + if [ ${{github.secret.github_token}} != true ]; then echo "No deploy -- secure environment variables not available" - elif [ "${github.event.number}" != false ]; then + elif [ ${{github.event.number}} != false ]; then echo "No deploy -- pull request detected" - elif [ "${github.repository}" != "$ciOrg/$ciRepo" ]; then - echo "No deploy -- repository fork: ${github.repository} != $ciOrg/$ciRepo" + elif [ ${{github.repository}} != "$ciOrg/$ciRepo" ]; then + echo "No deploy -- repository fork: ${{github.repository}} != $ciOrg/$ciRepo" # TODO: Detect travis-ci.org versus travis-ci.com? else echo "All checks passed for artifact deployment" @@ -138,7 +138,7 @@ EOL # Run the build. BUILD_ARGS='-B -Djdk.tls.client.protocols="TLSv1,TLSv1.1,TLSv1.2"' - if [ "$deployOK" -a "${github.head_ref}" = master ]; then + if [ "$deployOK" -a ${{github.head_ref}} = master ]; then echo echo "== Building and deploying master SNAPSHOT ==" mvn -Pdeploy-to-scijava $BUILD_ARGS deploy From a037a5386728d6b8bf685773ad12840d83e6cb68 Mon Sep 17 00:00:00 2001 From: Jack Yuan Date: Tue, 11 May 2021 02:49:03 -0500 Subject: [PATCH 12/77] deleted unexpected eof --- github-action-build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github-action-build.sh b/github-action-build.sh index b7616f4..e44628a 100644 --- a/github-action-build.sh +++ b/github-action-build.sh @@ -231,4 +231,4 @@ if which jupyter >/dev/null 2>/dev/null; then echo ::endgroup:: fi -exit $success +exit $success \ No newline at end of file From 42e989e1afaa3fb2a46b01e8f94dee747e36505d Mon Sep 17 00:00:00 2001 From: Jack Yuan Date: Tue, 11 May 2021 02:53:36 -0500 Subject: [PATCH 13/77] deleted double curly braces --- github-action-build.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/github-action-build.sh b/github-action-build.sh index e44628a..55eedaa 100644 --- a/github-action-build.sh +++ b/github-action-build.sh @@ -106,10 +106,10 @@ EOL # TODO: try ${ secret.GITHUB_TOKEN } / double braces? if [ "${ github.secret.github_token}" != true ]; then echo "No deploy -- secure environment variables not available" - elif [ ${{github.event.number}} != false ]; then + elif [ ${github.event.number} != false ]; then echo "No deploy -- pull request detected" - elif [ ${{github.repository}} != "$ciOrg/$ciRepo" ]; then - echo "No deploy -- repository fork: ${{github.repository}} != $ciOrg/$ciRepo" + elif [ ${github.repository} != "$ciOrg/$ciRepo" ]; then + echo "No deploy -- repository fork: ${github.repository} != $ciOrg/$ciRepo" # TODO: Detect travis-ci.org versus travis-ci.com? else echo "All checks passed for artifact deployment" @@ -142,7 +142,7 @@ EOL # Run the build. BUILD_ARGS='-B -Djdk.tls.client.protocols="TLSv1,TLSv1.1,TLSv1.2"' - if [ "$deployOK" -a ${{github.head_ref}} = master ]; then + if [ "$deployOK" -a ${github.head_ref} = master ]; then echo echo "== Building and deploying master SNAPSHOT ==" mvn -Pdeploy-to-scijava $BUILD_ARGS deploy @@ -231,4 +231,4 @@ if which jupyter >/dev/null 2>/dev/null; then echo ::endgroup:: fi -exit $success \ No newline at end of file +exit $success From e8958e3c7cda6db10fc9ef8b557779de82b5261d Mon Sep 17 00:00:00 2001 From: Jack Yuan Date: Tue, 11 May 2021 02:56:46 -0500 Subject: [PATCH 14/77] added after to avoid unexpected eof --- github-action-build.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/github-action-build.sh b/github-action-build.sh index 55eedaa..9b90c24 100644 --- a/github-action-build.sh +++ b/github-action-build.sh @@ -103,6 +103,7 @@ EOL ciOrg=${ciPrefix##*/} if [ $test_var == true ]; then echo "----TEST COMPLETE----" + fi # TODO: try ${ secret.GITHUB_TOKEN } / double braces? if [ "${ github.secret.github_token}" != true ]; then echo "No deploy -- secure environment variables not available" From 89b227c0791b138ef665decbdf5b62792802e677 Mon Sep 17 00:00:00 2001 From: Jack Yuan Date: Tue, 11 May 2021 03:04:51 -0500 Subject: [PATCH 15/77] commented out test section to see what caused unexpected eof error --- github-action-build.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/github-action-build.sh b/github-action-build.sh index 9b90c24..b4cbf36 100644 --- a/github-action-build.sh +++ b/github-action-build.sh @@ -101,9 +101,9 @@ EOL ciRepo=${ciURL##*/} ciPrefix=${ciURL%/*} ciOrg=${ciPrefix##*/} - if [ $test_var == true ]; then - echo "----TEST COMPLETE----" - fi + # if [ $test_var == true ]; then + # echo "----TEST COMPLETE----" + # fi # TODO: try ${ secret.GITHUB_TOKEN } / double braces? if [ "${ github.secret.github_token}" != true ]; then echo "No deploy -- secure environment variables not available" From 62c670f7884026cf1be780fdbf3d3872c2f13dac Mon Sep 17 00:00:00 2001 From: Jack Yuan Date: Tue, 11 May 2021 04:00:05 -0500 Subject: [PATCH 16/77] changed to --- github-action-build.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/github-action-build.sh b/github-action-build.sh index b4cbf36..e56c014 100644 --- a/github-action-build.sh +++ b/github-action-build.sh @@ -101,9 +101,9 @@ EOL ciRepo=${ciURL##*/} ciPrefix=${ciURL%/*} ciOrg=${ciPrefix##*/} - # if [ $test_var == true ]; then - # echo "----TEST COMPLETE----" - # fi + if [ ${test_var} != false ]; then + echo "----TEST COMPLETE----" + fi # TODO: try ${ secret.GITHUB_TOKEN } / double braces? if [ "${ github.secret.github_token}" != true ]; then echo "No deploy -- secure environment variables not available" From ee76878765f206f1f459a641aa71e769a6947f8b Mon Sep 17 00:00:00 2001 From: Jack Yuan Date: Tue, 11 May 2021 04:07:56 -0500 Subject: [PATCH 17/77] added quotation marks --- github-action-build.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/github-action-build.sh b/github-action-build.sh index e56c014..d520245 100644 --- a/github-action-build.sh +++ b/github-action-build.sh @@ -101,16 +101,16 @@ EOL ciRepo=${ciURL##*/} ciPrefix=${ciURL%/*} ciOrg=${ciPrefix##*/} - if [ ${test_var} != false ]; then + if [ "${test_var}" != false ]; then echo "----TEST COMPLETE----" fi # TODO: try ${ secret.GITHUB_TOKEN } / double braces? - if [ "${ github.secret.github_token}" != true ]; then + if [ "${secret.GITHUB_TOKEN}" != true ]; then echo "No deploy -- secure environment variables not available" - elif [ ${github.event.number} != false ]; then + elif [ "${github.event.number}" != false ]; then echo "No deploy -- pull request detected" - elif [ ${github.repository} != "$ciOrg/$ciRepo" ]; then - echo "No deploy -- repository fork: ${github.repository} != $ciOrg/$ciRepo" + elif [ "${github.repository}" != "$ciOrg/$ciRepo" ]; then + echo "No deploy -- repository fork: "${github.repository}"" != $ciOrg/$ciRepo" # TODO: Detect travis-ci.org versus travis-ci.com? else echo "All checks passed for artifact deployment" @@ -143,7 +143,7 @@ EOL # Run the build. BUILD_ARGS='-B -Djdk.tls.client.protocols="TLSv1,TLSv1.1,TLSv1.2"' - if [ "$deployOK" -a ${github.head_ref} = master ]; then + if [ "$deployOK" -a "${github.head_ref}"" = master ]; then echo echo "== Building and deploying master SNAPSHOT ==" mvn -Pdeploy-to-scijava $BUILD_ARGS deploy From cd5312e0369461df14cc4f48f2e6c465ab67aad0 Mon Sep 17 00:00:00 2001 From: Jack Yuan Date: Tue, 11 May 2021 04:10:27 -0500 Subject: [PATCH 18/77] deleted errornous quotation mark --- github-action-build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github-action-build.sh b/github-action-build.sh index d520245..c04ebb5 100644 --- a/github-action-build.sh +++ b/github-action-build.sh @@ -143,7 +143,7 @@ EOL # Run the build. BUILD_ARGS='-B -Djdk.tls.client.protocols="TLSv1,TLSv1.1,TLSv1.2"' - if [ "$deployOK" -a "${github.head_ref}"" = master ]; then + if [ "$deployOK" -a "${github.head_ref}" = master ]; then echo echo "== Building and deploying master SNAPSHOT ==" mvn -Pdeploy-to-scijava $BUILD_ARGS deploy From 6ac10f53e62c80ff2cab0bf1b9b7df81c751d5c4 Mon Sep 17 00:00:00 2001 From: Jack Yuan Date: Tue, 11 May 2021 04:18:21 -0500 Subject: [PATCH 19/77] commit to refresh --- github-action-build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github-action-build.sh b/github-action-build.sh index c04ebb5..d33436d 100644 --- a/github-action-build.sh +++ b/github-action-build.sh @@ -143,7 +143,7 @@ EOL # Run the build. BUILD_ARGS='-B -Djdk.tls.client.protocols="TLSv1,TLSv1.1,TLSv1.2"' - if [ "$deployOK" -a "${github.head_ref}" = master ]; then + if [ "$deployOK" -a ${github.head_ref} = master ]; then echo echo "== Building and deploying master SNAPSHOT ==" mvn -Pdeploy-to-scijava $BUILD_ARGS deploy From 6e5c05b6fb7118a7c36b1fe0c49c619aacad8954 Mon Sep 17 00:00:00 2001 From: Jack Yuan Date: Tue, 11 May 2021 04:18:40 -0500 Subject: [PATCH 20/77] commit to refresh --- github-action-build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github-action-build.sh b/github-action-build.sh index d33436d..c04ebb5 100644 --- a/github-action-build.sh +++ b/github-action-build.sh @@ -143,7 +143,7 @@ EOL # Run the build. BUILD_ARGS='-B -Djdk.tls.client.protocols="TLSv1,TLSv1.1,TLSv1.2"' - if [ "$deployOK" -a ${github.head_ref} = master ]; then + if [ "$deployOK" -a "${github.head_ref}" = master ]; then echo echo "== Building and deploying master SNAPSHOT ==" mvn -Pdeploy-to-scijava $BUILD_ARGS deploy From 15d59463e2752f12382fa7464ed78a637817eb58 Mon Sep 17 00:00:00 2001 From: Jack Yuan Date: Tue, 11 May 2021 04:21:40 -0500 Subject: [PATCH 21/77] fixed addition quotation mark --- github-action-build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github-action-build.sh b/github-action-build.sh index c04ebb5..27c2d0b 100644 --- a/github-action-build.sh +++ b/github-action-build.sh @@ -110,7 +110,7 @@ EOL elif [ "${github.event.number}" != false ]; then echo "No deploy -- pull request detected" elif [ "${github.repository}" != "$ciOrg/$ciRepo" ]; then - echo "No deploy -- repository fork: "${github.repository}"" != $ciOrg/$ciRepo" + echo "No deploy -- repository fork: "${github.repository}" != $ciOrg/$ciRepo" # TODO: Detect travis-ci.org versus travis-ci.com? else echo "All checks passed for artifact deployment" From bda81c6f43deba8ef735c9582ba228e99f66c891 Mon Sep 17 00:00:00 2001 From: Jack Yuan Date: Tue, 11 May 2021 04:27:34 -0500 Subject: [PATCH 22/77] restore changes --- github-action-build.sh | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/github-action-build.sh b/github-action-build.sh index 27c2d0b..ee36bd6 100644 --- a/github-action-build.sh +++ b/github-action-build.sh @@ -56,7 +56,6 @@ EOL # NB: Use maven.scijava.org instead of Central if defined in repositories. # This hopefully avoids intermittent "ReasonPhrase:Forbidden" errors # when the Travis build pings Maven Central; see travis-ci/travis-ci#6593. - # TODO: Try removing and see if error comes up grep -A 2 '' pom.xml | grep -q 'maven.scijava.org' && cat >>"$settingsFile" < @@ -101,16 +100,12 @@ EOL ciRepo=${ciURL##*/} ciPrefix=${ciURL%/*} ciOrg=${ciPrefix##*/} - if [ "${test_var}" != false ]; then - echo "----TEST COMPLETE----" - fi - # TODO: try ${ secret.GITHUB_TOKEN } / double braces? - if [ "${secret.GITHUB_TOKEN}" != true ]; then + if [ "${github.secret.github_token}" != true ]; then echo "No deploy -- secure environment variables not available" elif [ "${github.event.number}" != false ]; then echo "No deploy -- pull request detected" elif [ "${github.repository}" != "$ciOrg/$ciRepo" ]; then - echo "No deploy -- repository fork: "${github.repository}" != $ciOrg/$ciRepo" + echo "No deploy -- repository fork: ${github.repository} != $ciOrg/$ciRepo" # TODO: Detect travis-ci.org versus travis-ci.com? else echo "All checks passed for artifact deployment" From cc7e39d67ceb2749e906b28f916ce09fd4a3bc07 Mon Sep 17 00:00:00 2001 From: Jack Yuan Date: Tue, 11 May 2021 04:31:59 -0500 Subject: [PATCH 23/77] readded test codes --- github-action-build.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/github-action-build.sh b/github-action-build.sh index ee36bd6..96e25f3 100644 --- a/github-action-build.sh +++ b/github-action-build.sh @@ -100,6 +100,9 @@ EOL ciRepo=${ciURL##*/} ciPrefix=${ciURL%/*} ciOrg=${ciPrefix##*/} + if [ "${test_var}" == true ]; then + echo "----TEST COMPLETE----" + # TODO: try ${ secret.GITHUB_TOKEN } / double braces? if [ "${github.secret.github_token}" != true ]; then echo "No deploy -- secure environment variables not available" elif [ "${github.event.number}" != false ]; then From de0782bc971febf501f6caa4a0265c56fdc34c11 Mon Sep 17 00:00:00 2001 From: Jack Yuan Date: Tue, 11 May 2021 04:34:17 -0500 Subject: [PATCH 24/77] added fi --- github-action-build.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/github-action-build.sh b/github-action-build.sh index 96e25f3..6a8fd9f 100644 --- a/github-action-build.sh +++ b/github-action-build.sh @@ -102,6 +102,7 @@ EOL ciOrg=${ciPrefix##*/} if [ "${test_var}" == true ]; then echo "----TEST COMPLETE----" + fi # TODO: try ${ secret.GITHUB_TOKEN } / double braces? if [ "${github.secret.github_token}" != true ]; then echo "No deploy -- secure environment variables not available" From 954219874f3f7ccf4d39529a180368bc50e9b6f3 Mon Sep 17 00:00:00 2001 From: Jack Yuan Date: Tue, 11 May 2021 05:03:44 -0500 Subject: [PATCH 25/77] test 15 --- github-action-build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github-action-build.sh b/github-action-build.sh index 6a8fd9f..de3d6f9 100644 --- a/github-action-build.sh +++ b/github-action-build.sh @@ -100,7 +100,7 @@ EOL ciRepo=${ciURL##*/} ciPrefix=${ciURL%/*} ciOrg=${ciPrefix##*/} - if [ "${test_var}" == true ]; then + if [ "${test_var}" = true ]; then echo "----TEST COMPLETE----" fi # TODO: try ${ secret.GITHUB_TOKEN } / double braces? From c88691882914d9906ebc97c3975bd3c99ef0dc1b Mon Sep 17 00:00:00 2001 From: Jack Yuan Date: Tue, 11 May 2021 05:25:36 -0500 Subject: [PATCH 26/77] test 16 --- github-action-build.sh | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/github-action-build.sh b/github-action-build.sh index de3d6f9..d3a3a51 100644 --- a/github-action-build.sh +++ b/github-action-build.sh @@ -100,16 +100,13 @@ EOL ciRepo=${ciURL##*/} ciPrefix=${ciURL%/*} ciOrg=${ciPrefix##*/} - if [ "${test_var}" = true ]; then - echo "----TEST COMPLETE----" - fi # TODO: try ${ secret.GITHUB_TOKEN } / double braces? - if [ "${github.secret.github_token}" != true ]; then + if [ "${secure_env}" != true ]; then echo "No deploy -- secure environment variables not available" - elif [ "${github.event.number}" != false ]; then + elif [ "${pull_request}" != false ]; then echo "No deploy -- pull request detected" - elif [ "${github.repository}" != "$ciOrg/$ciRepo" ]; then - echo "No deploy -- repository fork: ${github.repository} != $ciOrg/$ciRepo" + elif [ "${repo_fork}" != "$ciOrg/$ciRepo" ]; then + echo "No deploy -- repository fork: ${repo_fork}} != $ciOrg/$ciRepo" # TODO: Detect travis-ci.org versus travis-ci.com? else echo "All checks passed for artifact deployment" @@ -118,7 +115,7 @@ EOL fi # Install GPG on OSX/macOS - if [ "${runner.os}" = 'macOS' ]; then + if [ "${runner_os}" = 'macOS' ]; then HOMEBREW_NO_AUTO_UPDATE=1 brew install gnupg2 fi @@ -142,7 +139,7 @@ EOL # Run the build. BUILD_ARGS='-B -Djdk.tls.client.protocols="TLSv1,TLSv1.1,TLSv1.2"' - if [ "$deployOK" -a "${github.head_ref}" = master ]; then + if [ "$deployOK" -a "${git_branch}" = master ]; then echo echo "== Building and deploying master SNAPSHOT ==" mvn -Pdeploy-to-scijava $BUILD_ARGS deploy @@ -180,7 +177,7 @@ if [ -f environment.yml ]; then if [ ! -f "$condaSh" ]; then echo echo "== Installing conda ==" - if [ "${matrix.python-version}" = "2.7" ]; then + 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 From a95e4de37dc0880aca33f4fdac47459df58bb793 Mon Sep 17 00:00:00 2001 From: Jack Yuan Date: Tue, 11 May 2021 08:42:46 -0500 Subject: [PATCH 27/77] test pr and repo fork --- github-action-build.sh | 34 +++++++++++---------- github-actionify.sh | 68 +++++++++++++++++++++--------------------- 2 files changed, 52 insertions(+), 50 deletions(-) diff --git a/github-action-build.sh b/github-action-build.sh index d3a3a51..08cddb6 100644 --- a/github-action-build.sh +++ b/github-action-build.sh @@ -53,20 +53,20 @@ if [ -f pom.xml ]; then EOL - # NB: Use maven.scijava.org instead of Central if defined in repositories. - # This hopefully avoids intermittent "ReasonPhrase:Forbidden" errors - # when the Travis build pings Maven Central; see travis-ci/travis-ci#6593. - grep -A 2 '' pom.xml | grep -q 'maven.scijava.org' && - cat >>"$settingsFile" < - - scijava-mirror - SciJava mirror - https://maven.scijava.org/content/groups/public/ - central - - -EOL +# # NB: Use maven.scijava.org instead of Central if defined in repositories. +# # This hopefully avoids intermittent "ReasonPhrase:Forbidden" errors +# # when the Travis build pings Maven Central; see travis-ci/travis-ci#6593. +# grep -A 2 '' pom.xml | grep -q 'maven.scijava.org' && +# cat >>"$settingsFile" < +# +# scijava-mirror +# SciJava mirror +# https://maven.scijava.org/content/groups/public/ +# central +# +# +# EOL cat >>"$settingsFile" < @@ -103,9 +103,11 @@ EOL # TODO: try ${ secret.GITHUB_TOKEN } / double braces? if [ "${secure_env}" != true ]; then echo "No deploy -- secure environment variables not available" - elif [ "${pull_request}" != false ]; then + fi + if [ "${pull_request}" != false ]; then echo "No deploy -- pull request detected" - elif [ "${repo_fork}" != "$ciOrg/$ciRepo" ]; then + fi + if [ "${repo_fork}" != "$ciOrg/$ciRepo" ]; then echo "No deploy -- repository fork: ${repo_fork}} != $ciOrg/$ciRepo" # TODO: Detect travis-ci.org versus travis-ci.com? else diff --git a/github-actionify.sh b/github-actionify.sh index 87e4ab2..33cd340 100644 --- a/github-actionify.sh +++ b/github-actionify.sh @@ -2,23 +2,23 @@ # travisify.sh # -# Script for enabling or updating Travis CI builds for a given repository. +# Script for enabling or updating GitHub Action builds for a given repository. #set -e dir="$(dirname "$0")" -travisDir=.travis -travisConfig=.travis.yml -travisBuildScript=$travisDir/build.sh -travisSettingsFile=$travisDir/settings.xml -travisNotifyScript=$travisDir/notify.sh +gitactionDir=.github +gitactionConfig=.gitaction.yml +gitactionBuildScript=$gitactionDir/build.sh +gitactionSettingsFile=$gitactionDir/settings.xml +gitactionNotifyScript=$gitactionDir/notify.sh credentialsDir=$HOME/.scijava/credentials varsFile=$credentialsDir/vars signingKeySourceFile=$credentialsDir/scijava-ci-signing.asc -signingKeyDestFile=$travisDir/signingkey.asc +signingKeyDestFile=$gitactionDir/signingkey.asc pomMinVersion='17.1.1' -tmpFile=travisify.tmp +tmpFile=gitaction.tmp info() { echo "- $@"; } warn() { echo "[WARNING] $@" 1>&2; } @@ -42,7 +42,7 @@ update() { file=$1 msg=$2 exe=$3 - test "$msg" || msg="Travis: update $file" + test "$msg" || msg="GitHub Action: update $file" if [ -e "$file" ] then if diff -q "$file" "$tmpFile" >/dev/null @@ -71,7 +71,7 @@ update() { process() { cd "$1" - # -- Git sanity checks -- + # -- GitHub Action sanity checks -- repoSlug=$(xmllint --xpath '//*[local-name()="project"]/*[local-name()="scm"]/*[local-name()="connection"]' pom.xml|sed 's_.*github.com[:/]\(.*\)<.*_\1_') test "$repoSlug" && info "Repository = $repoSlug" || die 'Could not determine GitHub repository slug' @@ -112,16 +112,16 @@ process() { *) die "Unsupported domain: $domain";; esac - # -- Travis sanity checks -- + # -- GitHub Action sanity checks -- - test -e "$travisDir" -a ! -d "$travisDir" && die "$travisDir is not a directory" - test -e "$travisConfig" -a ! -f "$travisConfig" && die "$travisConfig is not a regular file" - test -e "$travisConfig" && warn "$travisConfig already exists" - test -e "$travisBuildScript" && warn "$travisBuildScript already exists" + test -e "$gitactionDir" -a ! -d "$gitactionDir" && die "$gitactionDir is not a directory" + test -e "$gitactionConfig" -a ! -f "$gitactionConfig" && die "$gitactionConfig is not a regular file" + test -e "$gitactionConfig" && warn "$gitactionConfig already exists" + test -e "$gitactionBuildScript" && warn "$gitactionBuildScript already exists" # -- Do things -- - # Add/update the Travis configuration file. + # Add/update the GitHun Actions configuration file. cat >"$tmpFile" <"$tmpFile" < Date: Mon, 17 May 2021 13:04:22 -0500 Subject: [PATCH 28/77] test --- github-action-build.sh | 9 ++- github-actionify.sh | 1 + github-javadoc.sh | 127 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 github-javadoc.sh diff --git a/github-action-build.sh b/github-action-build.sh index 08cddb6..505c608 100644 --- a/github-action-build.sh +++ b/github-action-build.sh @@ -100,16 +100,21 @@ EOL ciRepo=${ciURL##*/} ciPrefix=${ciURL%/*} ciOrg=${ciPrefix##*/} - # TODO: try ${ secret.GITHUB_TOKEN } / double braces? + # https://docs.github.com/en/actions/reference/encrypted-secrets if [ "${secure_env}" != true ]; then echo "No deploy -- secure environment variables not available" + echo ${secure_env} + echo ${pull_request} + echo ${repo_fork} + echo ${runner_os} + echo ${git_branch} + echo ${python_version} fi if [ "${pull_request}" != false ]; then echo "No deploy -- pull request detected" fi if [ "${repo_fork}" != "$ciOrg/$ciRepo" ]; then echo "No deploy -- repository fork: ${repo_fork}} != $ciOrg/$ciRepo" - # TODO: Detect travis-ci.org versus travis-ci.com? else echo "All checks passed for artifact deployment" deployOK=1 diff --git a/github-actionify.sh b/github-actionify.sh index 33cd340..38f5c0f 100644 --- a/github-actionify.sh +++ b/github-actionify.sh @@ -101,6 +101,7 @@ process() { die "Not pom-scijava parent: $parent. Run with -p flag to skip this check." fi + # https://docs.github.com/en/actions/managing-workflow-runs/adding-a-workflow-status-badge domain=$(grep "travis-ci\.[a-z]*/$repoSlug" pom.xml 2>/dev/null | sed 's/.*\(travis-ci\.[a-z]*\).*/\1/') test "$domain" && info "Detected domain from pom.xml: $domain" || diff --git a/github-javadoc.sh b/github-javadoc.sh new file mode 100644 index 0000000..7badbcb --- /dev/null +++ b/github-javadoc.sh @@ -0,0 +1,127 @@ +#!/bin/bash + +# +# travis-javadoc.sh - A script to build the javadocs of a SciJava-based project. +# + +# The following repositories are known to use this script: +# +# bonej-org/bonej-javadoc +# fiji/fiji-javadoc +# imagej/imagej-javadoc +# imglib/imglib2-javadoc +# scifio/scifio-javadoc +# scijava/java3d-javadoc +# scijava/scijava-javadoc +# slim-curve/slim-javadoc +# uw-loci/loci-javadoc + +# Wait for a launched background command to complete, emitting +# an occasional message to avoid long periods without output. +# Return the same exit code as the launched command. +keep_alive() { + pid="$1" + if [ "$pid" = "" ] + then + echo "[ERROR] No PID given" + return + fi + i=0 + while kill -0 "$pid" 2>/dev/null; do + i=$((i+1)) + m=$((i/60)) + s=$((i%60)) + test $s -eq 0 && echo "[$m minutes elapsed]" + sleep 1 + done + wait "$pid" +} + +if [ "$TRAVIS_SECURE_ENV_VARS" = true \ + -a "$TRAVIS_PULL_REQUEST" = false \ + -a "$TRAVIS_BRANCH" = master ] +then + project=$1 + openssl_key=$2 + openssl_iv=$3 + + # Populate the settings.xml configuration. + mkdir -p "$HOME/.m2" + settingsFile="$HOME/.m2/settings.xml" + customSettings=.travis/settings.xml + if [ -f "$customSettings" ] + then + cp "$customSettings" "$settingsFile" + else + # NB: Use maven.scijava.org as sole mirror if defined in . + # This hopefully avoids intermittent "ReasonPhrase:Forbidden" errors + # when the Travis build pings Maven Central; see travis-ci/travis-ci#6593. + test -f pom.xml && grep -A 2 '' pom.xml | grep -q 'maven.scijava.org' && + cat >"$settingsFile" < + + + scijava-mirror + SciJava mirror + https://maven.scijava.org/content/groups/public/ + * + + + +EOL + fi + + # Emit some details useful for debugging. + # NB: We run once with -q to suppress the download messages, + # then again without it to emit the desired dependency tree. + mvn -B -q dependency:tree && + mvn -B dependency:tree && + + echo && + echo "== Generating javadoc ==" && + + # Build the javadocs. + (mvn -B -q -Pbuild-javadoc) & + keep_alive $! && + test -d target/apidocs && + # Strip out date stamps, to avoid spurious changes being committed. + sed -i'' -e '/\( Artifact to invalidate = $ga" && echo "machine maven.scijava.org" >"$HOME/.netrc" && - echo " login scijava-ci" >>"$HOME/.netrc" && + echo " login $MAVEN_USER" >>"$HOME/.netrc" && echo " password $MAVEN_PASS" >>"$HOME/.netrc" && sh maven-helper.sh invalidate-cache "$ga" checkSuccess $? From 60e4371790b58ee6dd2e7e865601e0d91ce9de20 Mon Sep 17 00:00:00 2001 From: Mark Hiner Date: Thu, 24 Jun 2021 13:28:00 -0500 Subject: [PATCH 75/77] Fix settings file creation Need to put variable values, not references, in the settings.xml. --- github-action-build.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/github-action-build.sh b/github-action-build.sh index 658ce93..04fb604 100644 --- a/github-action-build.sh +++ b/github-action-build.sh @@ -38,18 +38,18 @@ if [ -f pom.xml ]; then scijava.releases - \$MAVEN_USER - \$MAVEN_PASS + $MAVEN_USER + $MAVEN_PASS scijava.snapshots - \$MAVEN_USER - \$MAVEN_PASS + $MAVEN_USER + $MAVEN_PASS sonatype-nexus-releases scijava-ci - \$OSSRH_PASS + $OSSRH_PASS EOL @@ -59,12 +59,12 @@ EOL gpg - \$HOME/.gnupg + $HOME/.gnupg - \$GPG_KEY_NAME - \$GPG_PASSPHRASE + $GPG_KEY_NAME + $GPG_PASSPHRASE From 7f218b42e939ea908bcdcb60649a48e691f7a2f8 Mon Sep 17 00:00:00 2001 From: Mark Hiner Date: Thu, 24 Jun 2021 14:09:56 -0500 Subject: [PATCH 76/77] Restore fork detection --- github-action-build.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/github-action-build.sh b/github-action-build.sh index 04fb604..90c1ad7 100644 --- a/github-action-build.sh +++ b/github-action-build.sh @@ -81,8 +81,13 @@ EOL 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 [ "${GITHUB_REPOSITORY}" != "$ciOrg/$ciRepo" ]; then + echo "No deploy -- repository fork: ${GITHUB_REPOSITORY} != $ciOrg/$ciRepo" else echo "All checks passed for artifact deployment" deployOK=1 From fe4f3ed06a4cedc77139af63e3e10cc932b181d9 Mon Sep 17 00:00:00 2001 From: Mark Hiner Date: Mon, 28 Jun 2021 13:52:17 -0500 Subject: [PATCH 77/77] Split out CI-dependent build code --- github-action-build.sh => ci-build.sh | 21 +++++++++++++-------- github-action-ci.sh | 11 +++++++++++ github-actionify.sh | 19 +++++++++++++++++-- 3 files changed, 41 insertions(+), 10 deletions(-) rename github-action-build.sh => ci-build.sh (89%) mode change 100644 => 100755 create mode 100755 github-action-ci.sh mode change 100644 => 100755 github-actionify.sh diff --git a/github-action-build.sh b/ci-build.sh old mode 100644 new mode 100755 similarity index 89% rename from github-action-build.sh rename to ci-build.sh index 90c1ad7..93a5392 --- a/github-action-build.sh +++ b/ci-build.sh @@ -1,9 +1,13 @@ #!/bin/bash # -# github-action-build.sh - A script to build and/or release SciJava-based projects -# automatically using GitHub Actions. +# 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")" @@ -29,7 +33,7 @@ if [ -f pom.xml ]; then # Populate the settings.xml configuration. mkdir -p "$HOME/.m2" settingsFile="$HOME/.m2/settings.xml" - customSettings=.github/settings.xml + customSettings=.ci/settings.xml if [ -f "$customSettings" ]; then cp "$customSettings" "$settingsFile" else @@ -86,8 +90,8 @@ EOL ciOrg=${ciPrefix##*/} if [ ! "$SIGNING_ASC" ] || [ ! "$GPG_KEY_NAME" ] || [ ! "$GPG_PASSPHRASE" ] || [ ! "$MAVEN_PASS" ] || [ ! "$OSSRH_PASS" ]; then echo "No deploy -- secure environment variables not available" - elif [ "${GITHUB_REPOSITORY}" != "$ciOrg/$ciRepo" ]; then - echo "No deploy -- repository fork: ${GITHUB_REPOSITORY} != $ciOrg/$ciRepo" + 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 @@ -95,14 +99,15 @@ EOL fi # Install GPG on OSX/macOS - if [ ${RUNNER_OS} = 'macOS' ]; then + if [ $BUILD_OS = 'macOS' ]; then HOMEBREW_NO_AUTO_UPDATE=1 brew install gnupg2 fi # Import the GPG signing key. - keyFile=.github/signingkey.asc + 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" @@ -171,7 +176,7 @@ if [ -f environment.yml ]; then echo echo "== Configuring environment ==" - condaEnv=github-scijava + condaEnv=ci-scijava test -d "$condaDir/envs/$condaEnv" && condaAction=update || condaAction=create conda env "$condaAction" -n "$condaEnv" -f environment.yml && conda activate "$condaEnv" diff --git a/github-action-ci.sh b/github-action-ci.sh new file mode 100755 index 0000000..e368959 --- /dev/null +++ b/github-action-ci.sh @@ -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 diff --git a/github-actionify.sh b/github-actionify.sh old mode 100644 new mode 100755 index 626a4f3..37fc436 --- a/github-actionify.sh +++ b/github-actionify.sh @@ -17,6 +17,7 @@ gitactionDir=.github gitactionConfigRoot=/workflows/.gitaction.yml gitactionConfig=$gitactionDir$gitactionConfigRoot gitactionPRConfig=$gitactionDir/workflows/.gitaction-pr.yml +gitactionSetupScript=$gitactionDir/setup.sh gitactionBuildScript=$gitactionDir/build.sh gitactionSettingsFile=$gitactionDir/settings.xml gitactionNotifyScript=$gitactionDir/notify.sh @@ -118,6 +119,7 @@ process() { test -e "$gitactionPRConfig" -a ! -f "$gitactionPRConfig" && die "$gitactionPRConfig is not a regular file" test -e "$gitactionConfig" && warn "$gitactionConfig already exists" test -e "$gitactionBuildScript" && warn "$gitactionBuildScript already exists" + test -e "$gitactionSetupScript" && warn "$gitactionSetupScript already exists" # -- Do things -- @@ -154,6 +156,8 @@ jobs: with: java-version: '8' distribution: 'zulu' + - name: Set up CI environment + run: ./$gitactionSetupScript - name: Build with Maven run: ./$gitactionBuildScript env: @@ -199,16 +203,27 @@ jobs: with: java-version: '8' distribution: 'zulu' + - name: Set up CI environment + run: ./$gitactionSetupScript - name: Build with Maven run: ./$gitactionBuildScript EOL update "$gitactionPRConfig" + # Add/update the GitHub Action setup script. + cat >"$tmpFile" <"$tmpFile" <