From 9f10b6be1ba36c9bed4d62859d929972dfb637fc Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Wed, 3 Mar 2021 19:41:45 +0100 Subject: [PATCH 1/2] Replace delete opt on GitHub bootstrap with curl Signed-off-by: Hidde Beydals --- .github/workflows/bootstrap.yaml | 12 ++++++------ cmd/flux/bootstrap_github.go | 12 ------------ 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/.github/workflows/bootstrap.yaml b/.github/workflows/bootstrap.yaml index 23942d47..f9bac650 100644 --- a/.github/workflows/bootstrap.yaml +++ b/.github/workflows/bootstrap.yaml @@ -68,12 +68,12 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITPROVIDER_BOT_TOKEN }} - name: delete repository run: | - /tmp/flux bootstrap github --manifests ./manifests/install/ \ - --owner=fluxcd-testing \ - --repository=flux-test-${{ steps.vars.outputs.sha_short }} \ - --branch=main \ - --path=test-cluster \ - --delete + curl \ + -X DELETE \ + -H "Accept: application/vnd.github.v3+json" \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + --fail --silent \ + https://api.github.com/repos/fluxcd-testing/flux-test-${{ steps.vars.outputs.sha_short }} env: GITHUB_TOKEN: ${{ secrets.GITPROVIDER_BOT_TOKEN }} - name: Debug failure diff --git a/cmd/flux/bootstrap_github.go b/cmd/flux/bootstrap_github.go index 8fb48ac3..e40efd0f 100644 --- a/cmd/flux/bootstrap_github.go +++ b/cmd/flux/bootstrap_github.go @@ -80,7 +80,6 @@ type githubFlags struct { hostname string path flags.SafeRelativePath teams []string - delete bool sshHostname string } @@ -101,9 +100,6 @@ func init() { bootstrapGitHubCmd.Flags().StringVar(&githubArgs.sshHostname, "ssh-hostname", "", "GitHub SSH hostname, to be used when the SSH host differs from the HTTPS one") bootstrapGitHubCmd.Flags().Var(&githubArgs.path, "path", "path relative to the repository root, when specified the cluster sync will be scoped to this path") - bootstrapGitHubCmd.Flags().BoolVar(&githubArgs.delete, "delete", false, "delete repository (used for testing only)") - bootstrapGitHubCmd.Flags().MarkHidden("delete") - bootstrapCmd.AddCommand(bootstrapGitHubCmd) } @@ -163,14 +159,6 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error { } defer os.RemoveAll(tmpDir) - if githubArgs.delete { - if err := provider.DeleteRepository(ctx, repository); err != nil { - return err - } - logger.Successf("repository deleted") - return nil - } - // create GitHub repository if doesn't exists logger.Actionf("connecting to %s", githubArgs.hostname) changed, err := provider.CreateRepository(ctx, repository) From 0239307d8e88df53f58c9070e2e25498efd39a0e Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Mon, 8 Mar 2021 10:11:42 +0100 Subject: [PATCH 2/2] Change repository name used in bootstrap tests This changes the name of the repository that is used for the GitHub end-to-end tests to a name that is still traceable to the source (repository) that created it, by using the format `-`. The `PSEUDO_RAND_SUFFIX` is a SHA1 sum of the name of the branch and commit SHA the tests run for, resulting in a 40 character suffix that unlike the short commit SHA used before, should not result in collisions. Signed-off-by: Hidde Beydals --- .github/workflows/bootstrap.yaml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/bootstrap.yaml b/.github/workflows/bootstrap.yaml index f9bac650..8c832a2b 100644 --- a/.github/workflows/bootstrap.yaml +++ b/.github/workflows/bootstrap.yaml @@ -34,12 +34,18 @@ jobs: go build -o /tmp/flux ./cmd/flux - name: Set outputs id: vars - run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)" + run: | + REPOSITORY_NAME=${{ github.event.repository.name }} + BRANCH_NAME=${GITHUB_REF##*/} + COMMIT_SHA=$(git rev-parse HEAD) + PSEUDO_RAND_SUFFIX=$(echo "${BRANCH_NAME}-${COMMIT_SHA}" | shasum | awk '{print $1}') + TEST_REPO_NAME="${REPOSITORY_NAME}-${PSEUDO_RAND_SUFFIX}" + echo "::set-output name=test_repo_name::$TEST_REPO_NAME" - name: bootstrap init run: | /tmp/flux bootstrap github --manifests ./manifests/install/ \ --owner=fluxcd-testing \ - --repository=flux-test-${{ steps.vars.outputs.sha_short }} \ + --repository=${{ steps.vars.outputs.test_repo_name }} \ --branch=main \ --path=test-cluster env: @@ -48,7 +54,7 @@ jobs: run: | /tmp/flux bootstrap github --manifests ./manifests/install/ \ --owner=fluxcd-testing \ - --repository=flux-test-${{ steps.vars.outputs.sha_short }} \ + --repository=${{ steps.vars.outputs.test_repo_name }} \ --branch=main \ --path=test-cluster env: @@ -61,7 +67,7 @@ jobs: run: | /tmp/flux bootstrap github --manifests ./manifests/install/ \ --owner=fluxcd-testing \ - --repository=flux-test-${{ steps.vars.outputs.sha_short }} \ + --repository=${{ steps.vars.outputs.test_repo_name }} \ --branch=main \ --path=test-cluster env: @@ -73,7 +79,7 @@ jobs: -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: token ${GITHUB_TOKEN}" \ --fail --silent \ - https://api.github.com/repos/fluxcd-testing/flux-test-${{ steps.vars.outputs.sha_short }} + https://api.github.com/repos/fluxcd-testing/${{ steps.vars.outputs.test_repo_name }} env: GITHUB_TOKEN: ${{ secrets.GITPROVIDER_BOT_TOKEN }} - name: Debug failure