diff --git a/.eslintignore b/.eslintignore index b962b906..bee883d9 100644 --- a/.eslintignore +++ b/.eslintignore @@ -14,3 +14,4 @@ dist-pkg pkg/harvester/index.ts pkg/harvester/store/* scripts/pkgfile.js +tmp diff --git a/.github/mergify.yml b/.github/mergify.yml index 781cdc23..75935719 100644 --- a/.github/mergify.yml +++ b/.github/mergify.yml @@ -1,43 +1,4 @@ pull_request_rules: -- name: Automatically open backport PR to release-harvester-v1.6 - conditions: - - base=main - actions: - backport: - branches: - - "release-harvester-v1.6" - assignees: - - "{{ author }}" - labels: - - "v1.6 backport PR" - -pull_request_rules: -- name: Automatically open backport PR to release-harvester-v1.5 - conditions: - - base=main - - label="require backport 1.5" - actions: - backport: - branches: - - "release-harvester-v1.5" - assignees: - - "{{ author }}" - labels: - - "v1.5 backport PR" - -- name: Automatically open backport PR to release-harvester-v1.0 - conditions: - - base=main - - label="require backport 1.0" - actions: - backport: - branches: - - "release-harvester-v1.0" - assignees: - - "{{ author }}" - labels: - - "v1.0 backport PR" - - name: Ask to resolve conflict conditions: - conflict diff --git a/.github/workflows/backport-label.yaml b/.github/workflows/backport-label.yaml new file mode 100644 index 00000000..ff0df575 --- /dev/null +++ b/.github/workflows/backport-label.yaml @@ -0,0 +1,58 @@ +name: "[PR Management] Add Backport Label" + +on: + pull_request: + types: [opened, reopened] + branches: [main] + +permissions: + pull-requests: write + +jobs: + add-backport-label: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Fetch release branches and PR labels + id: fetch_info + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + set -euo pipefail + + repo="${{ github.repository }}" + pr_number=${{ github.event.pull_request.number }} + + release_branches=$(gh api "repos/${repo}/branches" --paginate --jq '.[].name' | grep -E '^release-harvester-v[0-9]+\.[0-9]+$' || true) + + if [[ -z "$release_branches" ]]; then + echo "should_label=false" >> "$GITHUB_OUTPUT" + exit 0 + fi + + latest_branch=$(echo "$release_branches" | sort -Vr | head -n1) + version="${latest_branch#release-harvester-v}" + release_tag="v${version}.0" + + tags=$(gh api "repos/${repo}/releases" --paginate --jq '.[].tag_name') + if echo "$tags" | grep -Fxq "$release_tag"; then + echo "should_label=false" >> "$GITHUB_OUTPUT" + exit 0 + fi + + label="require backport/v${version}" + echo "should_label=true" >> "$GITHUB_OUTPUT" + echo "backport_label=$label" >> "$GITHUB_OUTPUT" + + pr_labels=$(gh pr view "$pr_number" --repo "$repo" --json labels --jq '.labels[].name' || echo "") + pr_labels_csv=$(echo "$pr_labels" | tr '\n' ',' | sed 's/,$//') + echo "pr_labels=$pr_labels_csv" >> "$GITHUB_OUTPUT" + + - name: Add backport label if needed + if: steps.fetch_info.outputs.should_label == 'true' && !contains(steps.fetch_info.outputs.pr_labels, steps.fetch_info.outputs.backport_label) + uses: actions-ecosystem/action-add-labels@v1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + labels: ${{ steps.fetch_info.outputs.backport_label }} diff --git a/.github/workflows/backport-request.yaml b/.github/workflows/backport-request.yaml new file mode 100644 index 00000000..a74a5ea0 --- /dev/null +++ b/.github/workflows/backport-request.yaml @@ -0,0 +1,44 @@ +name: "[PR Management] Request Backport via Mergify" + +on: + pull_request: + types: [closed] + branches: [main] + +permissions: + pull-requests: write + +jobs: + comment-backport: + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + steps: + - name: Post Mergify backport command + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + set -euo pipefail + + pr_number=${{ github.event.pull_request.number }} + repo="${{ github.repository }}" + + labels_json='${{ toJson(github.event.pull_request.labels.*.name) }}' + labels=$(echo "$labels_json" | jq -r '.[] // empty') + + echo "Labels on PR: $labels" + + matches=$(echo "$labels" | grep -oE '^require backport/v[0-9]+\.[0-9]+$' || true) + + if [[ -z "$matches" ]]; then + echo "No back‑port labels found — skipping." + exit 0 + fi + + branches=$(echo "$matches" \ + | sed -E 's/^require backport\/v/release-harvester-v/' \ + | sort -u | tr '\n' ' ') + branches=${branches%% } + + cmd="@Mergifyio backport $branches" + echo "Posting Mergify command: $cmd" + gh pr comment "$pr_number" --repo "$repo" --body "$cmd"