Versions updater #201
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: Versions updater | |
on: | |
push: | |
branches: [master] # Trigger workflow for any push to master | |
pull_request: | |
branches: [ master ] # Trigger workflow for any PR targeting master | |
workflow_dispatch: # Allow manual trigger | |
# inputs: # Enable this for signed commit in case GPG key is updated | |
# allowEmptyCommit: | |
# description: 'Allow empty commit (yes/no)' | |
# required: true | |
# default: 'no' | |
schedule: | |
- cron: '42 2 * * 0' # Trigger workflow once a week | |
env: | |
COMMIT_AUTHOR_NAME: github-actions | |
COMMIT_AUTHOR_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com | |
jobs: | |
actives: | |
name: "Update actives.json" | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: 'php-versions-repo' | |
steps: | |
- name: Get current date/time | |
id: datetime | |
run: echo "::set-output name=value::$(date +'%Y-%m-%d')" | |
working-directory: '/tmp' # Repository is not yet there => use tmp directory as working directory | |
- name: "Checkout php/web-php repository" | |
uses: actions/checkout@v2 | |
with: | |
repository: 'php/web-php' | |
path: 'web-php-repo' | |
- name: "Add custom script" | |
run: | | |
echo '<?php | |
include "include/branches.inc"; | |
echo json_encode(get_active_branches(), JSON_PRETTY_PRINT)."\n"; | |
' > generate_active_version.php | |
cat generate_active_version.php | |
working-directory: 'web-php-repo' | |
- name: "Generate active versions JSON file" | |
id: active_versions | |
run: | | |
php generate_active_version.php | |
echo "::set-output name=json::'$(php generate_active_version.php)'" | |
working-directory: 'web-php-repo' | |
- name: "Checkout yoanm/php-version repository" | |
uses: actions/checkout@v2 | |
with: | |
ref: '${{ github.head_ref || github.ref }}' | |
path: 'php-versions-repo' | |
token: '${{ secrets.PAT_COMMIT }}' | |
- name: "Update actives.json file" | |
run: | | |
php ../web-php-repo/generate_active_version.php | |
php ../web-php-repo/generate_active_version.php > actives.json | |
cat actives.json | |
- name: "Add / commit / push" | |
run: | | |
git config user.name "${{ env.COMMIT_AUTHOR_NAME }}" | |
git config user.email "${{ env.COMMIT_AUTHOR_EMAIL }}" | |
git add actives.json | |
if [ $(git diff --cached --name-only | wc -l) -gt 0 ]; then | |
echo "Pushing updated file:" | |
git diff --cached --color actives.json | |
git commit \ | |
-m "Update actives.json (${{ steps.datetime.outputs.value }})" \ | |
-m "See ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"; | |
git push origin; | |
else | |
echo "Nothing to commit !"; | |
fi; | |
working-directory: 'php-versions-repo' |