-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: Add
prerun
to copy-content action (#56)
- Loading branch information
1 parent
de16c15
commit 10a6077
Showing
2 changed files
with
62 additions
and
28 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,9 @@ on: | |
commit_msg: | ||
required: true | ||
type: string | ||
prerun: | ||
required: false | ||
type: string | ||
secrets: | ||
PAT: | ||
required: true | ||
|
@@ -31,44 +34,73 @@ jobs: | |
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 code | ||
|
||
- name: Checkout source repo | ||
uses: actions/checkout@v4 | ||
with: | ||
path: "source" | ||
|
||
- name: Checkout destination repo (Branch exists) | ||
uses: actions/checkout@v4 | ||
# - name: Pull latest changes | ||
# run: git pull | ||
- name: Get current date | ||
id: date | ||
run: echo "date=$(date +%Y-%m-%d)" >> $GITHUB_OUTPUT | ||
- name: Push files if branch exists | ||
uses: dmnemec/copy_file_to_another_repo_action@main | ||
if: ${{ steps.check_branch.outputs.branch_exists != 0 }} | ||
env: | ||
API_TOKEN_GITHUB: ${{ secrets.PAT }} | ||
with: | ||
source_file: ${{ inputs.source_dir }} | ||
destination_repo: ${{ inputs.repo }} | ||
destination_folder: ${{ inputs.destination_dir }} | ||
destination_branch: ${{ inputs.branch }} | ||
user_email: "[email protected]" | ||
user_name: "Zeta Tokens Bot" | ||
commit_message: "deps(automated): ${{inputs.commit_msg}} ${{ steps.date.outputs.date }}" | ||
- name: Push files if branch does not exist | ||
uses: dmnemec/copy_file_to_another_repo_action@main | ||
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 }} | ||
env: | ||
API_TOKEN_GITHUB: ${{ secrets.PAT }} | ||
with: | ||
source_file: ${{ inputs.source_dir }} | ||
destination_repo: ${{ inputs.repo }} | ||
destination_folder: ${{ inputs.destination_dir }} | ||
destination_branch_create: ${{ inputs.branch }} | ||
user_email: "[email protected]" | ||
user_name: "Zeta Tokens Bot" | ||
commit_message: "deps(automated): ${{inputs.commit_msg}} ${{ steps.date.outputs.date }}" | ||
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 | ||
- name: Check if there are changes | ||
id: changed | ||
run: | | ||
cd destination | ||
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 }} | ||
|
@@ -80,6 +112,7 @@ jobs: | |
labels: tokens | ||
body: "${{inputs.commit_msg}} ${{ steps.date.outputs.date }}" | ||
repository: ${{ inputs.repo }} | ||
|
||
- name: Add comment to existing PR | ||
env: | ||
GH_TOKEN: ${{ secrets.PAT }} | ||
|
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