diff --git a/.github/actions/utils/fs/clean-dir/action.yml b/.github/actions/utils/fs/clean-dir/action.yml new file mode 100644 index 00000000..f65c33b5 --- /dev/null +++ b/.github/actions/utils/fs/clean-dir/action.yml @@ -0,0 +1,34 @@ +name: Clean directory +description: clean directory with excludes + +inputs: + targetDirectory: + description: working directory + default: tmp/target + required: true + syncIgnore: + description: working directory + default: tmp/target + required: true + +runs: + using: composite + + steps: + - name: Clean target directory except excluded files + shell: bash + working-directory: ${{ inputs.targetDirectory }} + env: + SYNC_IGNORE: ${{ inputs.syncIgnore }} + run: | + IFS=',' read -r -a ignored_files <<< "$SYNC_IGNORE" + + exclude_conditions="" + for ignored_file in "${ignored_files[@]}"; do + exclude_conditions=" $exclude_conditions ! -path \"./$ignored_file/*\" ! -path \"./$ignored_file\"" + done + + echo "$exclude_conditions" + + eval find . -mindepth 1 $exclude_conditions -type f -exec rm -f {} + + find . -mindepth 1 -type d -empty -delete diff --git a/.github/actions/utils/fs/rename-dirs/action.yml b/.github/actions/utils/fs/rename-dirs/action.yml new file mode 100644 index 00000000..490a846d --- /dev/null +++ b/.github/actions/utils/fs/rename-dirs/action.yml @@ -0,0 +1,32 @@ +name: Rename directories +description: rename directories + +inputs: + targetDirectory: + description: working directory + default: tmp/target + required: true + sourceDirname: + description: dirname to rename + required: true + targetDirname: + description: name to rename + required: true + +runs: + using: composite + + steps: + - name: Rename directories + shell: bash + working-directory: ${{ inputs.targetDirectory }} + run: | + find . -depth -type d -iname '*${{ inputs.sourceDirname }}*' -exec bash -c ' + for dir; do + newdir=$(echo "$dir" | sed -e "s/${{ inputs.sourceDirname }}/${{ inputs.targetDirname }}/gi") + if [ "$dir" != "$newdir" ]; then + echo "Renaming directory: $dir -> $newdir" + mv "$dir" "$newdir" + fi + done + ' bash {} + diff --git a/.github/actions/utils/fs/replace-file-content/action.yml b/.github/actions/utils/fs/replace-file-content/action.yml new file mode 100644 index 00000000..9634ff98 --- /dev/null +++ b/.github/actions/utils/fs/replace-file-content/action.yml @@ -0,0 +1,50 @@ +name: Replace file content +description: replace file content + +inputs: + targetDirectory: + description: working directory + default: tmp/target + required: true + syncIgnore: + description: working directory + default: tmp/target + required: true + replacementExtentions: + required: true + description: list of extentions to replace, separated by ',' + default: "*.ts,*.sh,*.yaml" + replacementContents: + required: true + description: list of contents to replace, separated by ',' and '|' - separate source target content\ + default: "source:content:1|target:conten:1,source-content-1|target-content-1" + +runs: + using: composite + + steps: + - name: Replace file content + shell: bash + working-directory: ${{ inputs.targetDirectory }} + env: + REPLACMENT_EXTENTIONS: ${{ inputs.replacementExtentions }} + REPLACEMENT_CONTENTS: ${{ inputs.replacementContents }} + run: | + IFS=',' read -r -a replacement_extentions <<< "$REPLACMENT_EXTENTIONS" + IFS=',' read -r -a replacement_contents <<< "$REPLACEMENT_CONTENTS" + + find_conditions="" + for extention in "${replacement_extentions[@]}"; do + if [ -z "$find_conditions" ]; then + find_conditions="-name \"$extention\"" + else + find_conditions="$find_conditions -o -name \"$extention\"" + fi + done + + sed_arguments="" + for replacement_content in "${replacement_contents[@]}"; do + sed_arguments+="-e 's|$replacement_content|g' " + done + + eval "find . -type f \( $find_conditions \) -exec sed -i $sed_arguments" {} + diff --git a/.github/actions/utils/fs/sync-dirs/action.yml b/.github/actions/utils/fs/sync-dirs/action.yml new file mode 100644 index 00000000..44ec78cd --- /dev/null +++ b/.github/actions/utils/fs/sync-dirs/action.yml @@ -0,0 +1,43 @@ +name: Sync directories +description: synchronization directories with excludes + +inputs: + sourceDirectory: + description: working directory + default: tmp/source + required: true + targetDirectory: + description: working directory + default: tmp/target + required: true + syncIgnore: + description: working directory + +runs: + using: composite + + steps: + - name: Sync files to remote repository + if: ${{ inputs.syncIgnore != '' }} + shell: bash + env: + SYNC_IGNORE: ${{ inputs.syncIgnore }} + SOURCE_TMP_DIR_PATH: ${{ inputs.sourceDirectory }} + TARGET_TMP_DIR_PATH: ${{ inputs.targetDirectory }} + run: | + IFS=',' read -r -a ignored_files <<< "$SYNC_IGNORE" + + exclude_conditions="" + for ignored_file in "${ignored_files[@]}"; do + exclude_conditions=" $exclude_conditions --exclude \"$ignored_file\"" + done + + echo $exclude_conditions + + eval rsync -av --progress "$SOURCE_TMP_DIR_PATH" "$TARGET_TMP_DIR_PATH" $exclude_conditions + + - name: Sync files to remote repository + if: ${{ inputs.syncIgnore == '' }} + shell: bash + run: | + rsync -av --progress "${{ inputs.targetDirectory }}" "${{ inputs.sourceDirectory }}" diff --git a/.github/workflows/reusable-android-synchronization.yaml b/.github/workflows/reusable-android-synchronization.yaml index e31ab271..163f1776 100644 --- a/.github/workflows/reusable-android-synchronization.yaml +++ b/.github/workflows/reusable-android-synchronization.yaml @@ -1,150 +1,131 @@ -name: Sync iOS Repositories +name: Sync Android Repositories + +env: + TARGET_TMP_DIR_PATH: tmp/target/ + SOURCE_TMP_DIR_PATH: tmp/source/ on: workflow_call: - secrets: - token: - required: true inputs: + appId: + type: string + required: true targetRepository: type: string required: true + repositoryOwner: + type: string + required: true + sourceDirname: + type: string + targetDirname: + type: string + syncIgnore: + type: string + required: true + description: list of files to exclue, separated by ',' + default: ".git,.idea,LICENSE," + replacementExtentions: + type: string + required: true + description: list of extentions to replace, separated by ',' + default: "*.ts,*.sh,*.yaml" + replacementContents: + type: string + required: true + description: list of contents to replace, separated by ',' and '|' - separate source target content\ + default: "source:content:1|target:conten:1,source-content-1|target-content-1" + secrets: + privateKey: + required: true jobs: run: name: Synchronization runs-on: ubuntu-latest steps: + - uses: actions/create-github-app-token@v1 + id: appTokenStep + with: + app-id: ${{ inputs.appId }} + private-key: ${{ secrets.privateKey }} + owner: ${{ inputs.repositoryOwner }} + - name: Checkout uses: actions/checkout@v4 with: - path: source - env: - GITHUB_TOKEN: ${{ secrets.token }} - - - name: Get current version from source - working-directory: source - env: - FILE_PATH: 'version.properties' - id: version_source - run: | - current_version=$(awk -F"=" '/VERSION_NAME/ {print $2}' "$FILE_PATH") - echo "version=$current_version" >> $GITHUB_OUTPUT - - - name: Get last merged PR author login - working-directory: source - id: pr_author - run: | - PR_NUMBER=$(gh pr list --state merged --limit 1 --json number --jq '.[0].number') - LAST_PR_AUTHOR=$(gh pr view $PR_NUMBER --json author --jq '.author.login') - echo "LAST_PR_AUTHOR=$LAST_PR_AUTHOR" >> $GITHUB_OUTPUT - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + path: ${{ env.SOURCE_TMP_DIR_PATH }} + token: ${{ steps.appTokenStep.outputs.token }} - - name: Check out remote repository + - name: Checkout remote repository uses: actions/checkout@v4 with: + path: ${{ env.TARGET_TMP_DIR_PATH }} + token: ${{ steps.appTokenStep.outputs.token }} repository: ${{inputs.targetRepository}} - token: ${{ secrets.token }} - path: target - - name: Clean target directory except excluded files - run: | - rsync -av --delete --exclude-from=<(echo \ - '.git' \ - '.idea' \ - '.github' \ - '.gitignore' \ - 'LICENSE' \ - 'README.md' \ - 'version.properties' \ - ) /dev/null target/ - - - name: Sync files to remote repository - run: | - rsync -av --progress \ - source/ target/ \ - --exclude '.git' \ - --exclude '.idea' \ - --exclude '.github' \ - --exclude '.gitignore' \ - --exclude 'LICENSE' \ - --exclude 'README.md' \ - --exclude 'version.properties' \ - - - name: Apply changes to Kotlin files - working-directory: target - run: | - find . -type f \( -name '*.kts' -o -name '*.kt' \) -exec sed -i \ - -e 's|https://api.rees46.com/|https://api.personaclick.com/|g' \ - -e 's/com.rees46:rees46-sdk/com.personaclick:personaclick-sdk/g' \ - -e 's/api.rees46.com/api.personaclick.com/g' \ - -e 's/rees46.com/personaclick.com/g' \ - -e 's/rees46/personaClick/g' \ - -e 's/REES46/PersonaClick/g' \ - -e 's/Rees46/PersonaClick/g' {} + - - - name: Apply changes to MD & XML & TOML files - working-directory: target - run: | - find . -type f \( -name '*.md' -o -name '*.xml' -o -name '*.toml' \) -exec sed -i \ - -e 's|https://api.rees46.com/|https://api.personaclick.com/|g' \ - -e 's/com.rees46:rees46-sdk/com.personaclick:personaclick-sdk/g' \ - -e 's/api.rees46.com/api.personaclick.com/g' \ - -e 's/rees46.com/personaclick.com/g' \ - -e 's/rees46/personaClick/g' \ - -e 's/REES46/PersonaClick/g' \ - -e 's/Rees46/PersonaClick/g' {} + - - - name: Rename directories - working-directory: target - run: | - find . -depth -type d -iname '*rees46*' -exec bash -c ' - for dir; do - newdir=$(echo "$dir" | sed -e "s/rees46/personaClick/gi") - if [ "$dir" != "$newdir" ]; then - echo "Renaming directory: $dir -> $newdir" - mv "$dir" "$newdir" - fi - done - ' bash {} + - - - name: Create commit - working-directory: target + - uses: rees46/workflow/.github/actions/utils/fs/clean-dir@master + with: + targetDirectory: ${{ env.TARGET_TMP_DIR_PATH }} + syncIgnore: ${{ inputs.syncIgnore }} + + - uses: rees46/workflow/.github/actions/utils/fs/sync-dirs@master + with: + syncIgnore: ${{ inputs.syncIgnore }} + targetDirectory: ${{ env.TARGET_TMP_DIR_PATH }} + sourceDirectory: ${{ env.SOURCE_TMP_DIR_PATH }} + + - uses: rees46/workflow/.github/actions/utils/fs/replace-file-content@master + with: + syncIgnore: ${{ inputs.syncIgnore }} + targetDirectory: ${{ env.TARGET_TMP_DIR_PATH }} + replacementExtentions: ${{ inputs.replacementExtentions }} + replacementContents: ${{ inputs.replacementContents }} + + - uses: rees46/workflow/.github/actions/utils/fs/rename-dirs@master + if: ${{ inputs.sourceDirname != '' && inputs.targetDirname != '' }} + with: + targetDirectory: ${{ env.TARGET_TMP_DIR_PATH }} + sourceDirname: ${{ inputs.sourceDirname }} + targetDirname: ${{ inputs.targetDirname }} + + - uses: rees46/workflow/.github/actions/utils/fs/sync-dirs@master + with: + targetDirectory: ${{ env.TARGET_TMP_DIR_PATH }} + sourceDirectory: . + + - name: debug fs after changes run: | - git config --global user.name Jade Smith - git config --global user.email github-bot@rees46.com - git add . - echo "Changes to be committed:" - git diff --staged - git commit -m "feat: release" - env: - GITHUB_TOKEN: ${{ secrets.token }} - - - name: Set branch name - id: branch_name - run: echo "BRANCH_NAME=feat/new-release-$(date +%Y%m%d%H%M%S)" >> $GITHUB_OUTPUT - - - name: Checkout new branch and push - working-directory: target + ls -a + + - name: debug fs after changes run: | - git checkout -b $BRANCH_NAME - git push --set-upstream origin $BRANCH_NAME - env: - GITHUB_TOKEN: ${{ secrets.token }} - BRANCH_NAME: ${{ steps.branch_name.outputs.BRANCH_NAME }} - - - name: Create Pull Request - working-directory: target + ls -a -R + + - uses: rees46/workflow/.github/actions/github/pull-request/get-last-author@master + id: lastPrAuthorStep + with: + githubToken: ${{ steps.appTokenStep.outputs.token }} + + - uses: rees46/workflow/.github/actions/github/utils/get-new-branch-name@master + id: newBranchNameStep + + - uses: rees46/workflow/.github/actions/github/checkout/new-branch@master + with: + branchName: ${{ steps.newBranchNameStep.outputs.branchName }} + + - name: git add run: | - PR_TITLE="Automated release" - PR_BODY="This is an automated pull request to update from branch $BRANCH_NAME" - DEFAULT_BRANCH=$(gh repo view --json defaultBranchRef -q ".defaultBranchRef.name") - echo "Assigning PR to LAST_PR_AUTHOR: $LAST_PR_AUTHOR" - echo "Adding MANAGER: $MANAGER as a reviewer" - gh pr create --title "$PR_TITLE" --body "$PR_BODY" --base "$DEFAULT_BRANCH" --head $BRANCH_NAME --assignee $LAST_PR_AUTHOR --reviewer $MANAGER - env: - GITHUB_TOKEN: ${{ secrets.token }} - BRANCH_NAME: ${{ steps.branch_name.outputs.BRANCH_NAME }} - LAST_PR_AUTHOR: ${{ steps.pr_author.outputs.LAST_PR_AUTHOR }} - MANAGER: TorinAsakura + git add --all -- . ':!tmp/' + + - uses: rees46/workflow/.github/actions/github/commit/create@master + with: + branchName: ${{ steps.newBranchNameStep.outputs.branchName }} + githubToken: ${{ steps.appTokenStep.outputs.token }} + targetRepository: ${{ inputs.targetRepository }} + + - uses: rees46/workflow/.github/actions/github/pull-request/create@master + with: + githubToken: ${{ steps.appTokenStep.outputs.token }} + lastPrAuthor: ${{ steps.lastPrAuthorStep.outputs.lastPrAuthor }} + branchName: ${{ steps.newBranchNameStep.outputs.branchName }}