Copy to repo #8
This file contains hidden or 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 to repo | |
on: | |
workflow_call: | |
inputs: | |
source-directory: | |
description: "Source directory" | |
required: true | |
default: "" | |
type: string | |
destination-repo: | |
description: "Destination repository" | |
required: true | |
default: "" | |
type: string | |
workflow_dispatch: | |
inputs: | |
source-directory: | |
description: "Source directory" | |
required: true | |
default: "" | |
type: string | |
destination-repo: | |
description: "Destination repository" | |
required: true | |
default: "" | |
type: string | |
jobs: | |
copy-to-repo: | |
runs-on: ubuntu-latest | |
if: github.repository_owner == 'restatedev' | |
steps: | |
- name: Checkout examples repo | |
uses: actions/checkout@v4 | |
with: | |
path: examples | |
- name: Checkout ${{ inputs.destination-repo }} repo | |
uses: actions/checkout@v4 | |
with: | |
repository: restatedev/${{ inputs.destination-repo }} | |
path: destination | |
token: ${{ secrets.COPY_TO_REPO_TOKEN }} | |
- name: Copy over the template to the destination repo | |
shell: bash | |
# We use git archive here because it respects .gitignore and friends | |
run: | | |
cd $GITHUB_WORKSPACE/examples/${{ inputs.source-directory }} | |
git archive HEAD -o temp.zip | |
cd $GITHUB_WORKSPACE/destination | |
unzip -o $GITHUB_WORKSPACE/examples/${{ inputs.source-directory }}/temp.zip | |
- name: Commit and push changes (if any) | |
shell: bash | |
env: | |
CI_COMMIT_MESSAGE: Update template | |
CI_COMMIT_AUTHOR: github-actions[bot] | |
CI_COMMIT_EMAIL: [email protected] | |
run: | | |
cd destination | |
git config --global user.name "${{ env.CI_COMMIT_AUTHOR }}" | |
git config --global user.email "${{ env.CI_COMMIT_EMAIL }}" | |
if [[ `git status --porcelain --untracked-files=no` ]]; then | |
# Changes | |
git add . | |
git commit -m "${{ env.CI_COMMIT_MESSAGE }}" | |
git push | |
else | |
# No changes | |
echo "no changes to the destination" | |
exit 0 | |
fi |