Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jpgarcia committed Aug 26, 2022
0 parents commit 9367c57
Show file tree
Hide file tree
Showing 14 changed files with 4,446 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist/**/*
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn commitlint --edit "${1}"
41 changes: 41 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"branches": [
"main",
{
"name": "beta",
"channel": "beta",
"prerelease": true
}
],
"tagFormat": "${version}",
"plugins": [
[
"@semantic-release/exec",
{
"prepareCmd": "./build-nitro-cli.sh"
}
],
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
[
"@semantic-release/npm",
{
"npmPublish": false
}
],
[
"@semantic-release/git",
{
"assets": ["package.json", "yarn.lock", "README.md", "CHANGELOG.md"],
"message": "chore(release): bump version to ${nextRelease.version}[skip ci]\n\n${nextRelease.notes}"
}
],
[
"@semantic-release/github",
{
"assets": ["dist/**"]
}
]
]
}
1 change: 1 addition & 0 deletions .yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
save-prefix ""
Empty file added CHANGELOG.md
Empty file.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2022 Underscope SRL

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Empty file added README.md
Empty file.
39 changes: 39 additions & 0 deletions bitrise.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
format_version: "4"
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"
project_type: ""
app:
envs:
- BITRISE_STEP_ID: nitro-android
- BITRISE_STEP_GIT_CLONE_URL: "https://github.com/underscopeio/bitrise-step-nitro-android.git"
meta:
bitrise.io:
stack: linux-docker-android-20.04
workflows:
release:
steps:
- activate-ssh-key@4:
run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
- git-clone@6: {}
- nvm@1:
run_if: .IsCI
inputs:
- node_version: "16"
- cache-pull@2: {}
- yarn@0:
inputs:
- cache_local_deps: "yes"
- command: install
- cache-push@2:
inputs:
- compress_archive: "true"
- git::https://github.com/bitrise-steplib/steps-readme-generator.git@main:
title: Generate README
- yarn@0:
inputs:
- command: semantic-release
trigger_map:
- push_branch: main
workflow: release
- push_branch: beta
workflow: release
46 changes: 46 additions & 0 deletions build-nitro-cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CREATE_TMP_DIR_CMD=$([[ "$(uname)" == "Darwin" ]] && echo "mktemp -d -t nitro" || echo "mktemp -d -t")
TMP_DIR=$($CREATE_TMP_DIR_CMD)
NITRO_SOURCE_DIR="$SCRIPT_DIR/node_modules/nitro"
NITRO_SOURCE_TMP_DIR="$TMP_DIR/nitro"
NITRO_CLI_TMP_DIR="$NITRO_SOURCE_TMP_DIR/packages/cli"

cp -R "$NITRO_SOURCE_DIR" "$TMP_DIR"

# Install Nitro dependencies
cd "$NITRO_SOURCE_TMP_DIR"
yarn

# Update default configuration
default_config_path="$NITRO_CLI_TMP_DIR/src/config/default.ts"

if [[ -n ${NITRO_API_HOST} ]]; then
sed -i'' 's,\(apiHost:\).*,\1 '\'"$NITRO_API_HOST"\'\\,',g' "$default_config_path"
fi
if [[ -n ${NITRO_AWS_ACCESS_KEY_ID} ]]; then
sed -i'' 's,\(awsS3AccessKeyId:\).*,\1 '\'"$NITRO_AWS_ACCESS_KEY_ID"\'\\,',g' "$default_config_path"
fi
if [[ -n ${NITRO_AWS_SECRET_ACCESS_KEY} ]]; then
sed -i'' 's,\(awsS3SecretAccessKey:\).*,\1 '\'"$NITRO_AWS_SECRET_ACCESS_KEY"\'\\,',g' "$default_config_path"
fi
if [[ -n ${NITRO_AWS_S3_REGION} ]]; then
sed -i'' 's,\(awsS3Region:\).*,\1 '\'"$NITRO_AWS_S3_REGION"\'\\,',g' "$default_config_path"
fi
if [[ -n ${NITRO_AWS_S3_BUCKET} ]]; then
sed -i'' 's,\(awsS3Bucket:\).*,\1 '\'"$NITRO_AWS_S3_BUCKET"\'\\,',g' "$default_config_path"
fi

# Build Nitro cli
cd "$NITRO_CLI_TMP_DIR"
yarn dist

# Copy Nitro binaries to publish a new release
cd "$SCRIPT_DIR"
rm -rf "$SCRIPT_DIR/dist"
cp -R "$NITRO_CLI_TMP_DIR/dist" "$SCRIPT_DIR"

# Remove temp dir
rm -rf "$TMP_DIR"
12 changes: 12 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
extends: ["@commitlint/config-conventional"],
rules: {
"body-max-line-length": [1, "always", 200],
"footer-max-line-length": [1, "always", 200],
},
parserPreset: {
parserOpts: {
noteKeywords: ["\\[.+\\]:"],
},
},
};
24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "bitrise-step-nitro-android",
"version": "1.1.0",
"repository": "git@github.com:underscopeio/bitrise-step-nitro-android.git",
"author": "Juan Pablo Garcia <juanpablogarcia@gmail.com>",
"license": "MIT",
"scripts": {
"prepare": "husky install"
},
"dependencies": {
"@semantic-release/changelog": "6.0.1",
"@semantic-release/exec": "6.0.3",
"@semantic-release/git": "10.0.1",
"semantic-release": "19.0.5",
"nitro": "ssh://git@github.com:underscopeio/nitro.git#e4d25d0a688fb5a431f27eabb9d108ef32ddb846"
},
"devDependencies": {
"@commitlint/cli": "17.0.3",
"@commitlint/config-conventional": "17.0.3",
"husky": "8.0.1",
"prettier": "2.7.1",
"prettier-plugin-sh": "0.12.8"
}
}
174 changes: 174 additions & 0 deletions step.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
#!/bin/bash
set -e

# ----------------------
# Advanced configuration
# ----------------------

# shellcheck disable=SC2154
if [[ "${fail_safe}" == "true" || "${fail_safe}" == "yes" ]]; then
set +e
fi

# shellcheck disable=SC2154
if [[ "${debug}" == "true" || "${debug}" == "yes" ]]; then
set -x
fi

if [[ -n ${entry_file} ]]; then
export ENTRY_FILE="${entry_file}"
fi

# Obtain vm boot time
ps_command=$([[ "$(uname)" == "Darwin" ]] && echo "ps -eo lstart,command" || echo "ps -eo lstart,cmd")
date_command=$([[ "$(uname)" == "Darwin" ]] && echo "gdate" || echo "date")

bitrise_process_started_at=$(${ps_command} | grep "bitrise run" | grep -v grep | sed -e 's/^\(.\{24\}\).*/\1/' | head -1)
bitrise_process_started_at_ms=$(${date_command} -d "${bitrise_process_started_at:=$(date)}" "+%s%3N")

# Set environment variables
export NITRO_BOOTED_AT_TIMESTAMP="${bitrise_process_started_at_ms}"

# Build command arguments
args=("android")
args+=("--tracking-provider" "nitro-on-premise")

args+=("--build-id" "${BITRISE_BUILD_SLUG}")
args+=("--repo-path" "${BITRISE_SOURCE_DIR}")

# -------------------
# Basic configuration
# -------------------

if [[ -n ${root_directory} ]]; then
args+=("--root-directory" "${root_directory}")
fi

if [[ -n ${android_flavor} ]]; then
args+=("--android-flavor" "${android_flavor}")
fi

# --------------
# App Versioning
# --------------

if [[ -n ${version_name} ]]; then
args+=("--version-name" "${version_name}")
fi

if [[ -n ${version_code} ]]; then
args+=("--version-code" "${version_code}")
fi

# shellcheck disable=SC2154
if [[ "${disable_version_name_from_package_json}" == "true" || "${disable_version_name_from_package_json}" == "yes" ]]; then
args+=("--disable-version-name-from-package-json")
fi

# shellcheck disable=SC2154
if [[ "${disable_version_code_auto_generation}" == "true" || "${disable_version_code_auto_generation}" == "yes" ]]; then
args+=("--disable-version-code-auto-generation")
fi

# -----------
# App Signing
# -----------

if [[ -n ${android_keystore_url} ]]; then
args+=("--android-keystore-url" "${android_keystore_url}")
fi

if [[ -n ${android_keystore_password} ]]; then
args+=("--android-keystore-password" "${android_keystore_password}")
fi

if [[ -n ${android_keystore_key_alias} ]]; then
args+=("--android-keystore-key-alias" "${android_keystore_key_alias}")
fi

if [[ -n ${android_keystore_key_password} ]]; then
args+=("--android-keystore-key-password" "${android_keystore_key_password}")
fi

# -------
# Caching
# -------

if [[ -n ${cache_provider} ]]; then
args+=("--cache-provider" "${cache_provider}")
fi

# shellcheck disable=SC2154
if [[ "${disable_cache}" == "true" || "${disable_cache}" == "yes" ]]; then
args+=("--disable-cache")
fi

if [[ -n ${cache_env_var_lookup_keys} ]]; then
IFS='|' cache_env_var_lookup_keys_value=("${cache_env_var_lookup_keys}")
# shellcheck disable=SC2206
args+=("--cache-env-var-lookup-keys" ${cache_env_var_lookup_keys_value[@]})
fi

if [[ -n ${cache_file_lookup_paths} ]]; then
IFS='|' cache_file_lookup_paths_value=("${cache_file_lookup_paths}")
# shellcheck disable=SC2206
args+=("--cache-file-lookup-paths" ${cache_file_lookup_paths_value[@]})
fi

# shellcheck disable=SC2154
if [[ "${disable_metro_cache}" == "true" || "${disable_metro_cache}" == "yes" ]]; then
args+=("--disable-metro-cache")
fi

# -----
# Hooks
# -----

if [[ -n ${pre_install_command} ]]; then
args+=("--pre-install-command" "${pre_install_command}")
fi

if [[ -n ${pre_build_command} ]]; then
args+=("--pre-build-command" "${pre_build_command}")
fi

if [[ -n ${post_build_command} ]]; then
args+=("--post-build-command" "${post_build_command}")
fi

# -----
# Advanced
# -----

if [[ -n ${output_directory} ]]; then
args+=("--output-directory" "${output_directory}")
fi

# -------------------
# Nitro Cli execution
# -------------------

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BITRISE_STEP_VERSION=$(cat < "${SCRIPT_DIR}/package.json" | jq -r '.version')

MACOS_BIN_FILE="nitro-macos"
LINUX_BIN_FILE="nitro-linux"

BIN_FILE=$([[ "$(uname)" == "Darwin" ]] && echo "${MACOS_BIN_FILE}" || echo "${LINUX_BIN_FILE}")
BIN_FILE_PATH="${SCRIPT_DIR}/nitro"

# Download cli release
wget -q "https://github.com/underscopeio/bitrise-step-nitro-android/releases/download/${BITRISE_STEP_VERSION}/${BIN_FILE}" -O "${BIN_FILE_PATH}"
chmod +x "${BIN_FILE_PATH}"
${BIN_FILE_PATH} "${args[@]}"

exit_code=$?

if [[ exit_code -ne 0 ]]; then
echo "⚠️ Nitro has thrown a '${exit_code}' error code while running on fail-safe mode. You can check 'NITRO_BUILD_FAILED' value in further steps."
envman add --key "NITRO_BUILD_FAILED" --value "true"
envman add --key "NITRO_BUILD_STATUS" --value "failed"
else
envman add --key "NITRO_BUILD_FAILED" --value "false"
envman add --key "NITRO_BUILD_STATUS" --value "success"
fi
Loading

0 comments on commit 9367c57

Please sign in to comment.