Skip to content

Commit afa69ee

Browse files
authored
Associate GitHub actions to PR tags (#47)
Closes #46
1 parent 6dbfaf1 commit afa69ee

7 files changed

Lines changed: 168 additions & 2 deletions

File tree

.github/workflows/greetings.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Greetings
2+
3+
on: [pull_request, issues]
4+
5+
jobs:
6+
greeting:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/first-interaction@v1
10+
continue-on-error: true
11+
with:
12+
repo-token: ${{ secrets.GITHUB_TOKEN }}
13+
issue-message: "Thank you for collaborating with the project by giving us feedback!"
14+
pr-message: "Thank you for collaborating with the project to help us improve! We hope this CLI is useful to you. Cheers!"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Pull Request Approved
2+
3+
on:
4+
pull_request_review:
5+
types: [submitted]
6+
7+
concurrency: pr-${{ github.event.pull_request.id }}
8+
9+
jobs:
10+
check-labels:
11+
runs-on: ubuntu-latest
12+
if: github.event.pull_request.mergeable == true && github.event.review.state == 'approved'
13+
steps:
14+
- name: Warn about missing labels
15+
if: ${{ !contains(github.event.pull_request.labels.*.name, 'release') && !contains(github.event.pull_request.labels.*.name, 'documentation') }}
16+
uses: thollander/actions-comment-pull-request@v1
17+
with:
18+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19+
message: "This pull request hasn't been labeled as `release` nor `documentation`. Please ensure this is intentional before merging."
20+
comment_tag: label-warn

.github/workflows/npm-pr.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: NodeJS CI with NPM (PR)
2+
3+
on:
4+
pull_request:
5+
types: [ opened, synchronize, ready_for_review, review_requested, labeled ]
6+
7+
concurrency: pr-${{ github.event.pull_request.id }}
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- uses: actions/setup-node@v3
15+
with:
16+
node-version: 16
17+
- run: npm ci
18+
19+
check-labels:
20+
runs-on: ubuntu-latest
21+
if: github.event.pull_request.mergeable == true
22+
steps:
23+
- name: Warn about missing labels
24+
if: ${{ !contains(github.event.pull_request.labels.*.name, 'release') && !contains(github.event.pull_request.labels.*.name, 'documentation') }}
25+
uses: thollander/actions-comment-pull-request@v2
26+
with:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
message: "This pull request hasn't been labeled as `release` nor `documentation`. Please ensure this is intentional before merging."
29+
comment_tag: label-warn

.github/workflows/npm-publish.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ jobs:
1616
with:
1717
node-version: 16
1818
- run: npm ci
19-
#- run: npm test
2019

2120
publish-npm:
2221
needs: build

.github/workflows/npm-push.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: NodeJS CI with NPM (Merge)
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
check-pr-labels:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
pull-requests: read
12+
outputs:
13+
labels: ${{ steps.get-pr.outputs.pr_labels }}
14+
steps:
15+
- name: Get Pull Request information
16+
uses: 8BitJonny/gh-get-current-pr@2.2.0
17+
id: get-pr
18+
19+
build:
20+
runs-on: ubuntu-latest
21+
needs: [check-pr-labels]
22+
if: contains(needs.check-pr-labels.outputs.labels, 'release')
23+
steps:
24+
- uses: actions/checkout@v3
25+
- uses: actions/setup-node@v3
26+
with:
27+
node-version: 16
28+
- run: npm ci
29+
30+
publish-npm:
31+
runs-on: ubuntu-latest
32+
needs: [build, check-pr-labels]
33+
if: contains(needs.check-pr-labels.outputs.labels, 'release')
34+
steps:
35+
- uses: actions/checkout@v3
36+
- uses: actions/setup-node@v3
37+
with:
38+
node-version: 16
39+
registry-url: https://registry.npmjs.org/
40+
- run: npm ci
41+
- run: npm publish
42+
env:
43+
NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}

.github/workflows/update-wiki.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Sync Docs (Merge)
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
check-pr-labels:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
pull-requests: read
12+
outputs:
13+
labels: ${{ steps.get-pr.outputs.pr_labels }}
14+
steps:
15+
- name: Get Pull Request information
16+
uses: 8BitJonny/gh-get-current-pr@2.2.0
17+
id: get-pr
18+
19+
update-wiki:
20+
runs-on: ubuntu-latest
21+
needs: [check-pr-labels]
22+
if: contains(needs.check-pr-labels.outputs.labels, 'documentation')
23+
steps:
24+
- name: Setup variables
25+
run: |
26+
echo "REPO_DEST=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}').wiki" >> $GITHUB_ENV
27+
shell: bash
28+
- name: Checkout OpenApi NodeJS CLI Repository
29+
run: git clone https://github.com/sngular/openapi-nodejs-cli.git openapi-nodejs-cli
30+
- name: Checkout OpenApi NodeJS CLI Wiki Repository
31+
run: git clone https://github.com/sngular/openapi-nodejs-cli.wiki.git wiki
32+
- name: Copy docs and consolidate links
33+
run: |
34+
cp -rf openapi-nodejs-cli/docs/* wiki/
35+
cd wiki
36+
grep -lr "(.*\.md)" *|xargs -r sed -i 's/\.md//g'
37+
echo ">"
38+
git diff-index --quiet HEAD & git status -s
39+
echo "<"
40+
git status
41+
echo ">"
42+
git diff-index --quiet HEAD & git status -s
43+
echo "<"
44+
echo "TO_BE_CANCELLED=$(if [[ $(git diff-index --quiet HEAD & git status -s) ]]; then echo "false"; else echo "true"; fi)" >> $GITHUB_ENV
45+
echo "$TO_BE_CANCELLED"
46+
- name: Setup git user
47+
if: ${{ env.TO_BE_CANCELLED == 'false' }}
48+
run: |
49+
git config --global user.name ${{ github.actor }}
50+
- name: Sync Wiki
51+
if: ${{ env.TO_BE_CANCELLED == 'false' }}
52+
run: |
53+
cd wiki
54+
git status
55+
git add .
56+
git commit -m "openapi-nodejs-cli documentation | GitHub Actions $GITHUB_WORKFLOW $GITHUB_RUN_NUMBER"
57+
git remote add origin-wiki "https://${{secrets.GITBOT_TOKEN}}@github.com/sngular/openapi-nodejs-cli.wiki.git"
58+
git push origin-wiki main

CONTRIBUTING.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ project. We encourage you to follow them and help us create a better product!
3838
3. Increase the version number in any package.json files to the new
3939
version that this pull request would represent. The versioning scheme we
4040
follow is [SemVer](http://semver.org/).
41-
4. You may squash and merge the pull request once you have the sign-off of two
41+
4. If your Pull Request corresponds to a new release, label it as `release`. If
42+
it updates the documentation, label it as `documentation`. You can add both
43+
labels simultaneously if that is the case.
44+
5. You may squash and merge the pull request once you have the sign-off of two
4245
other developers. If you do not have permission to merge, you may request the
4346
second reviewer to merge the pull request for you.
4447

0 commit comments

Comments
 (0)