Don't suggest not to read README in README (#295) #16
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
# This workflow is used to automatically update the `cargo-generate` branch. If you copied the | |
# template, you can safely delete this. :) | |
# | |
# BE VERY CAREFUL about what this workflow runs, since IT HAS THE ABILITY TO DELETE THE ENTIRE | |
# REPOSITORY'S CONTENTS. For this reason, stick to pre-installed tools and trusted actions (such as | |
# those hosted from the `actions` organization.) | |
name: Update `cargo-generate` branch | |
on: | |
# Update `cargo-generate` from `main` every time `main` is updated. | |
push: | |
branches: main | |
# Allow this workflow to be manually triggered. | |
workflow_dispatch: | |
# This workflows also has write-access for content and workflow, but it is through | |
# CARGO_GENERATE_PAT. | |
permissions: | |
# We need write permissions to create new issues. | |
issues: write | |
jobs: | |
update: | |
runs-on: ubuntu-latest | |
# Only run this job on the source repository, skipping forks, unless it was manually triggered. | |
if: ${{ github.repository == 'TheBevyFlock/bevy_quickstart' || github.event_name == 'workflow_dispatch' }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
# Fetch entire history, since we need it all to successfully merge. | |
fetch-depth: 0 | |
# Specify a personal access token, since the default one does not let workflows modify | |
# the `.github/workflows` folder. This PAT needs write permissions for Contents and | |
# Workflows. I recommend creating a scoped token that only has access to this repository. | |
token: ${{ secrets.CARGO_GENERATE_PAT }} | |
- name: Configure Git user | |
env: | |
# From https://github.com/actions/checkout/pull/1707. | |
NAME: github-actions[bot] | |
EMAIL: 41898282+github-actions[bot]@users.noreply.github.com | |
run: | | |
git config user.name "${NAME}" | |
git config user.email "${EMAIL}" | |
- name: Switch to `cargo-generate` branch | |
run: git checkout cargo-generate | |
- name: Merge `main` branch into `cargo-generate` | |
id: merge | |
# We use `--no-edit` to prevent any editor from being opened, since we can't close it. | |
run: git merge main --no-edit --verbose | |
- name: Handle merge conflict | |
# Only run this if merging failed. | |
if: ${{ failure() && steps.merge.outcome == 'failure' }} | |
env: | |
TITLE: Failed to auto-update `cargo-generate` | |
BODY: | | |
There were merge conflicts while trying to update `cargo-generate` from `main`. You can | |
do it manually by running: | |
```bash | |
# Update your local copy of the `main` branch. | |
git switch main | |
git pull | |
# Checkout the `cargo-generate` branch. | |
git checkout cargo-generate | |
# Merge changes from `main` to `cargo-generate`. You will have to fix merge conflicts. | |
git merge main | |
``` | |
<details> | |
<summary><code>git status</code></summary> | |
``` | |
GIT_STATUS_IDENTIFIER | |
``` | |
</details> | |
<details> | |
<summary><code>git diff --diff-filter=U</code></summary> | |
```diff | |
GIT_DIFF_IDENTIFIER | |
``` | |
</details> | |
_This is an automated message created by `cargo-generate.yaml`._ | |
# This is required to use the `gh` CLI. | |
GH_TOKEN: ${{ github.token }} | |
run: | | |
# Get a list of the IDs of open issues created by this action, then count them using JQ. | |
OPEN_ISSUES="$( | |
gh issue list \ | |
--search "is:issue is:open author:app/github-actions in:title ${TITLE}" \ | |
--json id \ | |
--jq '. | length' | |
)" | |
# If an issue already exists, do not create another. | |
if [[ "${OPEN_ISSUES}" -gt 0 ]]; then | |
echo 'An issue already exists on merge conflicts! Exiting without creating another.' | |
exit 0 | |
fi | |
GIT_STATUS="$(git status)" | |
# Filter the diff to only include files with merge conflicts. | |
GIT_DIFF="$(git diff --diff-filter=U)" | |
# Replace `GIT_STATUS_IDENTIFIER` and `GIT_DIFF_IDENTIFIER` with their outputs. | |
BODY="${BODY/GIT_STATUS_IDENTIFIER/"${GIT_STATUS}"}" | |
BODY="${BODY/GIT_DIFF_IDENTIFIER/"${GIT_DIFF}"}" | |
# Create the issue. | |
gh issue create --title "${TITLE}" --body "${BODY}" | |
- name: Push changes | |
# Only run if merging succeeded. | |
if: ${{ success() && steps.merge.outcome == 'success' }} | |
run: git push |