Merge pull request #120 from linkorb/repo-ansible-run #1
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
# Managed by https://github.com/linkorb/repo-ansible. Manual changes will be overwritten. | |
name: Auto-run repo-ansible | |
on: | |
workflow_dispatch: | |
pull_request_target: | |
paths: | |
- 'repo.yaml' | |
- 'docs/partials/*.md' | |
push: | |
branches: | |
- main | |
paths: | |
- 'repo.yaml' | |
- 'docs/partials/*.md' | |
permissions: | |
contents: write # allow git commits & push | |
pull-requests: write # allow comments on PR | |
env: | |
# XXX alternative to missing ternary syntax | |
IS_PULL_REQUEST: ${{ github.event_name == 'pull_request_target' && '1' || '0' }} | |
jobs: | |
run: | |
runs-on: ubuntu-latest | |
steps: | |
- if: ${{ env.IS_PULL_REQUEST == '0' }} | |
uses: actions/checkout@v4 | |
- if: ${{ env.IS_PULL_REQUEST == '1' }} | |
uses: actions/checkout@v4 | |
with: | |
ref: refs/pull/${{ github.event.pull_request.number }}/merge | |
- name: repo-ansible | |
run: | | |
docker pull ghcr.io/linkorb/repo-ansible:latest >/dev/null | |
docker run --rm -v "$PWD":/app ghcr.io/linkorb/repo-ansible:latest | tee /tmp/repo_ansible_output | |
export OUTPUT=$(cat /tmp/repo_ansible_output) | |
{ | |
echo 'REPO_ANSIBLE_OUTPUT<<EOF' | |
echo "$OUTPUT" | |
echo EOF | |
} >> "$GITHUB_ENV" | |
if ! echo "$OUTPUT" | grep "changed=0"; then | |
echo "REPOSITORY_CHANGED=1" >> "$GITHUB_ENV" | |
fi | |
- if: ${{ env.IS_PULL_REQUEST == '0' }} | |
name: commit changes | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git add . | |
if git commit -m "chore: automatic repo-ansible run #0000"; then | |
git push | |
fi | |
- if: ${{ env.IS_PULL_REQUEST == '1' && env.REPOSITORY_CHANGED == '1' }} | |
name: bot comment about repo-ansible detected changes | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const changes = process.env.REPO_ANSIBLE_OUTPUT | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: `Once PR is merged, repo-ansible will run on main and the following changes will apply | |
\`\`\`shell | |
${changes} | |
\`\`\` | |
` | |
}) |