Monitor and Sync ps2exe.ps1 from another repository #38
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: Monitor and Sync ps2exe.ps1 from another repository | |
on: | |
schedule: | |
- cron: '0 0 * * *' # Daily check at midnight | |
workflow_dispatch: # Manual check | |
jobs: | |
check-and-sync: | |
runs-on: ubuntu-latest | |
steps: | |
# 1. Check out this repository | |
- name: Check out this repository | |
uses: actions/checkout@v4 | |
# 2. Download ps2exe.ps1 from the external repository | |
- name: Download ps2exe.ps1 from MScholtes/Win-PS2EXE | |
run: | | |
curl -s https://raw.githubusercontent.com/MScholtes/Win-PS2EXE/master/ps2exe.ps1 -o external_ps2exe.ps1 | |
# 3. Check if ps2exe.ps1 exists in your repository | |
- name: Check if ps2exe.ps1 exists | |
id: file_check | |
run: | | |
if [ -f src/ps2exe.ps1 ]; then | |
echo "ps2exe.ps1 exists." | |
echo "exists=true" >> $GITHUB_ENV | |
else | |
echo "ps2exe.ps1 does not exist." | |
echo "exists=false" >> $GITHUB_ENV | |
fi | |
# 4. If the file exists, compare it with the external version | |
- name: Compare the two files | |
if: env.exists == 'true' | |
id: file_compare | |
run: | | |
if diff src/ps2exe.ps1 external_ps2exe.ps1; then | |
echo "No differences found" | |
echo "changed=false" >> $GITHUB_ENV | |
else | |
echo "Differences found" | |
echo "changed=true" >> $GITHUB_ENV | |
fi | |
# 5. If the file does not exist or there are changes, prepare the update for a Pull Request | |
- name: Prepare for Pull Request | |
if: env.exists == 'false' || env.changed == 'true' | |
run: | | |
echo "Updating ps2exe.ps1 in repository." | |
mv external_ps2exe.ps1 src/ps2exe.ps1 # Overwrite the file or add it if missing | |
git config --global user.name "github-actions" | |
git config --global user.email "[email protected]" | |
git add -f src/ps2exe.ps1 | |
git commit -m "Update ps2exe.ps1 from MScholtes/Win-PS2EXE" || echo "No changes to commit." | |
# 6. Create a Pull Request if changes were made | |
- name: Create a pull request | |
if: env.changed == 'true' || env.exists == 'false' | |
uses: peter-evans/create-pull-request@v7 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
commit-message: "Sync ps2exe.ps1 from MScholtes/Win-PS2EXE" | |
branch: sync-ps2exe-update | |
title: "Update ps2exe.ps1 from Win-PS2EXE repository" | |
body: "Automated pull request to sync the latest changes from [MScholtes/Win-PS2EXE](https://github.com/MScholtes/Win-PS2EXE/blob/master/ps2exe.ps1) repository." |