Update source images #1183
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: Update source images | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '45 * * * *' | |
jobs: | |
update: | |
name: Update source code | |
runs-on: ubuntu-latest | |
steps: | |
- name: Fetch data | |
id: fetch | |
run: | | |
# Fetch your JSON manifest from GitHub (or wherever it’s hosted) | |
data=$(curl -s https://raw.githubusercontent.com/flow-php/flow/refs/heads/1.x/manifest.json) | |
# Use 'jq' to extract the `.packages[].name` fields as a space-separated list | |
repos=$(echo "$data" | jq -r '.packages[].name') | |
echo "Here are the listed repos: $repos" | |
echo "::set-output name=repos::$repos" | |
- name: Set up PHP | |
uses: shivammathur/[email protected] | |
with: | |
php-version: 8.2 | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
persist-credentials: false | |
fetch-depth: 0 | |
- name: Download dependencies | |
run: | | |
composer install --no-interaction --prefer-dist --optimize-autoloader | |
- name: Compare & Print | |
run: | | |
# Loop over each repository name we got from the 'Fetch data' step | |
for REPOSITORY in ${{ steps.fetch.outputs.repos }} | |
do | |
echo "::group::$REPOSITORY" | |
# Clone the repository (1.x branch as in the original example) | |
git clone --branch 1.x https://${{ secrets.GH_TOKEN }}:[email protected]/$REPOSITORY output | |
cd output | |
# Count how many commits happened since the last tag | |
count=$(git rev-list --count $(git describe --abbrev=0 --tags)..HEAD) | |
cd .. | |
rm -rf output | |
# Example call to your PHP script | |
php ./src/image.php $REPOSITORY $count | |
echo "::endgroup::" | |
done | |
- name: Commit changes | |
run: | | |
echo "::group::git status" | |
git status | |
echo "::endgroup::" | |
git add -N docs | |
if [[ $(git diff --numstat | wc -l) -eq 0 ]]; then | |
echo "No changes found. Exiting." | |
exit 0; | |
fi | |
git config --local user.email "[email protected]" | |
git config --local user.name "Flow PHP Bot" | |
echo "::group::git push" | |
git add docs/* | |
git commit -m "Update images with new data" | |
echo "::endgroup::" | |
- name: Push changes | |
uses: ad-m/github-push-action@master | |
with: | |
github_token: ${{ secrets.GH_TOKEN }} | |