mirror of
https://github.com/RWejlgaard/pez-infra.git
synced 2026-05-06 04:14:43 +00:00
add comments as well
This commit is contained in:
parent
b3f05c5f2d
commit
9ac4e244d4
1 changed files with 46 additions and 1 deletions
47
.github/workflows/validate-ansible.yml
vendored
47
.github/workflows/validate-ansible.yml
vendored
|
|
@ -33,6 +33,7 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
id-token: write
|
id-token: write
|
||||||
|
pull-requests: write
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
host: ${{ fromJson(needs.discover.outputs.hosts) }}
|
host: ${{ fromJson(needs.discover.outputs.hosts) }}
|
||||||
|
|
@ -74,7 +75,51 @@ jobs:
|
||||||
done
|
done
|
||||||
|
|
||||||
- name: Run playbook (check mode)
|
- name: Run playbook (check mode)
|
||||||
|
id: check
|
||||||
working-directory: ansible/
|
working-directory: ansible/
|
||||||
|
continue-on-error: true
|
||||||
env:
|
env:
|
||||||
ANSIBLE_HOST_KEY_CHECKING: "false"
|
ANSIBLE_HOST_KEY_CHECKING: "false"
|
||||||
run: ansible-playbook deploy.yml --limit "${{ matrix.host }}" --check --diff
|
run: |
|
||||||
|
ansible-playbook deploy.yml --limit "${{ matrix.host }}" --check --diff 2>&1 | tee playbook_output.txt
|
||||||
|
|
||||||
|
- name: Post recap as PR comment
|
||||||
|
uses: actions/github-script@v7
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
const fs = require('fs');
|
||||||
|
const output = fs.readFileSync('ansible/playbook_output.txt', 'utf8');
|
||||||
|
const host = '${{ matrix.host }}';
|
||||||
|
const recap = output.split('\n').filter(l => l.startsWith('PLAY RECAP') || l.includes(host + ' ')).join('\n');
|
||||||
|
const outcome = '${{ steps.check.outcome }}';
|
||||||
|
const header = outcome === 'failure'
|
||||||
|
? `## Ansible Check → ${host} — FAILED`
|
||||||
|
: `## Ansible Check → ${host}`;
|
||||||
|
const body = `${header}\n\`\`\`\n${recap}\n\`\`\``;
|
||||||
|
|
||||||
|
const { data: comments } = await github.rest.issues.listComments({
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
issue_number: context.issue.number,
|
||||||
|
});
|
||||||
|
const marker = `## Ansible Check → ${host}`;
|
||||||
|
const existing = comments.find(c => c.body.startsWith(marker) || c.body.startsWith(marker + ' —'));
|
||||||
|
if (existing) {
|
||||||
|
await github.rest.issues.updateComment({
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
comment_id: existing.id,
|
||||||
|
body,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await github.rest.issues.createComment({
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
issue_number: context.issue.number,
|
||||||
|
body,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
- name: Fail if check failed
|
||||||
|
if: steps.check.outcome == 'failure'
|
||||||
|
run: exit 1
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue