Skip to content

Consider case of namespace branch lost #1816

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/bootstrap-pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ jobs:
git config --global user.email '[email protected]'
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
Expand Down
13 changes: 13 additions & 0 deletions bootstrap-pull-request/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
4 changes: 4 additions & 0 deletions bootstrap-pull-request/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions bootstrap-pull-request/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const main = async (): Promise<void> => {
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,
Expand Down
14 changes: 13 additions & 1 deletion bootstrap-pull-request/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Inputs = {
namespace: string
sourceRepository: string
destinationRepository: string
errorIfNamespaceBranchNotExists: boolean
prebuiltBranch: string | undefined
destinationRepositoryToken: string
namespaceManifest: string | undefined
Expand Down Expand Up @@ -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,
Expand Down
Loading