Skip to content

Commit

Permalink
UMP-652: Add CodePush action
Browse files Browse the repository at this point in the history
  • Loading branch information
vhsantos26 committed Jan 6, 2022
1 parent beda989 commit 2bdf1f5
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM ubuntu:18.04

RUN apt update && apt install -y git

COPY entrypoint.sh /entrypoint.sh

RUN chmod +x /entrypoint.sh

SHELL ["/bin/bash", "-c"]

ENTRYPOINT [ "/entrypoint.sh" ]
79 changes: 78 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,78 @@
# codepush-backwards-compatibility-check-action
# CodePush Backwards Compatibility Check Action

Actions responsible to validate if the backwards compatibility (based on the git SHA differentiation).

## :rocket: Usage

An example workflow to use it:

```yaml
name: Mobile Continuous Delivery

on:
pull_request:
branches:
- main
- develop
- rc-*
- hotfix-*

jobs:
build:
runs-on: ubuntu-latest
outputs:
is_backwards_compatible: ${{ steps.backwards_compatible.outputs.is_backwards_compatible }}
steps:
- uses: actions/checkout@v2

- run: yarn install

- working_directory: ./android
run: bundle exec fastlane build_release_bundle

- name: Release Compatibility Check
id: backwards_compatible
uses: ./.github/github-actions/codepush-backwards-compatibility-check
with:
before_commit_sha: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event_name == 'push' && github.event.before }}
after_commit_sha: ${{ github.sha }}
package_json_path: package.json
android_path: android/
ios_path: ios/
yarn_lock_path: yarn.lock

deploy_app_center:
runs-on: ubuntu-latest
needs: build
if: needs.build.outputs.is_backwards_compatible == 'true'
steps:
- uses: actions/checkout@v2

- run: yarn install

- env:
APP_CENTER_TOKEN: ${{ secrets.APP_CENTER_TOKEN }}
APP_VERSION: ${{ secrets.APP_VERSION }}
run: appcenter codepush release -a mobile-project/android -d staging -c ./codepush --token ${{ env.APP_CENTER_TOKEN }} --disable-duplicate-release-error --t ${{ env.APP_VERSION }}
```
## :gear: Inputs
| Name | Description | Default | Required |
| ----------------- | -------------------------------------- | :----------: | :------: |
| before_commit_sha | The SHA of the commit before the merge | | True |
| after_commit_sha | The SHA of the commit after the merge | | True |
| package_json_path | The path to the package.json file | package.json | False |
| android_path | The path to the Android project | android/ | False |
| ios_path | The path to the iOS project | ios/ | False |
| yarn_lock_path | The path to the yarn.lock file | yarn.lock | False |
## :gear: Outputs
| Name | Description | Default |
| ----------------------- | ---------------------------------------- | :-----: |
| is_backwards_compatible | The codepush deployment condition result | |
## :thought_balloon: Support
If you find our work useful, but for some reason there is something missing, please raise a pull request to us review it!
42 changes: 42 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: "CodePush Backwards Compatibility Check Action"
description: "Actions responsible to validate if the backwards compatibility (based on the git SHA differentiation)."
author: "Victor Hugo dos Santos"
inputs:
before_commit_sha:
description: "The SHA of the commit before the merge"
required: true
after_commit_sha:
description: "The SHA of the commit after the merge"
required: true
package_json_path:
description: "The path to the package.json file"
required: false
default: "package.json"
android_path:
description: "The path to the Android project"
required: false
default: "android/"
ios_path:
description: "The path to the iOS project"
required: true
default: "ios/"
yarn_lock_path:
description: "The path to the yarn.lock file"
required: false
default: "yarn.lock"
outputs:
is_backwards_compatible:
description: "A boolean indicating if the deployment is backwards compatible"
branding:
icon: upload-cloud
color: purple
runs:
using: "docker"
image: "Dockerfile"
args:
- ${{ inputs.before_commit_sha }}
- ${{ inputs.after_commit_sha }}
- ${{ inputs.package_json_path }}
- ${{ inputs.android_path }}
- ${{ inputs.ios_path }}
- ${{ inputs.yarn_lock_path }}
40 changes: 40 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash -l

git diff --name-only ${INPUT_BEFORE_COMMIT_SHA}..${INPUT_AFTER_COMMIT_SHA} >./git-diff.txt

while read git_diff_line; do
echo "::debug::Checking $git_diff_line against $INPUT_PACKAGE_JSON_PATH"

if [[ "$git_diff_line" == "$INPUT_PACKAGE_JSON_PATH"* ]]; then
echo "::warning title=$git_diff_line::Skip CodePush deployment as branch may not contains only react-native changes."
echo "::set-output name=is_backwards_compatible::false"
exit 0
fi

echo "::debug::Checking $git_diff_line against $INPUT_ANDROID_PATH"

if [[ "$git_diff_line" == "$INPUT_ANDROID_PATH"* ]]; then
echo "::warning title=$git_diff_line::Skip CodePush deployment as branch may not contains only react-native changes."
echo "::set-output name=is_backwards_compatible::false"
exit 0
fi

echo "::debug::Checking $git_diff_line against $INPUT_IOS_PATH"

if [[ "$git_diff_line" == "$INPUT_IOS_PATH"* ]]; then
echo "::warning title=$git_diff_line::Skip CodePush deployment as branch may not contains only react-native changes."
echo "::set-output name=is_backwards_compatible::false"
exit 0
fi

echo "::debug::Checking $git_diff_line against $INPUT_YARN_LOCK_PATH"

if [[ "$git_diff_line" == "$INPUT_YARN_LOCK_PATH"* ]]; then
echo "::warning title=$git_diff_line::Skip CodePush deployment as branch may not contains only react-native changes."
echo "::set-output name=is_backwards_compatible::false"
exit 0
fi
done <./git-diff.txt

echo "::notice title=CodePush::Branch contains only react-native changes."
echo "::set-output name=is_backwards_compatible::true"

0 comments on commit 2bdf1f5

Please sign in to comment.