diff --git a/.github/workflows/bootstrap-pull-request.yaml b/.github/workflows/bootstrap-pull-request.yaml index 5b3a165e0..40d133a26 100644 --- a/.github/workflows/bootstrap-pull-request.yaml +++ b/.github/workflows/bootstrap-pull-request.yaml @@ -49,6 +49,20 @@ jobs: git config --global user.email 'github-actions@github.com' git config --global user.name 'github-actions' + - uses: ./bootstrap-pull-request + id: when-namespace-branch-not-exists + continue-on-error: true + with: + overlay: overlay-${{ github.run_id }} + namespace: pr-${{ github.event.number }} + destination-repository: ${{ github.repository }} + error-if-namespace-branch-not-exists: true + prebuilt-branch: bootstrap-pull-request-e2e-prebuilt-${{ github.run_id }} + namespace-manifest: bootstrap-pull-request/tests/fixtures/namespace.yaml + substitute-variables: NAMESPACE=pr-${{ github.event.number }} + - if: steps.when-namespace-branch-not-exists.outcome != 'failure' + run: exit 1 + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: ref: ${{ github.head_ref }} # avoid "shallow update not allowed" error diff --git a/bootstrap-pull-request/README.md b/bootstrap-pull-request/README.md index b44bb04e9..ff85cab56 100644 --- a/bootstrap-pull-request/README.md +++ b/bootstrap-pull-request/README.md @@ -148,6 +148,19 @@ All placeholders will be replaced during copying the namespace manifest. For example, if `NAMESPACE=pr-123` is given by `substitute-variables` input, this action will replace `${NAMESPACE}` with `pr-123`. +## Consistency considerations + +### Namespace branch lost + +1. When a pull request is created, git-push-service action writes the service manifests to the namespace branch. +1. The namespace branch is deleted accidentally. +1. When the label is added to the pull request, this action creates the namespace branch with all services from the prebuilt branch. + It confuses the user because the namespace branch does not contain the change of the pull request. + +```yaml +error-if-namespace-branch-not-exists: ${{ github.event.action == 'labeled' }} +``` + ## Specification See [action.yaml](action.yaml). diff --git a/bootstrap-pull-request/action.yaml b/bootstrap-pull-request/action.yaml index 8933d0f93..0fdbe1f1a 100644 --- a/bootstrap-pull-request/action.yaml +++ b/bootstrap-pull-request/action.yaml @@ -15,6 +15,10 @@ inputs: destination-repository: description: Destination repository required: true + error-if-namespace-branch-not-exists: + description: Throw an error if the namespace branch does not exist + required: false + default: "false" prebuilt-branch: description: Name of prebuilt branch in the destination repository. This input will be required in the future release. required: false diff --git a/bootstrap-pull-request/src/main.ts b/bootstrap-pull-request/src/main.ts index ea39e6da2..408f52ce6 100644 --- a/bootstrap-pull-request/src/main.ts +++ b/bootstrap-pull-request/src/main.ts @@ -7,6 +7,7 @@ const main = async (): Promise => { namespace: core.getInput('namespace', { required: true }), sourceRepository: core.getInput('source-repository', { required: true }), destinationRepository: core.getInput('destination-repository', { required: true }), + errorIfNamespaceBranchNotExists: core.getBooleanInput('error-if-namespace-branch-not-exists', { required: true }), prebuiltBranch: core.getInput('prebuilt-branch', { required: false }) || undefined, destinationRepositoryToken: core.getInput('destination-repository-token', { required: true }), namespaceManifest: core.getInput('namespace-manifest') || undefined, diff --git a/bootstrap-pull-request/src/run.ts b/bootstrap-pull-request/src/run.ts index 20caf2e02..465a7aa9e 100644 --- a/bootstrap-pull-request/src/run.ts +++ b/bootstrap-pull-request/src/run.ts @@ -10,6 +10,7 @@ type Inputs = { namespace: string sourceRepository: string destinationRepository: string + errorIfNamespaceBranchNotExists: boolean prebuiltBranch: string | undefined destinationRepositoryToken: string namespaceManifest: string | undefined @@ -97,8 +98,19 @@ const checkoutPrebuiltBranch = async (inputs: Inputs, prebuiltBranch: string) => const checkoutNamespaceBranch = async (inputs: Inputs) => { const namespaceBranch = getNamespaceBranch(inputs) + if (inputs.errorIfNamespaceBranchNotExists) { + return await core.group( + `Checking out the namespace branch: ${namespaceBranch}`, + async () => + await git.checkout({ + repository: inputs.destinationRepository, + branch: namespaceBranch, + token: inputs.destinationRepositoryToken, + }), + ) + } return await core.group( - `Checking out the namespace branch: ${namespaceBranch}`, + `Checking out or init the namespace branch: ${namespaceBranch}`, async () => await git.checkoutOrInitRepository({ repository: inputs.destinationRepository,