Lint PR #85
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "Lint PR" | |
on: | |
pull_request: | |
types: | |
- opened | |
- edited | |
- synchronize | |
schedule: | |
- cron: "0 8 * * *" | |
jobs: | |
pr-title: | |
if: ${{ github.event_name == 'pull_request' }} | |
runs-on: ubuntu-latest | |
steps: | |
# Please look up the latest version from | |
# https://github.com/amannn/action-semantic-pull-request/releases | |
- uses: amannn/[email protected] | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- uses: actions/github-script@v6 | |
with: | |
script: | | |
const AZDO_TICKET_REGEX = 'https:\/\/(dev\.azure\.com\/msazure|msazure\.visualstudio\.com)\/Microsoft%20Teams%20Extensibility'; | |
const pullRequest = context.payload.pull_request; | |
if(pullRequest.title.startsWith("feat")) { | |
const body = pullRequest.body; | |
const match = body?.match(AZDO_TICKET_REGEX); | |
if(!match) { | |
core.setFailed("Feat PR should contains AZDO tickets"); | |
} | |
} else if(pullRequest.title.startsWith("fix")) { | |
const body = pullRequest.body; | |
const match = body?.match(AZDO_TICKET_REGEX); | |
if(!match && !body) { | |
core.setFailed("Fix PR should contains AZDO tickets or descrptions"); | |
} | |
} | |
npm-audit: | |
if: ${{ github.event_name == 'pull_request' }} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup node | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 14 | |
- name: audit | |
run: npx lerna-audit | |
- name: check cache | |
run: | | |
git add . | |
VAR=$(git diff --cached --name-only) | |
if [ ! -z "$VAR" ] | |
then | |
echo $VAR | |
echo '======================================= Prompt Information ===============================================' | |
echo 'There found several moderate severity vulnerabilities in this repo, please check in the package or lock file to repo with: ' | |
echo 'npx lerna-audit' | |
exit 1 | |
fi | |
check-format: | |
if: ${{ github.event_name == 'pull_request' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout branch | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
ref: ${{ github.event.pull_request.head.ref }} | |
repository: ${{github.event.pull_request.head.repo.full_name}} | |
- name: Setup node | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 14 | |
- name: Setup Project | |
run: | | |
npm run setup | |
- name: prettier check files in PR on Fork | |
if: ${{ github.event.pull_request.head.repo.full_name != 'OfficeDev/TeamsFx' }} | |
run: | | |
git remote add upstream https://github.com/OfficeDev/TeamsFx.git | |
git fetch upstream ${{ github.event.pull_request.base.ref }} | |
VAR=$(realpath .github/scripts/lint-pr.sh) | |
npx lerna exec -- bash $VAR upstream/${{ github.event.pull_request.base.ref }} | |
- name: prettier check files in PR on local | |
if: ${{ github.event.pull_request.head.repo.full_name == 'OfficeDev/TeamsFx' }} | |
run: | | |
VAR=$(realpath .github/scripts/lint-pr.sh) | |
npx lerna exec -- bash $VAR origin/${{ github.event.pull_request.base.ref }} | |
- name: Check if there are changes | |
id: changes | |
run: | | |
git add . | |
VAR=$(git diff --cached --name-only) | |
if [ ! -z "$VAR" ] | |
then | |
echo $VAR | |
echo '======================================= Prompt Information ===============================================' | |
echo 'There may be some unformatted files in your PR, please run these commands on Git Bash terminal: ' | |
echo '1. npm run setup' | |
echo '2. VAR=$(realpath .github/scripts/lint-pr.sh) ' | |
echo '3. npx lerna exec -- bash $VAR ${your-PR-target-branch}' | |
echo 'please replace the ${your-PR-target-branch} as the target branch of your PR, such as origin/dev or upstream/dev' | |
exit 1 | |
fi | |
check-yaml-lint: | |
if: ${{ github.event_name == 'pull_request' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout branch | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
ref: ${{ github.event.pull_request.head.ref }} | |
repository: ${{github.event.pull_request.head.repo.full_name}} | |
- name: Install Yaml lint | |
run: | | |
pip install yamllint | |
- name: check yaml lint | |
run: | | |
TRAGET=origin/${{ github.event.pull_request.base.ref }} | |
VAR=$(git diff --diff-filter=MARC $TRAGET...HEAD --name-only -- templates/scenarios | grep -E '.yml.tpl$|.yml$' | xargs) | |
echo $VAR | |
if [ ! -z "$VAR" ] | |
then | |
yamllint $VAR | |
fi | |
check-sensitive-content: | |
if: ${{ github.event_name == 'pull_request' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout branch | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
ref: ${{ github.event.pull_request.head.ref }} | |
repository: ${{github.event.pull_request.head.repo.full_name}} | |
- name: prettier check files in PR on Fork | |
if: ${{ github.event.pull_request.head.repo.full_name != 'OfficeDev/TeamsFx' }} | |
run: | | |
git remote add upstream https://github.com/OfficeDev/TeamsFx.git | |
git fetch upstream ${{ github.event.pull_request.base.ref }} | |
git diff --diff-filter=MARC upstream/${{ github.event.pull_request.base.ref }}...HEAD --name-only >> diffFiles.txt | |
- name: prettier check files in PR on local | |
if: ${{ github.event.pull_request.head.repo.full_name == 'OfficeDev/TeamsFx' }} | |
run: | | |
git diff --diff-filter=MARC origin/${{ github.event.pull_request.base.ref }}...HEAD --name-only >> diffFiles.txt | |
- name: check content | |
run: | | |
touch diffFiles.txt | |
python .github/detect/sensitive-detect.py diff | |
schedule-check-sensitive-content: | |
if: ${{ github.event_name == 'schedule' && (github.ref == 'refs/heads/dev'|| github.ref == 'refs/heads/main' || github.ref == 'refs/heads/ga') }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: checkout branch | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.CD_PAT }} | |
ref: ${{ github.ref }} | |
- name: check content | |
run: | | |
python .github/detect/sensitive-detect.py repo | |
attension-on-version: | |
if: ${{ github.event_name == 'pull_request' && (github.event.pull_request.base.ref == 'main' || github.event.pull_request.base.ref == 'prerelease') && github.event.action != 'edited' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: checkout branch | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
token: ${{ secrets.GITHUB_TOKEN }} | |
ref: ${{ github.event.pull_request.head.ref }} | |
- name: check feature history | |
id: description | |
shell: "/bin/bash {0}" | |
run: | | |
head=$(git describe --first-parent --abbrev=0) | |
echo $head | |
history_cli=$(git log --pretty=format:"%s %h" $head...HEAD -- packages/cli | grep "^feat") | |
echo $history_cli | |
history_toolkit=$(git log --pretty=format:"%s %h" $head...HEAD -- packages/vscode-extension | grep "^feat") | |
echo $history_toolkit | |
echo -e '\nCLI feat commits:\n' "$history_cli" '\n\nExtension-toolkit feat commits:\n' "$history_toolkit" > feat_history.txt | |
breaking_change_cli=$(git log $head...HEAD -- packages/cli | grep -i "BREAKING CHANGE") | |
echo $breaking_change_cli | |
breaking_change_toolkit=$(git log $head...HEAD -- packages/vscode-extension| grep -i "BREAKING CHANGE") | |
echo $breaking_change_toolkit | |
echo -e '\nCLI BREAKING CHANGE:\n' "$breaking_change_cli" '\n\nExtension-toolkit BREAKING CHANGE:\n' "$breaking_change_toolkit" > breaking_change_history.txt | |
- name: Setup node | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 14 | |
- name: lerna expect rc version | |
run: | | |
npx lerna version --conventional-commits --conventional-prerelease --preid=rc --no-git-tag-version --allow-branch ${{ github.event.pull_request.head.ref }} --yes | |
npx lerna changed -l | awk '{ print $1 "\t" $2 }'> version_info.txt | |
- uses: edwardgeorge/file-outputs-action@main | |
id: test | |
with: | |
files: | | |
output1=version_info.txt | |
output2=breaking_change_history.txt | |
outpot3=feat_history.txt | |
- uses: riskledger/update-pr-description@v2 | |
with: | |
body: ${{join(steps.test.outputs.*, '')}} | |
token: ${{ secrets.GITHUB_TOKEN }} | |