1set -eux 2 3if [ "$GITHUB_REPOSITORY" == "google/dagger" ] && \ 4 [ "$GITHUB_EVENT_NAME" == "push" ] && \ 5 [ "$GITHUB_REF" == "refs/heads/master" ]; then 6 echo -e "Publishing javadoc...\n" 7 bazel build //:user-docs.jar 8 JAVADOC_JAR="$(pwd)/bazel-bin/user-docs.jar" 9 10 cd $HOME 11 git clone --quiet --branch=gh-pages https://x-access-token:${GH_TOKEN}@github.com/google/dagger gh-pages > /dev/null 12 13 cd gh-pages 14 git config --global user.email "[email protected]" 15 git config --global user.name "Dagger Team" 16 git rm -rf api/latest 17 mkdir -p api 18 unzip "$JAVADOC_JAR" -d api/latest 19 rm -rf api/latest/META-INF/ 20 git add -f api/latest 21 22 # Check if there are any changes before committing, otherwise attempting 23 # to commit will fail the build (https://stackoverflow.com/a/2659808). 24 if [[ $(git diff-index --quiet HEAD --) || $? == 1 ]]; then 25 # The exist status is 1, meaning there are changes to commit 26 git commit -m "Latest javadoc on successful Github build $GITHUB_WORKFLOW/$GITHUB_RUN_ID auto-pushed to gh-pages" 27 git push -fq origin gh-pages > /dev/null 28 echo -e "Published Javadoc to gh-pages.\n" 29 else 30 # The exist status is 0, meaning there are no changes to commit 31 echo -e "Skipping publishing docs since no changes were detected." 32 fi 33else 34 echo -e "Not publishing docs for branch=${$GITHUB_REF}" 35fi 36