Skip to content

Commit 8ea9922

Browse files
authored
Merge pull request #1 from SAP-docs/workflows
add workflows
2 parents b5fa379 + acb1f20 commit 8ea9922

7 files changed

+331
-0
lines changed

Diff for: .github/workflows/community-id-requester.yaml

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: SAP Community profile URL requester
2+
3+
# What the execution context is:
4+
# The assignment of a label to an issue or pull request indicating
5+
# that the contribution was valuable.
6+
7+
# What it does:
8+
# Adds a comment to the issue or pull request asking the author for
9+
# their SAP Community ID.
10+
11+
# Why we need it:
12+
# So that we can properly recognize the contribution in SAP Community.
13+
14+
# What's important to know:
15+
# The label is specified at the start of the 'community-id-requester'
16+
# job as an environment variable LABEL, and also in the job-level condition.
17+
# Also, it adds a comment only after the first time the label is added, and
18+
# only if there are no other issues / pull requests already labeled.
19+
20+
on:
21+
pull_request_target:
22+
types: [labeled]
23+
issues:
24+
types: [labeled]
25+
26+
jobs:
27+
28+
community-id-requester:
29+
30+
env:
31+
LABEL: "contribution"
32+
runs-on: ubuntu-20.04
33+
if: contains(github.repositoryUrl, 'github.com') && github.event.label.name == 'contribution'
34+
35+
steps:
36+
37+
- id: token_gen
38+
name: Generate app installation token
39+
uses: machine-learning-apps/[email protected]
40+
with:
41+
APP_PEM: ${{ secrets.SAP_CODOC_APP_PEM_BASE64 }}
42+
APP_ID: ${{ secrets.SAP_CODOC_APP_ID }}
43+
44+
- id: checkout
45+
name: Check out the repo
46+
uses: actions/checkout@v3
47+
with:
48+
token: ${{ steps.token_gen.outputs.app_token }}
49+
50+
- id: issue_details
51+
name: Determine related details if issue
52+
if: github.event_name == 'issues'
53+
run: |
54+
echo "OBJECTTYPE=issue" >> $GITHUB_ENV
55+
echo "CONTRIBUTIONTYPE=feedback" >> $GITHUB_ENV
56+
echo "OBJECTNR=${{ github.event.issue.number }}" >> $GITHUB_ENV
57+
echo "CONTRIBUTOR=${{ github.event.issue.user.login }}" >> $GITHUB_ENV
58+
59+
- id: pull_request_details
60+
name: Determine related details if pull request
61+
if: github.event_name == 'pull_request_target'
62+
run: |
63+
echo "OBJECTTYPE=pr" >> $GITHUB_ENV
64+
echo "CONTRIBUTIONTYPE=content" >> $GITHUB_ENV
65+
echo "OBJECTNR=${{ github.event.pull_request.number }}" >> $GITHUB_ENV
66+
echo "CONTRIBUTOR=${{ github.event.pull_request.user.login }}" >> $GITHUB_ENV
67+
68+
- id: auth_gh
69+
name: Authenticate gh to repo
70+
run: echo -n ${{ steps.token_gen.outputs.app_token }} | gh auth login --with-token
71+
72+
- id: count_label_additions
73+
name: Count number of times label has been added
74+
run: |
75+
endpoint="repos/${{ github.repository }}/issues/$OBJECTNR/events"
76+
count=$(gh api --jq "[.[]|(select(.event==\"labeled\" and .label.name==\"$LABEL\"))] | length" $endpoint)
77+
echo "LABELADDITIONCOUNT=$count" >> $GITHUB_ENV
78+
79+
- id: count_previous_labeled_objects
80+
name: Count how many other issues / pull requests are so labeled
81+
run: |
82+
querystring="is:${OBJECTTYPE}+label:${LABEL}+author:${CONTRIBUTOR}+repo:${GITHUB_REPOSITORY}"
83+
result=$(gh api --jq '.items[] | [.number, .title] | @tsv' "/search/issues?q=$querystring")
84+
echo "$result"
85+
echo "OBJECTCOUNT=$(wc -l <<< $result)" | tee -a $GITHUB_ENV
86+
87+
- id: requester
88+
name: Ask for SAP Community profile URL if label added for first time and no prev labeled issue / pr
89+
if: env.LABELADDITIONCOUNT == 1 && env.OBJECTCOUNT <= 1
90+
run: |
91+
printf "Thank you for your valuable ${CONTRIBUTIONTYPE} contribution, @${CONTRIBUTOR}! So that we can [recognize your contribution in the SAP Community](https://github.com/SAP-docs/contribution-guidelines/blob/main/docs/recognition.md), please check your SAP Community user ID (this is a number) in your [personal settings page](https://community.sap.com/t5/user/myprofilepage/tab/personal-profile) and share it with us in a reply to this comment. Make sure you just include the number in the reply.\n\nYour user ID is displayed as follows:\n\n**Change display name for User ID N**\n\nwhere N is your user ID. For example, [53 is the user ID of the user 'qmacro'](https://community.sap.com/t5/user/viewprofilepage/user-id/53).\n\nPlease note that we are currently refactoring our profile and badge system on the SAP Community, and will start assigning badges again when that's complete." \
92+
| gh $OBJECTTYPE comment $OBJECTNR --body-file -

Diff for: .github/workflows/disallowed-content-checks.yaml

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Disallowed content checker
2+
3+
# What the execution context is:
4+
# A pull request on the main branch. Only relevant for users who
5+
# don't have admin access on the repository.
6+
7+
# What it does:
8+
# Checks to see if there are any files included in the pull request
9+
# that we cannot accept. Only files in the docs/ directory are open
10+
# to contribution.
11+
12+
# Why we need it:
13+
# So the repository remains stable and we can focus on documentation
14+
# contributions.
15+
16+
# What's important to know:
17+
# The filter used in the check_files_changed step is a negated one,
18+
# i.e. notice the use of the '!'. Read the filter like this: "The
19+
# disallowed files are any that DON'T match docs/**".
20+
21+
on:
22+
pull_request_target:
23+
branches: [main]
24+
25+
jobs:
26+
main:
27+
runs-on: ubuntu-20.04
28+
steps:
29+
30+
- id: token_gen
31+
name: Generate app installation token
32+
uses: machine-learning-apps/[email protected]
33+
with:
34+
APP_PEM: ${{ secrets.SAP_CODOC_APP_PEM_BASE64 }}
35+
APP_ID: ${{ secrets.SAP_CODOC_APP_ID }}
36+
37+
- id: checkout
38+
name: Check out the repo
39+
uses: actions/checkout@v3
40+
with:
41+
token: ${{ steps.token_gen.outputs.app_token }}
42+
43+
- id: auth_gh
44+
name: Authenticate gh to repo
45+
run: echo -n ${{ steps.token_gen.outputs.app_token }} | gh auth login --with-token
46+
47+
- id: determine_permission
48+
name: Look up actor's repository permission level
49+
run: |
50+
permission="$(gh api --jq .permission "/repos/$GITHUB_REPOSITORY/collaborators/$GITHUB_ACTOR/permission")"
51+
echo "repo_permission=$permission" >> $GITHUB_ENV
52+
53+
- id: check_files_changed
54+
name: Checks if disallowed content has been changed
55+
if: env.repo_permission != 'admin'
56+
uses: dorny/paths-filter@v2
57+
with:
58+
list-files: 'shell'
59+
filters: |
60+
disallowed:
61+
- '!docs/**'
62+
63+
- id: comment_on_disallowed
64+
if: steps.check_files_changed.outputs.disallowed == 'true'
65+
env:
66+
DOCS_LOC: "/${{ github.repository }}/tree/${{ github.base_ref }}/docs"
67+
REVERT_COMMAND: '`git checkout origin/main <filename>`'
68+
DISALLOWED_FILES: ${{ steps.check_files_changed.outputs.disallowed_files }}
69+
run: |
70+
printf "🚨 Hi there. It looks like you've included some files in this pull request that we can't accept in a contribution. Only actual documentation content, which is managed in the [docs]($DOCS_LOC) directory, is open for contribution.\n\nThe disallowed files that you submitted are:\n\n$DISALLOWED_FILES.\n\nYou'll need to revert all of the files you changed in that list using [GitHub Desktop](https://docs.github.com/en/free-pro-team@latest/desktop/contributing-and-collaborating-using-github-desktop/reverting-a-commit) or $REVERT_COMMAND. Once you get those files reverted, we can continue with the review process." \
71+
| gh pr comment ${{ github.event.pull_request.number }} --body-file -
72+
exit 1

Diff for: .github/workflows/markdown-checks.yaml

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Markdown linter
2+
3+
# What the execution context is:
4+
# The creation of a pull request. Can also be triggered manually.
5+
6+
# What it does:
7+
# Performs Markdown linting on the content of the pull request.
8+
9+
# Why we need it:
10+
# To maintain a level of consistency in the markup content.
11+
12+
# What's important to know:
13+
# As well as the rules defined in the configuration, a custom
14+
# rule is also employed to check title case.
15+
16+
on:
17+
workflow_dispatch:
18+
pull_request:
19+
branches: [main]
20+
paths: 'docs/**'
21+
22+
jobs:
23+
main:
24+
if: contains(github.repositoryUrl, 'github.com')
25+
runs-on: ubuntu-20.04
26+
steps:
27+
28+
- id: checkout_repo
29+
name: Check out the repository content
30+
uses: actions/checkout@v3
31+
32+
- id: check_files_changed
33+
uses: dorny/paths-filter@v2
34+
with:
35+
list-files: 'escape'
36+
filters: |
37+
changed:
38+
- 'docs/**'
39+
40+
- id: add_matcher
41+
name: Add the matcher for markdownlint style message output
42+
run: "echo ::add-matcher::.github/workflows/markdownlint/problem-matcher.json"
43+
44+
- id: install_linter
45+
name: Install linting tool, custom rule and rule helpers
46+
run: |
47+
npm install \
48+
--no-package-lock \
49+
--no-save \
50+
[email protected] markdownlint-rule-titlecase [email protected]
51+
52+
- id: run_linter
53+
if: steps.check_files_changed.outputs.changed_files
54+
name: Run linter with specific rules, on the docs/ content
55+
run: |
56+
npx markdownlint \
57+
--config .github/workflows/markdownlint/config.yaml \
58+
--rules .github/workflows/markdownlint/md901 \
59+
--rules markdownlint-rule-titlecase \
60+
${{ steps.check_files_changed.outputs.changed_files }}

Diff for: .github/workflows/markdownlint/config.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# All rules are inactive by default.
2+
default: false
3+
4+
# These specific rules are active.
5+
# See https://github.com/DavidAnson/markdownlint#rules--aliases for details.
6+
no-reversed-links: true
7+
no-missing-space-atx: true
8+
no-multiple-space-atx: true
9+
heading-increment-no-blockquote: true

Diff for: .github/workflows/markdownlint/md901.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// @ts-check
2+
3+
"use strict";
4+
5+
const { addErrorDetailIf, filterTokens } = require("markdownlint-rule-helpers");
6+
7+
module.exports = {
8+
"names": [ "MD901", "heading-increment-no-blockquote" ],
9+
"description": "Custom version of MD001. Heading levels should only increment by one level at a time, except if in a blockquote",
10+
"tags": [ "headings", "headers" ],
11+
"function": function MD901(params, onError) {
12+
let prevLevel = 0;
13+
filterTokens(params, "heading_open", function forToken(token) {
14+
const level = Number.parseInt(token.tag.slice(1), 10);
15+
if (token.line.match(/^\s*> ?/)) return;
16+
if (prevLevel && (level > prevLevel)) {
17+
addErrorDetailIf(onError, token.lineNumber,
18+
"h" + (prevLevel + 1), "h" + level);
19+
}
20+
prevLevel = level;
21+
});
22+
}
23+
};

Diff for: .github/workflows/markdownlint/problem-matcher.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"problemMatcher": [
3+
{
4+
"owner": "markdownlint",
5+
"pattern": [
6+
{
7+
"regexp": "([^:]*):(\\d+):?(\\d+)?\\s([\\w-\\/]*)\\s(.*)",
8+
"file": 1,
9+
"line": 2,
10+
"column": 3,
11+
"code": 4,
12+
"message": 5
13+
}
14+
]
15+
}
16+
]
17+
}

Diff for: .github/workflows/merged-pr-labeler.yaml

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Merged pull request labeler
2+
3+
# What the execution context is:
4+
# The merging (not just closing) of a pull request.
5+
6+
# What it does:
7+
# Assigns the 'valuable contribution' label.
8+
9+
# Why we need it:
10+
# To mark a valuable pull request contribution, and thus to cause the
11+
# SAP Community profile URL requester to be triggered.
12+
13+
# What's important to know:
14+
# The label to assign is defined at the start of the job, in the LABEL
15+
# environment variable. The label is not assigned if the actor is an administrator.
16+
17+
on:
18+
pull_request_target:
19+
types: [closed]
20+
21+
jobs:
22+
23+
assign-label-on-merge:
24+
if: contains(github.repositoryUrl, 'github.com') && github.event.pull_request.merged
25+
env:
26+
LABEL: "contribution"
27+
runs-on: ubuntu-20.04
28+
29+
steps:
30+
31+
- id: token_gen
32+
name: Generate app installation token
33+
uses: machine-learning-apps/[email protected]
34+
with:
35+
APP_PEM: ${{ secrets.SAP_CODOC_APP_PEM_BASE64 }}
36+
APP_ID: ${{ secrets.SAP_CODOC_APP_ID }}
37+
38+
- id: checkout
39+
name: Check out the repo
40+
uses: actions/checkout@v3
41+
with:
42+
token: ${{ steps.token_gen.outputs.app_token }}
43+
44+
- id: auth_gh
45+
name: Authenticate gh to repo
46+
run: echo -n ${{ steps.token_gen.outputs.app_token }} | gh auth login --with-token
47+
48+
- id: determine_permission
49+
name: Look up repository permission level for PR author
50+
run: |
51+
pr_author="$(gh api --jq .user.login "${{ github.event.pull_request._links.self.href }}")"
52+
permission="$(gh api --jq .permission "/repos/$GITHUB_REPOSITORY/collaborators/$pr_author/permission")"
53+
echo "pr_author=$pr_author"
54+
echo "repo_permission=$permission" | tee --append "$GITHUB_ENV"
55+
56+
- id: assign_label
57+
if: env.repo_permission != 'admin'
58+
run: gh pr edit ${{ github.event.number }} --add-label "$LABEL"

0 commit comments

Comments
 (0)