Set a new git flow #60
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Check PR | |
on: | |
pull_request: | |
branches: | |
- master | |
- develop | |
env: | |
FORK: "${{ github.event.pull_request.head.repo.full_name != github.repository }}" | |
APP_BUILD_TYPE: Release | |
RELEASE_CANDIDATE: "${{ github.event.pull_request.head.repo.full_name == github.repository && github.base_ref == 'master' && startsWith(github.head_ref, 'release/') }}" | |
BUNDLE_WITHOUT: development | |
FASTLANE_SKIP_UPDATE_CHECK: true | |
# Here I use some workarounds to prevent check stuck at 'waiting status update' | |
jobs: | |
# Buildin 'paths-ignore' not working here. I need to pass all checks on PR. Without it PR will stuck on 'waiting for status' | |
filter_paths: | |
name: Filter changed paths | |
runs-on: ubuntu-latest | |
outputs: | |
is_release: ${{ env.RELEASE_CANDIDATE }} | |
src_changed: ${{ steps.check_files.outputs.src_files }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dorny/[email protected] | |
id: check_files | |
with: | |
filters: | | |
src_files: | |
- '.bundle/**' | |
- '.github/workflows/*.yml' | |
- 'app/**' | |
- 'buildSrc/**' | |
- 'common/**' | |
- 'data/**' | |
- 'fastlane/actions/*.rb' | |
- 'fastlane/Appfile' | |
- 'fastlane/Fastfile' | |
- 'gradle/**' | |
- 'logic/**' | |
- 'native' | |
- '.tool-versions' | |
- '*.gradle.kts' | |
- 'Gemfile*' | |
- 'gradle*' | |
- 'rust-toolchain' | |
- '*.properties' | |
# Bump app version and commit changes | |
# WARNING: it will checkout HEAD, not BASE | |
bump_version: | |
name: PR bump version | |
runs-on: ubuntu-latest | |
if: ${{ needs.filter_paths.outputs.src_changed == 'true' || needs.filter_paths.outputs.is_release == 'true' }} | |
needs: filter_paths | |
outputs: | |
bumped: ${{ steps.persist_version.outputs.changes_detected || 'false' }} | |
version_name: ${{ steps.bump_version.outputs.VERSION_NAME }} | |
version_code: ${{ steps.bump_version.outputs.VERSION_CODE }} | |
steps: | |
- uses: actions/checkout@v4 | |
if: ${{ env.RELEASE_CANDIDATE == 'true' }} | |
with: | |
# Required by stefanzweifel/git-auto-commit-action | |
# PR check will stuck on 'waiting for status' without PAT after version bump pushing | |
token: ${{ secrets.PAT }} | |
ref: ${{ github.head_ref }} | |
- uses: actions/checkout@v4 | |
if: ${{ env.RELEASE_CANDIDATE == 'false' }} | |
- name: Setup required Ruby | |
uses: ruby/setup-ruby@v1 | |
with: | |
bundler-cache: true | |
- uses: benjlevesque/[email protected] | |
id: short-sha | |
with: | |
length: 7 | |
# Valid names for release candidate: release/0.1.0, hotfix/0.1.0. Otherwise you can use any branch name. | |
# App version name and version code depends on GH releases on BASE branch. | |
# Output app name will be different from persisted release candidate app name. | |
# Related Java properties file will be changed only if it is a release candidate | |
# Step outputs: versionName and versionCode | |
- name: Calculate version name and code | |
id: bump_version | |
run: | | |
version_tag="0.0.0" | |
# If this is a release candidate than branch should have valid name e.g. release/0.1.0 | |
if [[ ${RELEASE_CANDIDATE} = true ]]; then | |
if [[ ${{ github.head_ref }} =~ /(([0-9]+\.?){3})$ ]]; then | |
version_tag=$(echo ${BASH_REMATCH[1]}) | |
else | |
echo "Invalid branch name. It should contains version name" | |
exit 1 | |
fi | |
fi | |
o=($(bundle exec fastlane run release_version_calc token:"${{ secrets.GITHUB_TOKEN }}" tag:"v${version_tag}")) | |
name='' | |
code=$((${o[-1]})) | |
if [[ ${RELEASE_CANDIDATE} = true ]]; then | |
name=${o[-2]} | |
bundle exec fastlane run persist_version version_name:"${name}" version_code:"${code}" | |
else | |
name="pr-${{ github.event.number }}-${{ steps.short-sha.outputs.sha }}" | |
fi | |
echo "Output app name: $name, code: $code" | |
echo "VERSION_NAME=${name}" >> "$GITHUB_OUTPUT" | |
echo "VERSION_CODE=${code}" >> "$GITHUB_OUTPUT" | |
# Commit and push version change if it us a release candidate | |
- name: Persist version | |
id: persist_version | |
if: ${{ env.RELEASE_CANDIDATE == 'true' }} | |
uses: stefanzweifel/[email protected] | |
with: | |
commit_message: Bump version | |
commit_user_name: github-actions[bot] | |
commit_user_email: github-actions[bot]@users.noreply.github.com | |
file_pattern: seeneva.properties | |
# If version was changed, send a comment about it | |
- name: Send comment | |
if: steps.persist_version.outputs.changes_detected == 'true' | |
run: | | |
msg=":exclamation: App version was changed.\n\n**versionName**: ${{ steps.bump_version.outputs.VERSION_NAME }}\n**versionCode**: ${{ steps.bump_version.outputs.VERSION_CODE }}" | |
bundle exec fastlane run issue_comment token:"${{ secrets.GITHUB_TOKEN }}" number:${{ github.event.number }} msg:"$(printf "${msg}")" | |
test: | |
name: PR test | |
runs-on: ubuntu-latest | |
# This condition required to prevent multiple PR status checks after version bump was pushed | |
if: ${{ needs.bump_version.outputs.bumped == 'false' }} | |
needs: bump_version | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Prepare env | |
uses: ./actions/prepare_env | |
- name: Run Android tests | |
run: | | |
bundle exec fastlane tests build_type:$APP_BUILD_TYPE | |
- name: Upload reports | |
if: ${{ always() }} | |
uses: actions/upload-artifact@v3 | |
with: | |
name: reports | |
path: | | |
**/build/reports/lint-*.html | |
**/build/reports/tests | |
build: | |
name: PR build | |
runs-on: ubuntu-latest | |
environment: | |
name: release | |
if: ${{ needs.bump_version.outputs.bumped == 'false' }} | |
needs: bump_version | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Prepare env | |
uses: ./actions/prepare_env | |
# Check that fastlane has changelog for the new version | |
- name: Check Fastlane changelog | |
if: ${{ env.RELEASE_CANDIDATE == 'true' }} | |
run: | | |
locales="" | |
for dir in fastlane/metadata/android/*/; do | |
if [[ ! -f "${dir}/changelogs/${{ needs.bump_version.outputs.version_code }}.txt" ]]; then | |
locales="${locales}- *$(basename $dir)*\n" | |
fi | |
done | |
if [[ ! -z "$locales" ]]; then | |
msg=":exclamation: There is no Fastlane changelog for locales:\n\n${locales}" | |
echo "::error::${msg}" | |
bundle exec fastlane run issue_comment token:"${{ secrets.GITHUB_TOKEN }}" number:${{ github.event.number }} msg:"$(printf "${msg}")" | |
exit 1 | |
fi | |
- name: Run assemble task | |
if: ${{ env.FORK == 'false' }} | |
run: | | |
bundle exec fastlane pr_build_apk build_type:"${APP_BUILD_TYPE}" store_data:"${SEENEVA_STORE_DATA}" | |
env: | |
SEENEVA_VERSION_NAME: ${{ needs.bump_version.outputs.version_name }} | |
SEENEVA_VERSION_CODE: ${{ needs.bump_version.outputs.version_code }} | |
SEENEVA_STORE_FILE: ${{ github.workspace }}/seeneva.keystore | |
SEENEVA_STORE_DATA: ${{ secrets.KEYSTORE }} | |
SEENEVA_STORE_PASS: ${{ secrets.KEYSTORE_PASS }} | |
SEENEVA_KEY_ALIAS: ${{ secrets.KEYSTORE_ALIAS }} | |
SEENEVA_KEY_PASS: ${{ secrets.KEY_PASS }} | |
FL_GRADLE_PRINT_COMMAND: false | |
- name: Run forked assemble task | |
if: ${{ env.FORK == 'true' }} | |
run: | | |
bundle exec fastlane pr_build_fork_apk build_type:"${APP_BUILD_TYPE}" | |
env: | |
SEENEVA_VERSION_NAME: ${{ needs.bump_version.outputs.version_name }} | |
SEENEVA_VERSION_CODE: ${{ needs.bump_version.outputs.version_code }} | |
- name: Upload APKs | |
uses: actions/upload-artifact@v3 | |
with: | |
name: apk | |
path: ./app/build/outputs/apk | |
if-no-files-found: error |