diff --git a/.github/workflows/major-version-check.yml b/.github/workflows/major-version-check.yml new file mode 100644 index 00000000000..ea71edbe867 --- /dev/null +++ b/.github/workflows/major-version-check.yml @@ -0,0 +1,46 @@ +name: Major version in changeset + +on: + pull_request: + branches: + - main + types: + - labeled + - unlabeled + - opened + - synchronize + - reopened + +jobs: + check-changesets: + if: | + !contains(github.event.pull_request.labels.*.name, '🤖Skip Major Check') + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Fetch all branches + run: git fetch --all + + - name: Checkout the feature branch + run: git checkout "$GITHUB_HEAD_REF" -- + + - name: Check major versions in changeset entries + run: | + commits="origin/$GITHUB_BASE_REF...origin/$GITHUB_HEAD_REF" + changeset_files=$(git diff --name-only --diff-filter=d "$commits" -- ".changeset/*.md") + + if [[ -z "$changeset_files" ]]; then + echo "No changeset files detected" + exit 0 + fi + + if ! echo "$changeset_files" | xargs grep -qE "^\s*[\"'].*?[\"']\s*:\s*major\s*$"; then + echo "No major version upgrade detected" + exit 0 + else + echo "This PR contains a major version upgrade which is only used for breaking changes." + echo "If you are sure you want to perform this action, please add the '🤖Skip Major Check' label" + exit 1 + fi diff --git a/.github/workflows/migrator-comment.yml b/.github/workflows/migrator-comment.yml new file mode 100644 index 00000000000..ec90285d453 --- /dev/null +++ b/.github/workflows/migrator-comment.yml @@ -0,0 +1,52 @@ +name: Migrator comment in diff + +on: + pull_request: + types: + - labeled + - unlabeled + - opened + - synchronize + - reopened + +env: + COMMENT: 'generated by polaris-migrator DO NOT COPY' + +jobs: + check-diff: + if: | + !contains(github.event.pull_request.labels.*.name, '🤖Skip Comment Check') + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Fetch all branches + run: git fetch --all + + - name: Checkout the feature branch + run: git checkout "$GITHUB_HEAD_REF" -- + + - name: Check for generic migrator comment in diff + run: | + commits="origin/$GITHUB_BASE_REF...origin/$GITHUB_HEAD_REF" + files=$(git diff --name-only --diff-filter=d "$commits" -- "*.scss") + + if [ -n "$files" ]; then + echo "SCSS files where modified." + echo "$files" + else + echo "No SCSS files where modified." + exit 0 + fi + + filesWithComment=$(git diff --unified=0 --diff-filter=d "$commits" -- $(echo $files) | grep "^\+.*$COMMENT" || true) + + if [ -n "$filesWithComment" ]; then + echo "A migrator comment '$COMMENT' was added to a SCSS file in this PR." + echo "Please provide a description for any Stylelint disable comments." + echo "If this is not applicable, you can add the '🤖Skip Comment Check' label to this PR." + exit 1 + else + echo "All good, no migrator comments were added." + fi