From 5e8bc4b7f03e1c466f5e8b9c4c2748a2f3212944 Mon Sep 17 00:00:00 2001 From: "Marcel S. Henselin" Date: Fri, 30 Jan 2026 12:27:46 +0100 Subject: [PATCH] fix: fix publisher command fix: fix ci pipeline to include publish testing --- .github/workflows/ci.yaml | 94 ++++++++++++++++++++++++++++++++++++- cmd/cmd/publish/provider.go | 13 +++++ cmd/cmd/publishCmd.go | 7 ++- 3 files changed, 112 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index bbd69400..12278cab 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -13,6 +13,99 @@ env: CODE_COVERAGE_ARTIFACT_NAME: "code-coverage" jobs: + publish_test: + name: "Test readiness for publishing provider" + needs: config + runs-on: ubuntu-latest + permissions: + actions: read # Required to identify workflow run. + checks: write # Required to add status summary. + contents: read # Required to checkout repository. + pull-requests: write # Required to add PR comment. + steps: + - name: Install needed tools + run: | + apt-get -y -qq update + apt-get -y -qq install jq python3 python3-pip python-is-python3 s3cmd git make wget + + - name: Setup Go + uses: actions/setup-go@v6 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Install go tools + run: | + go install golang.org/x/tools/cmd/goimports@latest + go install github.com/hashicorp/terraform-plugin-codegen-framework/cmd/tfplugingen-framework@latest + go install github.com/hashicorp/terraform-plugin-codegen-openapi/cmd/tfplugingen-openapi@latest + + - name: Setup JAVA + uses: actions/setup-java@v5 + with: + distribution: 'temurin' # See 'Supported distributions' for available options + java-version: '21' + + - name: Checkout + uses: actions/checkout@v6 + + - name: Run build pkg directory + run: | + go run cmd/main.go build + + - name: Set up s3cfg + run: | + cat <<'EOF' >> ~/.s3cfg + [default] + host_base = https://object.storage.eu01.onstackit.cloud + host_bucket = https://%(bucket).object.storage.eu01.onstackit.cloud + check_ssl_certificate = False + access_key = ${{ secrets.S3_ACCESS_KEY }} + secret_key = ${{ secrets.S3_SECRET_KEY }} + EOF + + - name: Import GPG key + run: | + echo "${{ secrets.PRIVATE_KEY_PEM }}" > ~/private.key.pem + gpg --import ~/private.key.pem + rm ~/private.key.pem + + - name: Run GoReleaser with SNAPSHOT + if: github.event_name == 'workflow_dispatch' + id: goreleaser + env: + GITHUB_TOKEN: ${{ env.FORGEJO_TOKEN }} + GPG_FINGERPRINT: ${{ secrets.GPG_FINGERPRINT }} + uses: goreleaser/goreleaser-action@v6 + with: + args: release --skip publish --clean --snapshot + + - name: Run GoReleaser + if: github.event_name != 'workflow_dispatch' + id: goreleaser + env: + GITHUB_TOKEN: ${{ env.FORGEJO_TOKEN }} + GPG_FINGERPRINT: ${{ secrets.GPG_FINGERPRINT }} + uses: goreleaser/goreleaser-action@v6 + with: + args: release --skip publish --clean + + - name: Prepare key file + run: | + echo "${{ secrets.PUBLIC_KEY_PEM }}" >public_key.pem + + - name: Prepare provider directory structure + run: | + VERSION=$(jq -r .version < dist/metadata.json) + go run cmd/main.go \ + publish \ + --namespace=mhenselin \ + --providerName=stackitprivatepreview \ + --repoName=terraform-provider-stackitprivatepreview \ + --domain=tfregistry.sysops.stackit.rocks \ + --gpgFingerprint=${{ secrets.GPG_FINGERPRINT }} \ + --gpgPubKeyFile=public_key.pem \ + --version=${VERSION} + main: name: CI runs-on: ubuntu-latest @@ -57,7 +150,6 @@ jobs: name: ${{ env.CODE_COVERAGE_ARTIFACT_NAME }} path: "stackit/${{ env.CODE_COVERAGE_FILE_NAME }}" - config: name: Check GoReleaser config if: github.event_name == 'pull_request' diff --git a/cmd/cmd/publish/provider.go b/cmd/cmd/publish/provider.go index 73f12ab0..947a42ff 100644 --- a/cmd/cmd/publish/provider.go +++ b/cmd/cmd/publish/provider.go @@ -8,11 +8,13 @@ import ( "io/fs" "log" "os" + "os/exec" "path" "strings" ) type Provider struct { + RootPath string Namespace string Provider string DistPath string @@ -23,6 +25,17 @@ type Provider struct { Domain string } +func (p *Provider) GetRoot() error { + cmd := exec.Command("git", "rev-parse", "--show-toplevel") + out, err := cmd.Output() + if err != nil { + return err + } + lines := strings.Split(string(out), "\n") + p.RootPath = lines[0] + return nil +} + func (p *Provider) CreateV1Dir() error { // Path to semantic version dir versionPath := p.providerDirs() diff --git a/cmd/cmd/publishCmd.go b/cmd/cmd/publishCmd.go index 0f595009..9930aa65 100644 --- a/cmd/cmd/publishCmd.go +++ b/cmd/cmd/publishCmd.go @@ -6,6 +6,7 @@ import ( "io/fs" "log" "os" + "path" "path/filepath" publish2 "github.com/mhenselin/terraform-provider-stackitprivatepreview/cmd/cmd/publish" @@ -96,10 +97,14 @@ func publish() error { GpgPubKeyFile: gpgPubKeyFile, Domain: domain, } + err := p.GetRoot() + if err != nil { + return err + } // Create release dir - only the contents of this need to be uploaded to S3 log.Printf("* Creating reelase directory") - err := os.Mkdir("release", os.ModePerm) + err = os.Mkdir(path.Join(p.RootPath, "release"), os.ModePerm) if !errors.Is(err, fs.ErrExist) { return fmt.Errorf("error creating 'release' dir: %w", err) }