Skip to content

Commit

Permalink
Add reusable workflow and usage example (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
reakaleek authored Jan 15, 2025
1 parent 5f35669 commit 34910ca
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 27 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/comment-on-asciidoc-changes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Comment on PR for .asciidoc changes

on:
workflow_call: ~

jobs:
comment-on-asciidoc-change:
runs-on: ubuntu-latest

steps:
- name: Checkout the repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # This is important to fetch all history

- name: Check for changes in .asciidoc files
id: check-files
run: |
git fetch origin ${{ github.base_ref }}
if git diff --name-only origin/${{ github.base_ref }}..HEAD | grep -E '\.asciidoc$'; then
echo "asciidoc_changed=true" >> $GITHUB_OUTPUT
else
echo "asciidoc_changed=false" >> $GITHUB_OUTPUT
fi
- name: Add a comment if .asciidoc files changed
if: steps.check-files.outputs.asciidoc_changed == 'true'
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: 'It looks like this PR modifies one or more `.asciidoc` files. The documentation is currently under a documentation freeze. Please do not merge this PR. See the [migration guide](https://elastic.github.io/docs-builder/migration/index.html) to learn more.'
})
32 changes: 5 additions & 27 deletions docs/source/migration/freeze/gh-action.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,8 @@ on:

jobs:
comment-on-asciidoc-change:
runs-on: ubuntu-latest

steps:
- name: Checkout the repository
uses: actions/checkout@v3

- name: Check for changes in .asciidoc files
id: check-files
run: |
if git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -E '\.asciidoc$'; then
echo "asciidoc_changed=true" >> $GITHUB_ENV
else
echo "asciidoc_changed=false" >> $GITHUB_ENV
fi
- name: Add a comment if .asciidoc files changed
if: env.asciidoc_changed == 'true'
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: 'It looks like this PR modifies one or more `.asciidoc` files. The documentation is currently under a documentation freeze. Please do not merge this PR. See [link](link) to learn more.'
});
```
permissions:
contents: read
pull_request: write
uses: elastic/docs-builder/.github/workflows/comment-on-asciidoc-changes.yml@main
```

0 comments on commit 34910ca

Please sign in to comment.