Skip to content

Commit 34910ca

Browse files
authored
Add reusable workflow and usage example (#200)
1 parent 5f35669 commit 34910ca

File tree

2 files changed

+40
-27
lines changed

2 files changed

+40
-27
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Comment on PR for .asciidoc changes
2+
3+
on:
4+
workflow_call: ~
5+
6+
jobs:
7+
comment-on-asciidoc-change:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Checkout the repository
12+
uses: actions/checkout@v4
13+
with:
14+
fetch-depth: 0 # This is important to fetch all history
15+
16+
- name: Check for changes in .asciidoc files
17+
id: check-files
18+
run: |
19+
git fetch origin ${{ github.base_ref }}
20+
if git diff --name-only origin/${{ github.base_ref }}..HEAD | grep -E '\.asciidoc$'; then
21+
echo "asciidoc_changed=true" >> $GITHUB_OUTPUT
22+
else
23+
echo "asciidoc_changed=false" >> $GITHUB_OUTPUT
24+
fi
25+
- name: Add a comment if .asciidoc files changed
26+
if: steps.check-files.outputs.asciidoc_changed == 'true'
27+
uses: actions/github-script@v6
28+
with:
29+
script: |
30+
github.rest.issues.createComment({
31+
owner: context.repo.owner,
32+
repo: context.repo.repo,
33+
issue_number: context.payload.pull_request.number,
34+
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.'
35+
})

docs/source/migration/freeze/gh-action.md

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,8 @@ on:
2626

2727
jobs:
2828
comment-on-asciidoc-change:
29-
runs-on: ubuntu-latest
30-
31-
steps:
32-
- name: Checkout the repository
33-
uses: actions/checkout@v3
34-
35-
- name: Check for changes in .asciidoc files
36-
id: check-files
37-
run: |
38-
if git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -E '\.asciidoc$'; then
39-
echo "asciidoc_changed=true" >> $GITHUB_ENV
40-
else
41-
echo "asciidoc_changed=false" >> $GITHUB_ENV
42-
fi
43-
44-
- name: Add a comment if .asciidoc files changed
45-
if: env.asciidoc_changed == 'true'
46-
uses: actions/github-script@v6
47-
with:
48-
script: |
49-
github.rest.issues.createComment({
50-
owner: context.repo.owner,
51-
repo: context.repo.repo,
52-
issue_number: context.payload.pull_request.number,
53-
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.'
54-
});
55-
```
29+
permissions:
30+
contents: read
31+
pull_request: write
32+
uses: elastic/docs-builder/.github/workflows/comment-on-asciidoc-changes.yml@main
33+
```

0 commit comments

Comments
 (0)