270 lines
10 KiB
YAML
270 lines
10 KiB
YAML
name: inhouse-code-push-cli
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
environment:
|
|
description: 'Environment to deploy to (QA/Prod)'
|
|
required: true
|
|
type: choice
|
|
options:
|
|
- QA
|
|
- Prod
|
|
buildFlavor:
|
|
description: 'Build flavor (Field/Calling)'
|
|
required: true
|
|
type: choice
|
|
options:
|
|
- Field
|
|
- Calling
|
|
minTargetVersion:
|
|
description: 'Minimum target version'
|
|
required: true
|
|
type: string
|
|
maxTargetVersion:
|
|
description: 'Maximum target version'
|
|
required: true
|
|
type: string
|
|
description:
|
|
description: 'Update description'
|
|
required: true
|
|
type: string
|
|
|
|
jobs:
|
|
generate:
|
|
runs-on: [default]
|
|
outputs:
|
|
package_version: ${{ steps.get_version.outputs.version }}
|
|
build_number: ${{ steps.get_version.outputs.buildNumber }}
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v2
|
|
with:
|
|
token: ${{ secrets.MY_REPO_PAT }}
|
|
submodules: recursive
|
|
|
|
- name: Set Node.js 16.x
|
|
uses: actions/setup-node@v3
|
|
with:
|
|
node-version: 16.x
|
|
|
|
- name: Setup Nexus authentication
|
|
run: |
|
|
echo "@navi:registry=https://nexus.cmd.navi-tech.in/repository/navi-commons/" > .npmrc
|
|
echo "//nexus.cmd.navi-tech.in/repository/navi-commons/:_authToken=${{ secrets.NEXUS_AUTH_TOKEN }}" >> .npmrc
|
|
echo "@navi:registry=https://nexus.cmd.navi-tech.in/repository/npm-packages/" >> .npmrc
|
|
echo "//nexus.cmd.navi-tech.in/repository/npm-packages/:_authToken=${{ secrets.NEXUS_AUTH_TOKEN }}" >> .npmrc
|
|
|
|
- name: Get version from build flavor
|
|
id: get_version
|
|
run: |
|
|
if [[ "${{ github.event.inputs.buildFlavor }}" == "Field" ]]; then
|
|
VERSION=$(cat buildFlavor/field/buildVersion.txt)
|
|
BUILD_NUMBER=$(cat buildFlavor/field/buildNumber.txt)
|
|
else
|
|
VERSION=$(cat buildFlavor/tele/buildVersion.txt)
|
|
BUILD_NUMBER=$(cat buildFlavor/tele/buildNumber.txt)
|
|
fi
|
|
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
|
echo "buildNumber=$BUILD_NUMBER" >> $GITHUB_OUTPUT
|
|
echo "Using ${{ github.event.inputs.buildFlavor }} flavor: version=$VERSION, buildNumber=$BUILD_NUMBER"
|
|
|
|
- name: Install yarn
|
|
run: npm install --global yarn
|
|
|
|
- name: Install dependencies
|
|
run: |
|
|
yarn
|
|
yarn add @navi/navi-codepush-cli@1.0.4
|
|
|
|
# Environment specific steps
|
|
- name: Prepare QA Field Environment
|
|
if: github.event.inputs.environment == 'QA' && github.event.inputs.buildFlavor == 'Field'
|
|
run: yarn move:qa && yarn prepare-codepush-field-build
|
|
|
|
- name: Prepare QA Calling Environment
|
|
if: github.event.inputs.environment == 'QA' && github.event.inputs.buildFlavor == 'Calling'
|
|
run: yarn move:qa && yarn prepare-codepush-tele-build
|
|
|
|
- name: Prepare Prod Field Environment
|
|
if: github.event.inputs.environment == 'Prod' && github.event.inputs.buildFlavor == 'Field'
|
|
run: yarn move:prod && yarn prepare-codepush-field-build
|
|
|
|
- name: Prepare Prod Calling Environment
|
|
if: github.event.inputs.environment == 'Prod' && github.event.inputs.buildFlavor == 'Calling'
|
|
run: yarn move:prod && yarn prepare-codepush-tele-build
|
|
|
|
- name: Deploy Field to QA
|
|
if: github.event.inputs.environment == 'QA' && github.event.inputs.buildFlavor == 'Field'
|
|
run: |
|
|
npx navi-codepush-cli \
|
|
--app FIELD_COSMOS \
|
|
--versionMin ${{ github.event.inputs.minTargetVersion }} \
|
|
--versionMax ${{ github.event.inputs.maxTargetVersion }} \
|
|
--desc "${{ github.event.inputs.description }}" \
|
|
--platform android \
|
|
--env qa
|
|
|
|
- name: Deploy Calling to QA
|
|
if: github.event.inputs.environment == 'QA' && github.event.inputs.buildFlavor == 'Calling'
|
|
run: |
|
|
npx navi-codepush-cli \
|
|
--app TELE_COSMOS \
|
|
--versionMin ${{ github.event.inputs.minTargetVersion }} \
|
|
--versionMax ${{ github.event.inputs.maxTargetVersion }} \
|
|
--desc "${{ github.event.inputs.description }}" \
|
|
--platform android \
|
|
--env qa
|
|
|
|
- name: Deploy Field to Production
|
|
if: github.event.inputs.environment == 'Prod' && github.event.inputs.buildFlavor == 'Field'
|
|
run: |
|
|
npx navi-codepush-cli \
|
|
--app FIELD_COSMOS \
|
|
--versionMin ${{ github.event.inputs.minTargetVersion }} \
|
|
--versionMax ${{ github.event.inputs.maxTargetVersion }} \
|
|
--desc "${{ github.event.inputs.description }}" \
|
|
--platform android \
|
|
--env prod
|
|
|
|
- name: Deploy Calling to Production
|
|
if: github.event.inputs.environment == 'Prod' && github.event.inputs.buildFlavor == 'Calling'
|
|
run: |
|
|
npx navi-codepush-cli \
|
|
--app TELE_COSMOS \
|
|
--versionMin ${{ github.event.inputs.minTargetVersion }} \
|
|
--versionMax ${{ github.event.inputs.maxTargetVersion }} \
|
|
--desc "${{ github.event.inputs.description }}" \
|
|
--platform android \
|
|
--env prod
|
|
|
|
generate_source_map:
|
|
needs: generate
|
|
outputs:
|
|
package_version: ${{ needs.generate.outputs.package_version }}
|
|
build_number: ${{ needs.generate.outputs.build_number }}
|
|
runs-on: [default]
|
|
if: success() && (github.event.inputs.environment == 'Prod') # Only create source map for Prod releases
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v2
|
|
with:
|
|
token: ${{ secrets.MY_REPO_PAT }}
|
|
submodules: recursive
|
|
- name: Set Node.js 16.x
|
|
uses: actions/setup-node@v3
|
|
with:
|
|
node-version: 16.x
|
|
- name: Install yarn
|
|
run: npm install --global yarn
|
|
- name: Install dependency
|
|
run: yarn
|
|
- name: Generate Android Bundle and Source Map
|
|
run: |
|
|
npx react-native bundle \
|
|
--dev false \
|
|
--minify true \
|
|
--platform android \
|
|
--entry-file index.js \
|
|
--reset-cache \
|
|
--bundle-output index.android.bundle \
|
|
--sourcemap-output index.android.bundle.map
|
|
|
|
- name: Upload Source Map
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: source-map-${{needs.generate.outputs.package_version}}
|
|
path: index.android.bundle.map
|
|
|
|
upload_sourcemap_cybertron:
|
|
needs: generate_source_map
|
|
runs-on: [default]
|
|
if: success() && (github.event.inputs.environment == 'Prod')
|
|
steps:
|
|
- name: Download Source Map
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: source-map-${{needs.generate_source_map.outputs.package_version}}
|
|
path: ./artifacts
|
|
|
|
- name: 'create release'
|
|
run: |
|
|
cd artifacts
|
|
ls -lh
|
|
echo creating release
|
|
response=$(curl --location --request POST '${{secrets.CYBERTRON_BASE_URL}}/api/v1/release' \
|
|
--header 'Content-Type: application/json' \
|
|
--data '{
|
|
"releaseVersion": "${{ needs.generate_source_map.outputs.package_version }}",
|
|
"projectReferenceId": "${{ secrets.CYBERTRON_PROJECT_ID }}"
|
|
}')
|
|
echo $response
|
|
|
|
- name: 'create presigned url'
|
|
run: |
|
|
presigned_url_source_map='${{secrets.CYBERTRON_BASE_URL}}/api/v1/get-sourcemap-upload-url?project_id=${{secrets.CYBERTRON_PROJECT_ID}}&release_id=${{ needs.generate_source_map.outputs.package_version }}&file_name=index.android.bundle.map'
|
|
response=$(curl --location $presigned_url_source_map)
|
|
echo "$response"
|
|
upload_url=$(echo "$response" | jq -r .url)
|
|
echo $upload_url
|
|
curl --location --request PUT --progress-bar --header "Content-Type: application/octet-stream" $upload_url --upload-file artifacts/index.android.bundle.map
|
|
|
|
create_release_tag:
|
|
needs: generate_source_map
|
|
runs-on: [default]
|
|
if: success() && (github.event.inputs.environment == 'Prod') # Only create tag for Prod releases
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v2
|
|
with:
|
|
token: ${{ secrets.MY_REPO_PAT }}
|
|
submodules: recursive
|
|
persist-credentials: true
|
|
- name: Check if tag exists
|
|
id: check_tag
|
|
run: |
|
|
TAG_NAME="${{ needs.generate_source_map.outputs.package_version }}"
|
|
EXISTING_TAG=$(git ls-remote --tags origin refs/tags/$TAG_NAME)
|
|
if [[ -z "$EXISTING_TAG" ]]; then
|
|
echo "Tag $TAG_NAME does not exist."
|
|
echo "tag_exists=false" >> $GITHUB_ENV
|
|
else
|
|
echo "Tag $TAG_NAME already exists."
|
|
echo "tag_exists=true" >> $GITHUB_ENV
|
|
fi
|
|
|
|
- name: Create and push tag
|
|
if: env.tag_exists == 'false'
|
|
run: |
|
|
TAG_NAME="${{ needs.generate_source_map.outputs.package_version }}"
|
|
# git config --local user.email "${{ github.actor }}@github.com"
|
|
git config --local user.name "${{ github.actor }}"
|
|
git tag $TAG_NAME
|
|
git push origin $TAG_NAME --no-verify
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.MY_REPO_PAT }}
|
|
- name: Create release tag
|
|
run: |
|
|
TAG_NAME="${{ needs.generate_source_map.outputs.package_version }}"
|
|
BUILD_NUMBER="${{ needs.generate.outputs.build_number }}"
|
|
RELEASE_NAME="$TAG_NAME (build $BUILD_NUMBER) code push"
|
|
DESCRIPTION="${{ github.event.inputs.description }}"
|
|
REPO="navi-medici/address-verification-app"
|
|
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
|
|
|
|
curl -X POST \
|
|
-H "Authorization: token ${{ secrets.MY_REPO_PAT }}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{
|
|
\"tag_name\": \"$TAG_NAME\",
|
|
\"target_commitish\": \"$BRANCH_NAME\",
|
|
\"name\": \"$RELEASE_NAME\",
|
|
\"body\": \"\",
|
|
\"draft\": false,
|
|
\"prerelease\": false,
|
|
\"generate_release_notes\": true
|
|
}" \
|
|
"https://api.github.com/repos/$REPO/releases"
|
|
shell: bash
|