diff --git a/.github/workflows/pr-merge.yml b/.github/workflows/pr-merge.yml new file mode 100644 index 0000000000..edf9dbc943 --- /dev/null +++ b/.github/workflows/pr-merge.yml @@ -0,0 +1,75 @@ +name: PR Merge +on: + pull_request: + types: + - closed + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + check-pr-label: + if: ${{ github.event.pull_request.merged }} + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Check for PR description label + id: check_pr_description_label + run: | + python scripts/process_message.py "${TEXT_BODY}" > processed_body.txt + processed_body=$(cat processed_body.txt) + proposed_version_impact=$(echo "$processed_body" | awk '/Major \\\(when you make incompatible API changes\\\)/,/Patch \\\(when you make backward compatible bug fixes\\\)/') + is_major=$(echo "$proposed_version_impact" | grep -qi '\[X\] Major'; echo $((1-$?))) + is_minor=$(echo "$proposed_version_impact" | grep -qi '\[X\] Minor'; echo $((1-$?))) + is_patch=$(echo "$proposed_version_impact" | grep -qi '\[X\] Patch'; echo $((1-$?))) + sum=$(($is_major + $is_minor + $is_patch)) + echo "sum=$sum" >> $GITHUB_OUTPUT + if [[ "$sum" -eq 0 ]]; then + echo "message=$(echo "@${MERGE_AUTHOR} Each PR must have a SEMVER impact label, remember to label the PR properly.")" >> $GITHUB_OUTPUT + elif [[ "$sum" -ge 2 ]]; then + echo "message=$(echo "@${MERGE_AUTHOR} Each PR can only have one SEMVER impact label, remember to label the PR properly.")" >> $GITHUB_OUTPUT + else + echo "message=$(echo "SEMVER impact selected.")" >> $GITHUB_OUTPUT + echo "chosen_label=$( + if [ "$is_major" -eq 1 ]; then + echo "r.Major" + elif [ "$is_minor" -eq 1 ]; then + echo "r.Minor" + elif [ "$is_patch" -eq 1 ]; then + echo "r.Patch" + fi + )" >> $GITHUB_OUTPUT + fi + + env: + TEXT_BODY: ${{ github.event.pull_request.body }} + MERGE_AUTHOR: ${{ github.event.pull_request.merged_by.login }} + + - name: Assign label based on version impact + uses: actions/github-script@v7 + with: + script: | + if (process.env.SUM != 1) { + github.rest.issues.createComment({ + issue_number: context.payload.pull_request.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: process.env.MESSAGE, + }); + } else { + github.rest.issues.addLabels({ + issue_number: context.payload.pull_request.number, + owner: context.repo.owner, + repo: context.repo.repo, + labels: [process.env.CHOSEN_LABEL] + }); + } + env: + SUM: ${{ steps.check_pr_description_label.outputs.sum }} + MESSAGE: ${{ steps.check_pr_description_label.outputs.message }} + CHOSEN_LABEL: ${{ steps.check_pr_description_label.outputs.chosen_label }} + + + \ No newline at end of file diff --git a/packages/core/src/utils/fsUtil.ts b/packages/core/src/utils/fsUtil.ts index b3719a09aa..11dd49307f 100644 --- a/packages/core/src/utils/fsUtil.ts +++ b/packages/core/src/utils/fsUtil.ts @@ -43,7 +43,10 @@ export function copySyncWithOptions(src: string, dest: string, options: CopyOpti const files = fs.readdirSync(src); files.forEach((file) => { const curSource = path.join(src, file); - const curDest = path.join(dest, file); + let curDest = path.join(dest, file); + if (file === 'gitignore') { + curDest = path.join(dest, '.gitignore'); + } if (fs.lstatSync(curSource).isDirectory()) { if (!fs.existsSync(curDest)) { diff --git a/packages/core/template/default/.gitignore b/packages/core/template/default/gitignore similarity index 97% rename from packages/core/template/default/.gitignore rename to packages/core/template/default/gitignore index abf44778d8..3b8cd63a6d 100644 --- a/packages/core/template/default/.gitignore +++ b/packages/core/template/default/gitignore @@ -20,4 +20,4 @@ _site/ # IDE configs .vscode/ .idea/* -*.iml \ No newline at end of file +*.iml