diff --git a/.github/workflows/auto-merge.yml b/.github/workflows/auto-merge.yml index f6f182d..c8f0e9d 100644 --- a/.github/workflows/auto-merge.yml +++ b/.github/workflows/auto-merge.yml @@ -6,6 +6,7 @@ on: types: [completed] permissions: + actions: write contents: write pull-requests: write @@ -27,10 +28,11 @@ jobs: head_repo="$(jq -r '.head.repo.full_name' <<<"$pr")" login="$(jq -r '.user.login' <<<"$pr")" association="$(jq -r '.author_association' <<<"$pr")" + base_ref="$(jq -r '.base.ref' <<<"$pr")" draft="$(jq -r '.draft' <<<"$pr")" - if [[ "$head_repo" != "$REPOSITORY" || "$draft" == "true" ]]; then - echo "Skipping forked or draft pull request." + if [[ "$head_repo" != "$REPOSITORY" || "$base_ref" != "main" || "$draft" == "true" ]]; then + echo "Skipping forked, non-main, or draft pull request." exit 0 fi @@ -39,5 +41,7 @@ jobs: exit 0 fi - gh pr merge "$PR_NUMBER" --repo "$REPOSITORY" --squash --delete-branch + gh pr merge "$PR_NUMBER" --repo "$REPOSITORY" --merge --delete-branch + merge_sha="$(gh pr view "$PR_NUMBER" --repo "$REPOSITORY" --json mergeCommit --jq '.mergeCommit.oid')" + gh workflow run cd.yml --repo "$REPOSITORY" --ref main -f ref="$merge_sha" diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index b1e419a..fcd401e 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -4,6 +4,12 @@ on: workflow_run: workflows: [CI] types: [completed] + workflow_dispatch: + inputs: + ref: + description: Commit SHA to package + required: true + type: string permissions: contents: read @@ -11,23 +17,26 @@ permissions: jobs: release-artifact: if: >- - github.event.workflow_run.conclusion == 'success' && + github.event_name == 'workflow_dispatch' || + (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main' && - github.event.workflow_run.event == 'push' + github.event.workflow_run.event == 'push') runs-on: ubuntu-latest + env: + RELEASE_REF: ${{ github.event_name == 'workflow_dispatch' && inputs.ref || github.event.workflow_run.head_sha }} steps: - uses: actions/checkout@v7 with: - ref: ${{ github.event.workflow_run.head_sha }} + ref: ${{ env.RELEASE_REF }} - uses: docker/setup-buildx-action@v4 - uses: docker/build-push-action@v7 with: context: . outputs: type=oci,dest=${{ runner.temp }}/local-llm-router.tar - tags: local-llm-router:${{ github.event.workflow_run.head_sha }} + tags: local-llm-router:${{ env.RELEASE_REF }} - uses: actions/upload-artifact@v7 with: - name: local-llm-router-${{ github.event.workflow_run.head_sha }} + name: local-llm-router-${{ env.RELEASE_REF }} path: ${{ runner.temp }}/local-llm-router.tar retention-days: 14