<commit_before>#!/bin/bash

# Get secrets from keystore and set and environment variables.
setup_environment_secrets() {
  export SONATYPE_USERNAME=functions-framework-release-bot
  export SONATYPE_PASSWORD=$(cat ${KOKORO_KEYSTORE_DIR}/75669_functions-framework-java-release-bot-sonatype-password)
  export GPG_PASSPHRASE=$(cat ${KOKORO_KEYSTORE_DIR}/75669_functions-framework-java-release-bot-gpg-passphrase)

  # Add the keybox file to $GNUPGHOME to verify the GPG credentials.
  export GNUPGHOME=/tmp/gpg
  mkdir $GNUPGHOME
  mv ${KOKORO_KEYSTORE_DIR}/75669_functions-framework-java-release-bot-gpg-pubring $GNUPGHOME/pubring.kbx
  # Restart the gpg-agent to avoid the error of no default secret key.
  gpg -k
}

create_settings_xml_file() {
  echo "<settings>
   <profiles>
     <profile>
         <activation>
             <activeByDefault>true</activeByDefault>
         </activation>
         <properties>
             <gpg.passphrase>${GPG_PASSPHRASE}</gpg.passphrase>
         </properties>
     </profile>
  </profiles>
  <servers>
    <server>
      <id>sonatype-nexus-staging</id>
      <username>${SONATYPE_USERNAME}</username>
      <password>${<PASSWORD>}</password>
    </server>
    <server>
      <id>sonatype-nexus-snapshots</id>
      <username>${SONATYPE_USERNAME}</username>
      <password>${<PASSWORD>}</password>
    </server>
  </servers>
</settings>" > $1
}

setup_environment_secrets

# Pick the right package to release based on the Kokoro job name.
cd ${KOKORO_ARTIFACTS_DIR}/github/functions-framework-java
create_settings_xml_file "settings.xml"
echo "KOKORO_JOB_NAME=${KOKORO_JOB_NAME}"
if [[ $KOKORO_JOB_NAME == *"function-maven-plugin"* ]]; then
  cd function-maven-plugin
elif [[ $KOKORO_JOB_NAME == *"functions-framework-api"* ]]; then
  cd functions-framework-api
else
  cd invoker
fi
echo "pwd=$(pwd)"

# Make sure `JAVA_HOME` is set and using jdk11.
export JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64
echo "JAVA_HOME=$JAVA_HOME"
mvn clean deploy -B \
  -P sonatype-oss-release \
  --settings=../settings.xml \
  -Dgpg.executable=gpg \
  -Dgpg.passphrase=${GPG_PASSPHRASE} \
  -Dgpg.homedir=${GNUPGHOME}<commit_msg>chore: use gpg2 to sign the packages (#160)<commit_after>#!/bin/bash

# Stop execution when any command fails.
set -e

# Get secrets from keystore and set and environment variables.
setup_environment_secrets() {
  export SONATYPE_USERNAME=functions-framework-release-bot
  export SONATYPE_PASSWORD=$(cat ${KOKORO_KEYSTORE_DIR}/75669_functions-framework-java-release-bot-sonatype-password)
  export GPG_PASSPHRASE=$(cat ${KOKORO_KEYSTORE_DIR}/75669_functions-framework-java-release-bot-gpg-passphrase)

  # Add the keybox file to $GNUPGHOME to verify the GPG credentials.
  export GNUPGHOME=/tmp/gpg
  mkdir $GNUPGHOME
  mv ${KOKORO_KEYSTORE_DIR}/75669_functions-framework-java-release-bot-gpg-pubring $GNUPGHOME/pubring.kbx
  # Restart the gpg-agent to avoid the error of no default secret key.
  gpg2 -k
}

create_settings_xml_file() {
  echo "<settings>
   <profiles>
     <profile>
         <activation>
             <activeByDefault>true</activeByDefault>
         </activation>
         <properties>
             <gpg.passphrase>${GPG_PASSPHRASE}</gpg.passphrase>
         </properties>
     </profile>
  </profiles>
  <servers>
    <server>
      <id>sonatype-nexus-staging</id>
      <username>${SONATYPE_USERNAME}</username>
      <password>${<PASSWORD>}</password>
    </server>
    <server>
      <id>sonatype-nexus-snapshots</id>
      <username>${SONATYPE_USERNAME}</username>
      <password>${<PASSWORD>}</password>
    </server>
  </servers>
</settings>" > $1
}

setup_environment_secrets

# Pick the right package to release based on the Kokoro job name.
cd ${KOKORO_ARTIFACTS_DIR}/github/functions-framework-java
create_settings_xml_file "settings.xml"
echo "KOKORO_JOB_NAME=${KOKORO_JOB_NAME}"
if [[ $KOKORO_JOB_NAME == *"function-maven-plugin"* ]]; then
  cd function-maven-plugin
elif [[ $KOKORO_JOB_NAME == *"functions-framework-api"* ]]; then
  cd functions-framework-api
else
  cd invoker
fi
echo "pwd=$(pwd)"

# Make sure `JAVA_HOME` is set and using jdk11.
export JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64
echo "JAVA_HOME=$JAVA_HOME"
mvn clean deploy -B \
  -P sonatype-oss-release \
  --settings=../settings.xml \
  -Dgpg.executable=gpg2 \
  -Dgpg.passphrase=${GPG_PASSPHRASE} \
  -Dgpg.homedir=${GNUPGHOME}
{'fraction_non_alphanumeric': 0.1320754716981132, 'fraction_numerical': 0.012275517162991589, 'mean_word_length': 3.954954954954955, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4508212', 'n_tokens_mistral': 1657, 'n_tokens_neox': 1585, 'n_words': 288}