Supported versions auto-update #36
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: 'Supported versions auto-update' | |
on: | |
workflow_dispatch: # Allows to run the workflow manually from the Actions tab | |
schedule: | |
- cron: '0 0 1 * *' # Every month | |
permissions: | |
contents: write | |
issues: write | |
concurrency: | |
group: "${{ github.workflow }}-${{ github.head_ref || github.ref }}" | |
cancel-in-progress: true | |
env: | |
AUTHOR_NAME: github-actions | |
AUTHOR_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com | |
V_FILE: .supported-versions.json | |
UPDATE_BRANCH: auto/feature/increase-supported-version | |
ISSUE_TITLE: "[AUTO] update supported versions" | |
PR_TITLE: "Update supported versions" | |
ASSIGNEE_HANDLES: "yoanm" | |
SERVER_URL: ${{ github.server_url }} | |
REPO_NAME: ${{ github.repository }} | |
RUN_ID: ${{ github.run_id }} | |
jobs: | |
php: | |
name: PHP | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
issues: write | |
steps: | |
- name: Get current date/time | |
id: datetime | |
run: echo "value=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT | |
- name: "Checkout current repository" | |
uses: actions/checkout@v5 | |
with: | |
ref: ${{ github.event.repository.default_branch }} | |
fetch-depth: 0 | |
- name: Create/Switch to update branch | |
env: | |
BRANCH: ${{ env.UPDATE_BRANCH }} | |
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} | |
run: | | |
git checkout "${BRANCH}" || git checkout --track origin/${DEFAULT_BRANCH} -b "${BRANCH}" | |
- name: Update versions | |
id: update-versions | |
uses: yoanm/gha-php-supported-versions-auto-update@v0 | |
with: | |
path: ${{ env.V_FILE }} | |
- name: "Add / commit / push" | |
id: commit-and-push | |
if: ${{ steps.update-versions.outputs.updated == '1' }} | |
env: | |
DATE: ${{ steps.datetime.outputs.value }} | |
run: | | |
git config user.name "${AUTHOR_NAME}" | |
git config user.email "${AUTHOR_EMAIL}" | |
git add $V_FILE | |
if [ $(git diff --cached --name-only | wc -l) -gt 0 ]; then | |
echo "Pushing updated files:" | |
git diff --cached --color $V_FILE | |
git commit -m "Update PHP supported versions (${DATE})" -m "See ${SERVER_URL}/${REPO_NAME}/actions/runs/${RUN_ID}"; | |
git push --set-upstream origin "${UPDATE_BRANCH}"; | |
ISSUE_NEEDED=1 | |
else | |
echo "Nothing to commit !"; | |
ISSUE_NEEDED=0 | |
fi; | |
echo "issue-needed=${ISSUE_NEEDED}" >> $GITHUB_OUTPUT | |
- name: "Create issue" | |
if: ${{ steps.commit-and-push.outputs.issue-needed == 1 }} | |
env: | |
BODY_FILE: ${{ runner.temp }}/body-file.txt | |
GH_TOKEN: ${{ github.token }} | |
run: | | |
ISSUE_BODY_HEADER="Supported versions file needs to be updated !" | |
ISSUE_URL=$(gh issue list --search "state:open author:@me \"${ISSUE_TITLE}\"" --json url --jq '.[0].url') | |
if [[ -z "${ISSUE_URL}" ]]; then | |
echo "Creating new issue" | |
gh issue create --title "${ISSUE_TITLE}" --body "${ISSUE_BODY_HEADER}" --assignee "${ASSIGNEE_HANDLES}" > issue_url.txt | |
ISSUE_URL=$(cat issue_url.txt) | |
if [[ -z "${ISSUE_URL}" ]]; then | |
echo "::error::Unable to retrieve the issue URL !" | |
exit 1 | |
fi | |
ISSUE_ID=$(gh issue view "${ISSUE_URL}" --json number --jq '.number') | |
if [[ -z "${ISSUE_ID}" ]]; then | |
echo "::error::Unable to retrieve the issue ID !" | |
exit 1 | |
fi | |
echo "Update issue with proper link to create the PR" | |
PR_ENCODED_TITLE=$(jq -rn --arg x "${PR_TITLE}" '$x|@uri') | |
PR_BODY_ENCODED=$(jq -rn --arg x "Fix #${ISSUE_ID}" '$x|@uri') | |
echo "${ISSUE_BODY_HEADER}" > ${BODY_FILE} | |
echo "" >> ${BODY_FILE} | |
echo "Create PR [there](https://github.com/${REPO_NAME}/compare/${UPDATE_BRANCH}?quick_pull=1&assignees=${ASSIGNEE_HANDLES}&title=${PR_ENCODED_TITLE}&body=${PR_BODY_ENCODED})" >> ${BODY_FILE} | |
gh issue edit "${ISSUE_URL}" --body-file "${BODY_FILE}" | |
else | |
echo "Issue already exists: ${ISSUE_URL}" | |
fi |