From 9d7faafe5fc1666bf3823e5f3dbbac38078a0a3a Mon Sep 17 00:00:00 2001 From: Ulric Date: Wed, 13 Sep 2023 10:56:12 +0200 Subject: [PATCH] WIP 2 --- .../{build-example.yml => build-apk.yml} | 48 ++++++++----- .github/workflows/build-package.yml | 9 +-- .github/workflows/check-version.yml | 31 +++++++++ .github/workflows/format-version-code.yml | 20 ++++++ .github/workflows/publish-bundle.yml | 68 +++++++++++++++++++ .github/workflows/publish-package.yml | 40 +++++++++++ .github/workflows/publish-s3.yml | 38 +++++++++++ .github/workflows/publish-soti.yml | 44 ++++++++++++ .github/workflows/release.yml | 55 +++++++++++++++ .github/workflows/set-bundle-key.yml | 26 +++++++ .github/workflows/tag.yml | 12 ++++ Storybook/index.js | 5 +- 12 files changed, 369 insertions(+), 27 deletions(-) rename .github/workflows/{build-example.yml => build-apk.yml} (69%) create mode 100644 .github/workflows/check-version.yml create mode 100644 .github/workflows/format-version-code.yml create mode 100644 .github/workflows/publish-bundle.yml create mode 100644 .github/workflows/publish-package.yml create mode 100644 .github/workflows/publish-s3.yml create mode 100644 .github/workflows/publish-soti.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/set-bundle-key.yml create mode 100644 .github/workflows/tag.yml diff --git a/.github/workflows/build-example.yml b/.github/workflows/build-apk.yml similarity index 69% rename from .github/workflows/build-example.yml rename to .github/workflows/build-apk.yml index fbfb55e5..f2cf7252 100644 --- a/.github/workflows/build-example.yml +++ b/.github/workflows/build-apk.yml @@ -1,12 +1,27 @@ name: Build Design System Storybook App on: - push: - branches: - - main - pull_request: - release: - types: [created] + workflow_call: + inputs: + version-code: + required: true + type: string + node-version: + required: true + type: string + java-version: + required: true + type: string + outputs: + apk-name: + description: 'Apk name' + value: app-release.apk + apk-version: + description: 'Apk version' + value: ${{ jobs.build.outputs.apk-version }} + apk-artifact-name: + description: 'Apk artifact name' + value: Design-System-Samples-Apk jobs: build: @@ -18,8 +33,6 @@ jobs: working-directory: ./Storybook env: smartway_keystore_name: smartway.keystore - node-version: 18 - java-version: 11 steps: - name: Tailscale uses: tailscale/github-action@v2 @@ -30,7 +43,7 @@ jobs: version: ${{ vars.TAILSCALE_VERSION }} - name: Import Secrets - id: secrets + id: import-secrets uses: hashicorp/vault-action@v2 with: url: ${{ vars.VAULT_URL }} @@ -38,9 +51,6 @@ jobs: method: jwt path: 'github-actions' secrets: | - secret/data/smartapp/keystore KEYSTORE_PASSWORD | SMARTWAY_KEYSTORE_PASSWORD ; - secret/data/smartapp/keystore KEYSTORE_PASSWORD | SMARTWAY_KEY_PASSWORD ; - secret/data/smartapp/keystore KEY_ALIAS | SMARTWAY_KEY_ALIAS ; secret/data/github-actions-common/aws accessKey | AWS_ACCESS_KEY_ID ; secret/data/github-actions-common/aws secretKey | AWS_SECRET_ACCESS_KEY ; @@ -49,7 +59,7 @@ jobs: - uses: actions/setup-node@v3 with: - node-version: ${{ env.node-version }} + node-version: ${{ inputs.node-version }} registry-url: 'https://npm.pkg.github.com' scope: '@ZeroGachis' @@ -60,7 +70,7 @@ jobs: - uses: actions/setup-java@v3 with: distribution: 'temurin' - java-version: ${{ env.java-version }} + java-version: ${{ inputs.java-version }} cache: 'gradle' - name: Validate Gradle wrapper @@ -72,13 +82,19 @@ jobs: - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v1-node16 with: - aws-access-key-id: ${{ steps.secrets.outputs.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ steps.secrets.outputs.AWS_SECRET_ACCESS_KEY }} + aws-access-key-id: ${{ steps.import-secrets.outputs.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ steps.import-secrets.outputs.AWS_SECRET_ACCESS_KEY }} aws-region: eu-west-1 - name: Get Smartway APK keystore run: aws s3 cp s3://backup-zerogachis/github-actions/${{ env.smartway_keystore_name }} android/app/${{ env.smartway_keystore_name }} + - name: Update android versions + uses: chkfung/android-version-actions@v1 + with: + gradlePath: android/app/build.gradle + versionCode: ${{ inputs.version-code }} + - name: Install dependencies run: npm install env: diff --git a/.github/workflows/build-package.yml b/.github/workflows/build-package.yml index c69f7e38..c4e4f174 100644 --- a/.github/workflows/build-package.yml +++ b/.github/workflows/build-package.yml @@ -1,12 +1,11 @@ name: Build Design System package on: + workflow_call: push: branches: - main pull_request: - release: - types: [created] jobs: build: @@ -41,9 +40,3 @@ jobs: - name: Compile run: npm run tsc - - - name: Publish - if: startsWith(github.ref, 'refs/tags/') - run: npm publish - env: - NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/check-version.yml b/.github/workflows/check-version.yml new file mode 100644 index 00000000..e7aae4f7 --- /dev/null +++ b/.github/workflows/check-version.yml @@ -0,0 +1,31 @@ +name: Check apk version + +on: + workflow_call: + outputs: + is-new-apk-version: + value: ${{ jobs.need-new-version-apk.outputs.need-new-apk }} +env: + apk_name: app-release.apk + +jobs: + need-new-version-apk: + runs-on: [ubuntu-latest] + outputs: + need-new-apk: ${{ steps.get-existing-apk.outputs.need-new-apk }} + steps: + - name: Get APK version + id: get-apk-version + run: | + echo "apk-version=$(grep -oP "versionName \"\K[^\"]*" android/app/build.gradle)" >> $GITHUB_OUTPUT + + - name: Get existing APK + id: get-existing-apk + run: | + aws s3 cp s3://${{ vars.S3_BUCKET }}/storybook-smartapp/${{ steps.get-apk-version.outputs.apk-version }}/${{ env.apk_name }} android/app/build/outputs/apk/release/${{ env.apk_name }} && { + echo "Apk already exist for that version" + echo "need-new-apk=false" >> $GITHUB_OUTPUT + } || { + echo "Apk does not exist for that version, need build a new one" + echo "need-new-apk=true" >> $GITHUB_OUTPUT + } diff --git a/.github/workflows/format-version-code.yml b/.github/workflows/format-version-code.yml new file mode 100644 index 00000000..11316489 --- /dev/null +++ b/.github/workflows/format-version-code.yml @@ -0,0 +1,20 @@ +name: 'FormatVersionCode' + +on: + workflow_call: + outputs: + version-code: + description: 'Version code generated' + value: ${{ jobs.format-version-code.outputs.version-code }} + +jobs: + format-version-code: + name: Format Version Code + runs-on: ubuntu-latest + + outputs: + version-code: ${{ steps.version-code.outputs.value }} + steps: + - name: 'Format build number for Android VersionCode' + id: version-code + run: echo "value=`printf '%04o\n' ${{ github.run_number }}`" >> $GITHUB_OUTPUT diff --git a/.github/workflows/publish-bundle.yml b/.github/workflows/publish-bundle.yml new file mode 100644 index 00000000..e29eb819 --- /dev/null +++ b/.github/workflows/publish-bundle.yml @@ -0,0 +1,68 @@ +name: 'Bundle JS' + +on: + workflow_call: + inputs: + node-version: + required: true + type: string + codepush-app: + required: true + type: string + +jobs: + bundle-js: + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + packages: read + steps: + - name: Import Secrets + id: imported-secrets + uses: hashicorp/vault-action@v2 + with: + url: ${{ vars.VAULT_URL }} + role: ${{ vars.VAULT_GITHUB_ACTIONS_ROLE }} + method: jwt + path: 'github-actions' + secrets: | + secret/data/storybook-smartapp CODE_PUSH_KEY_NAME | STORYBOOK_CODE_PUSH_KEY_NAME ; + secret/data/storybook-smartapp CODE_PUSH_TOKEN | STORYBOOK_CODE_PUSH_TOKEN ; + + - name: Clean Workspace + uses: mickem/clean-after-action@v2 + + - name: Checkout + uses: actions/checkout@v3 + + - uses: actions/setup-node@v3 + with: + node-version: ${{ inputs.node-version }} + registry-url: 'https://npm.pkg.github.com' + scope: '@ZeroGachis' + + - name: Install dependencies + run: npm ci --ignore-scripts + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Rebuild & Prepare dependencies + run: npm rebuild && npm run prepare --if-present + + - name: Install App center + run: npm install -g appcenter-cli + + - name: App center login + run: appcenter login --token ${{ steps.imported-secrets.outputs.STORYBOOK_CODE_PUSH_TOKEN }} + + - name: Deploy code push + run: | + appcenter codepush release-react -a ${{ inputs.codepush-app }} -d ${{ steps.imported-secrets.outputs.STORYBOOK_CODE_PUSH_KEY_NAME }} || { + if [[ $? -eq 3 ]] ; then + echo "Code push deploy skipped." + exit 0 + fi + + exit $? + } diff --git a/.github/workflows/publish-package.yml b/.github/workflows/publish-package.yml new file mode 100644 index 00000000..edfa37bc --- /dev/null +++ b/.github/workflows/publish-package.yml @@ -0,0 +1,40 @@ +on: + push: + tags: + - '*' + +jobs: + publish: + runs-on: [ubuntu-latest] + steps: + - name: Checkout + uses: actions/checkout@v3 + + - uses: actions/setup-node@v3 + with: + node-version: 18 + registry-url: 'https://npm.pkg.github.com' + scope: '@ZeroGachis' + + - name: Install dependencies + run: npm ci --ignore-scripts + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Rebuild & Prepare dependencies + run: npm rebuild && npm run prepare --if-present + + - name: Update package version + uses: mingjun97/file-regex-replace@v1 + with: + regex: '"version": "([0-9.]*)"' + replacement: '"version": "${{ github.ref_name }}"' + include: 'package.json' + + - name: Compile + run: npm run tsc + + - name: Publish + run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/publish-s3.yml b/.github/workflows/publish-s3.yml new file mode 100644 index 00000000..595b1a0f --- /dev/null +++ b/.github/workflows/publish-s3.yml @@ -0,0 +1,38 @@ +name: Publish S3 + +on: + workflow_call: + inputs: + apk-artifact-name: + required: true + type: string + apk-name: + required: true + type: string + apk-version: + required: true + type: string + +jobs: + publish-s3: + runs-on: [ubuntu-latest] + steps: + - name: Clean Workspace + uses: mickem/clean-after-action@v2 + + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v1-node16 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: eu-west-1 + + - name: Download Artefact + uses: actions/download-artifact@v3 + with: + name: ${{ inputs.artifact-name }} + path: ${{ github.workspace }}/artifact/ + + - name: Push Apk to S3 + working-directory: 'artifact' + run: aws s3 cp ${{ inputs.apk-name }} s3://${{ vars.S3_BUCKET }}/react-native/${{ inputs.apk-version }}/${{ inputs.apk-name }} diff --git a/.github/workflows/publish-soti.yml b/.github/workflows/publish-soti.yml new file mode 100644 index 00000000..ac078664 --- /dev/null +++ b/.github/workflows/publish-soti.yml @@ -0,0 +1,44 @@ +name: Publish Soti + +on: + workflow_call: + inputs: + environment: + required: true + type: string + apk-name: + required: true + type: string + apk-artifact-name: + required: true + type: string +jobs: + publish-soti: + name: Publish APK on Soti + environment: ${{ inputs.environment }} + runs-on: [self-hosted, python] + + steps: + - name: Clean Workspace + uses: mickem/clean-after-action@v2 + + - name: Checkout + uses: actions/checkout@v3 + + - name: Download APK + uses: actions/download-artifact@v3 + with: + name: ${{ inputs.apk-artifact-name }} + path: ${{ github.workspace }}/artifact/ + + - name: Publish APK on SOTI + working-directory: scripts/soti + run: | + pip3 install --user -r requirements.txt \ + && python3 upload-package.py \ + "${{ secrets.SOTI_API_URL }}" \ + "${{ github.workspace }}/artifact/${{ inputs.apk-name }}" \ + "${{ secrets.SOTI_API_KEY }}" \ + "${{ secrets.SOTI_API_SECRET }}" \ + "${{ secrets.SOTI_USERNAME }}" \ + "${{ secrets.SOTI_PASSWORD }}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..8e0e4039 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,55 @@ +name: Release Design System package + +on: + push: + branches: + - task/add-code-push + +jobs: + publish-bundle: + name: Publish on code push + uses: ./.github/workflows/publish-bundle.yml + with: + node-version: 18 + codepush-app: smartway-ai/storybook-smartapp + secrets: inherit + + # # To step build-apk + # set-bundle-key: + # name: Set bundle key + # uses: ./.github/workflows/set-bundle-key.yml + # secrets: inherit + + # format-version-code: + # name: Format version for Android + # uses: ./.github/workflows/format-version-code.yml + # # -- + + # check-version: + # name: Check version APK + # uses: ./.github/workflows/check-version.yml + + # build-apk: + # name: Build apk + # needs: [format-version-code, check-version] + # if: needs.check-version.outputs.is-new-apk-version + # uses: ./.github/workflows/build-apk.yml + # with: + # version-code: ${{ needs.format-version-code.outputs.version-code }} + # node-version: 18 + # java-version: 11 + # secrets: inherit + + # publish-s3: + # name: Publish S3 + # needs: [build-apk, format-version-code] + # uses: ./.github/workflows/publish-s3.yml + # with: + # apk-artifact-name: ${{ needs.build-apk.outputs.apk-artifact-name }} + # apk-name: ${{ needs.build-apk.outputs.apk-name }} + # app-version: ${{ needs.format-version-code.outputs.version-code }} + + # publish-soti: + # name: Publish Soti + # needs: [build-apk] + # uses: ./.github/workflows/publish-soti.yml diff --git a/.github/workflows/set-bundle-key.yml b/.github/workflows/set-bundle-key.yml new file mode 100644 index 00000000..af0978b9 --- /dev/null +++ b/.github/workflows/set-bundle-key.yml @@ -0,0 +1,26 @@ +name: Build Design System package + +on: + workflow_call: + +jobs: + build: + runs-on: [ubuntu-latest] + steps: + - name: Import Secrets + id: import-secrets + uses: hashicorp/vault-action@v2 + with: + url: ${{ vars.VAULT_URL }} + role: ${{ vars.VAULT_GITHUB_ACTIONS_ROLE }} + method: jwt + path: 'github-actions' + secrets: | + secret/data/storybook-smartapp CODE_PUSH_KEY_PASS | STORYBOOK_CODE_PUSH_KEY_PASS ; + + - name: Set code push key + uses: mingjun97/file-regex-replace@v1 + with: + regex: '(.*)' + replacement: '${{ steps.import-secrets.outputs.STORYBOOK_CODE_PUSH_KEY_PASS }}' + include: '^android/app/src/main/res/values/strings.xml' diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml new file mode 100644 index 00000000..185316d9 --- /dev/null +++ b/.github/workflows/tag.yml @@ -0,0 +1,12 @@ +name: Tag event Design System package + +on: + push: + tags: + - '*' + +jobs: + publish-package: + name: Publish pacakghe + uses: ./.github/workflows/workflow-calls/publish-package.yml + secrets: inherit diff --git a/Storybook/index.js b/Storybook/index.js index ef4632fa..17b8170b 100644 --- a/Storybook/index.js +++ b/Storybook/index.js @@ -1,13 +1,12 @@ +/* global __DEV__ */ import {AppRegistry} from 'react-native'; import App from './App'; import {name as appName} from './app.json'; import CodePush from 'react-native-code-push'; import { gestureHandlerRootHOC } from 'react-native-gesture-handler'; -AppRegistry.registerComponent(appName, () => gestureHandlerRootHOC(App)); - const CodePushApp = CodePush({ - checkFrequency: CodePush.CheckFrequency.ON_APP_RESUME, + checkFrequency: __DEV__ ? CodePush.CheckFrequency.MANUAL : CodePush.CheckFrequency.ON_APP_RESUME, installMode: CodePush.InstallMode.ON_NEXT_RESUME, minimumBackgroundDuration: 30, rollbackRetryOptions: { maxRetryAttempts: 10 }