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: Copy content to other repository | |
on: | |
workflow_call: | |
inputs: | |
repo: | |
required: true | |
type: string | |
branch: | |
required: true | |
type: string | |
source_dir: | |
required: true | |
type: string | |
destination_dir: | |
required: true | |
type: string | |
commit_msg: | |
required: true | |
type: string | |
prerun: | |
required: false | |
type: string | |
secrets: | |
PAT: | |
required: true | |
jobs: | |
copy_content: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check if existing tokens branch exists | |
id: check_branch | |
env: | |
GH_TOKEN: ${{ secrets.PAT }} | |
run: echo "branch_exists=$(gh api repos/${{ inputs.repo }}/branches/${{ inputs.branch }} --jq '.name' | wc -l | xargs)" >> $GITHUB_OUTPUT | |
- name: Check if open PR exists | |
id: check_pr | |
env: | |
GH_TOKEN: ${{ secrets.PAT }} | |
run: echo "pr_exists=$(gh pr list -R ${{ inputs.repo }} -H ${{ inputs.branch }} --json number -q length)" >> $GITHUB_OUTPUT | |
- name: Checkout source repo | |
uses: actions/checkout@v4 | |
with: | |
path: "source" | |
- name: Checkout destination repo (Branch exists) | |
uses: actions/checkout@v4 | |
if: ${{ steps.check_branch.outputs.branch_exists != 0 }} | |
with: | |
path: "destination" | |
repository: ${{ inputs.repo }} | |
token: ${{ secrets.PAT }} | |
ref: ${{ inputs.branch }} | |
- name: Checkout destination repo (Branch doesn't exist) | |
uses: actions/checkout@v4 | |
if: ${{ steps.check_branch.outputs.branch_exists == 0 }} | |
with: | |
path: "destination" | |
repository: ${{ inputs.repo }} | |
token: ${{ secrets.PAT }} | |
- name: Create branch in destination repo | |
if: ${{ steps.check_branch.outputs.branch_exists == 0 }} | |
run: | | |
cd destination | |
git checkout -b ${{ inputs.branch }} | |
- name: Run pre-run command | |
if: inputs.prerun != '' | |
run: | | |
cd destination | |
eval ${{ inputs.prerun }} | |
- name: Get current date | |
id: date | |
run: echo "date=$(date +'%d %b %Y, %H:%M:%S')" >> $GITHUB_OUTPUT | |
- name: Copy files | |
# run: cp -r source/${{ inputs.source_dir }}/* destination/${{ inputs.destination_dir }} | |
- name: Stage destination changes | |
run: | | |
cd destination | |
git config --global user.name "zeta-icons-bot" | |
git config --global user.email "[email protected]" | |
git add -A | |
- run: cd destination; git diff | |
- name: Check if there are changes | |
id: changed | |
run: | | |
cd destination | |
git diff | |
git diff --quiet . || echo "changed=true" >> $GITHUB_OUTPUT | |
- name: Commit and push changes | |
if: steps.changed.outputs.changed == 'true' | |
run: | | |
git commit -m "deps(automated): ${{inputs.commit_msg}} ${{ steps.date.outputs.date }}" | |
git push --set-upstream origin ${{inputs.branch}} -f | |
- name: Open PR | |
uses: thecanadianroot/[email protected] | |
if: ${{ steps.check_pr.outputs.pr_exists == 0 }} | |
with: | |
token: ${{ secrets.PAT }} | |
base: main | |
head: ${{ inputs.branch }} | |
title: "deps(automated): ${{inputs.commit_msg}}" | |
labels: tokens | |
body: "${{inputs.commit_msg}} ${{ steps.date.outputs.date }}" | |
repository: ${{ inputs.repo }} | |
- name: Add comment to existing PR | |
env: | |
GH_TOKEN: ${{ secrets.PAT }} | |
if: ${{ steps.check_pr.outputs.pr_exists != 0 }} | |
run: gh pr comment -R ${{ inputs.repo }} ${{ inputs.branch }} --body "${{inputs.commit_msg}} ${{ steps.date.outputs.date }}" |