diff --git a/.github/actions/github/checkout/new-branch/action.yml b/.github/actions/github/checkout/new-branch/action.yml new file mode 100644 index 00000000..f7a5abfd --- /dev/null +++ b/.github/actions/github/checkout/new-branch/action.yml @@ -0,0 +1,27 @@ +name: Checkout new branch +description: checkout new branch + +inputs: + targetDirectory: + description: working directory + default: tmp/target + required: true + branchName: + description: new branch name + required: true + +runs: + using: composite + + steps: + - name: Checkout new branch + shell: bash + working-directory: ${{ inputs.targetDirectory }} + run: | + git checkout -b ${{ inputs.branchName }} + + - name: Push new branch + shell: bash + working-directory: ${{ inputs.targetDirectory }} + run: | + git push --set-upstream origin ${{ inputs.branchName }} diff --git a/.github/actions/github/commit/create/action.yml b/.github/actions/github/commit/create/action.yml new file mode 100644 index 00000000..8dd0d394 --- /dev/null +++ b/.github/actions/github/commit/create/action.yml @@ -0,0 +1,26 @@ +name: Create commit +description: create commit + +inputs: + targetRepository: + description: Target repository to commit + required: true + githubToken: + description: GitHup token + required: true + branchName: + description: Branch to commit + required: true + +runs: + using: composite + + steps: + - name: Commit changes + uses: planetscale/ghcommit-action@v0.2.0 + env: + GITHUB_TOKEN: ${{ inputs.githubToken }} + with: + repo: ${{ inputs.targetRepository }} + branch: ${{ inputs.branchName }} + commit_message: 'feat: release' diff --git a/.github/actions/github/pull-request/create/action.yml b/.github/actions/github/pull-request/create/action.yml new file mode 100644 index 00000000..d3ae2699 --- /dev/null +++ b/.github/actions/github/pull-request/create/action.yml @@ -0,0 +1,42 @@ +name: Create pull request on target repo +description: create pull request on target repo + +inputs: + targetDirectory: + default: tmp/target + description: Commit author GitGup token + required: true + githubToken: + description: GitHup token + required: true + reviewerUsername: + description: PullRequest reviewer username + default: TorinAsakura + required: true + lastPrAuthor: + description: PullRequest reviewer username + default: TorinAsakura + required: true + branchName: + description: git branch name + required: true + +runs: + using: composite + + steps: + - name: Create Pull Request + shell: bash + working-directory: ${{ inputs.targetDirectory }} + env: + GITHUB_TOKEN: ${{ inputs.githubToken }} + BRANCH_NAME: ${{ inputs.branchName }} + LAST_PR_AUTHOR: ${{ inputs.lastPrAuthor }} + REVIEWER: ${{ inputs.reviewerUsername }} + 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 REVIEWER: $REVIEWER as a reviewer" + gh pr create --title "$PR_TITLE" --body "$PR_BODY" --base "$DEFAULT_BRANCH" --head $BRANCH_NAME --assignee $LAST_PR_AUTHOR --reviewer $REVIEWER diff --git a/.github/actions/github/pull-request/get-last-author/action.yml b/.github/actions/github/pull-request/get-last-author/action.yml new file mode 100644 index 00000000..98c28ed8 --- /dev/null +++ b/.github/actions/github/pull-request/get-last-author/action.yml @@ -0,0 +1,31 @@ +name: Get last merget PullRequest author +description: get last merget pull request author + +inputs: + sourceDirectory: + default: tmp/source + description: Commit author GitGup token + required: true + githubToken: + description: GitHup token + required: true + +outputs: + lastPrAuthor: + description: Get branch name + value: ${{ steps.pr_author.outputs.lastPrAuthor }} + +runs: + using: composite + + steps: + - name: Get last merged PR author login + shell: bash + working-directory: ${{ inputs.sourceDirectory }} + id: pr_author + env: + GH_TOKEN: ${{ inputs.githubToken }} + 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 "lastPrAuthor=$LAST_PR_AUTHOR" >> $GITHUB_OUTPUT diff --git a/.github/actions/github/push/create/action.yml b/.github/actions/github/push/create/action.yml new file mode 100644 index 00000000..0b83944f --- /dev/null +++ b/.github/actions/github/push/create/action.yml @@ -0,0 +1,25 @@ +name: Git push +description: gith push + +inputs: + targetDirectory: + default: tmp/target + description: TargetDirectory + required: true + githubToken: + description: GitHup token + required: true + branchName: + description: branchName + required: true + +runs: + using: composite + + steps: + - shell: bash + working-directory: ${{ inputs.targetDirectory }} + env: + GITHUB_TOKEN: ${{ inputs.githubToken }} + run: | + git push --set-upstream origin ${{ inputs.branchName }} diff --git a/.github/actions/github/utils/get-new-branch-name/action.yml b/.github/actions/github/utils/get-new-branch-name/action.yml new file mode 100644 index 00000000..a090f32c --- /dev/null +++ b/.github/actions/github/utils/get-new-branch-name/action.yml @@ -0,0 +1,16 @@ +name: Get new branch name +description: get new branch name with now date + +outputs: + branchName: + description: Get last merged PR author + value: ${{ steps.branch_name.outputs.branchName }} + +runs: + using: composite + + steps: + - name: Get new branch name + shell: bash + id: branch_name + run: echo "branchName=feat/new-release-$(date +%Y%m%d%H%M%S)" >> $GITHUB_OUTPUT diff --git a/.github/workflows/synchronization.yaml b/.github/workflows/synchronization.yaml new file mode 100644 index 00000000..33713792 --- /dev/null +++ b/.github/workflows/synchronization.yaml @@ -0,0 +1,126 @@ +name: PersonaClick Synchronization + +env: + TARGET_REPO: "PersonaClick/workflow" + SYNC_IGNORE: ".git,.idea,LICENSE,.github/workflows/synchronization.yaml" + REPLACMENT_EXTENTIONS: "*.ts,*.sh,*.yaml" + REPLACEMENT_CONTENTS: "https://api.rees46.com/|https://api.personaclick.com/,com.rees46:rees46-sdk|com.personaclick:personaclick-sdk,api.rees46.com|api.personaclick.com,rees46.com|personaclick.com,rees46|personaClick,REES46|PersonaClick,Rees46|PersonaClick" + +on: + pull_request: + types: + - closed + branches: + - master + workflow_dispatch: + +jobs: + run: + if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch' + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + path: tmp/source + env: + GITHUB_TOKEN: ${{ secrets.JADE_SMITH_BOT_TOKEN }} + + - name: Check out remote repository + uses: actions/checkout@v4 + with: + repository: ${{ env.TARGET_REPO }} + token: ${{ secrets.JADE_SMITH_BOT_TOKEN }} + path: tmp/target + + - uses: actions/create-github-app-token@v1 + id: appTokenStep + with: + app-id: ${{ vars.PERSONACLICK_COURIER_ID }} + private-key: ${{ secrets.PERSONACLICK_COURIER_SECRET }} + owner: PersonaClick + + - name: Clean target directory except excluded files + working-directory: tmp/target + run: | + IFS=',' read -r -a ignored_files <<< "$SYNC_IGNORE" + + exclude_conditions="" + for ignored_file in "${ignored_files[@]}"; do + exclude_conditions=" $exclude_conditions ! -name \"$ignored_file\"" + done + + eval find . -mindepth 1 -maxdepth 1 $exclude_conditions -exec rm -rf {} + + + # TODO need to separete .github/workflows/synchronization.yaml into personal directory + - name: Sync files to remote repository + 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 tmp/source/ tmp/target/ $exclude_conditions + + - name: Apply changes to files + working-directory: tmp/target + 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" {} + + + - name: Copy files from targe dir + run: | + rsync -a tmp/target/ . + + - name: Debug current dir + run: | + git add . + + - 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 }} + + - uses: rees46/workflow/.github/actions/github/push/create@master + with: + branchName: ${{ steps.newBranchNameStep.outputs.branchName }} + githubToken: ${{ steps.appTokenStep.outputs.token }} + + - uses: rees46/workflow/.github/actions/github/commit/create@master + with: + branchName: ${{ steps.newBranchNameStep.outputs.branchName }} + githubToken: ${{ steps.appTokenStep.outputs.token }} + targetRepository: ${{ env.TARGET_REPO }} + + - 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 }} diff --git a/.gitignore b/.gitignore index 69880ddc..aeab77ca 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,4 @@ dist # Env .env +tmp/