From f8f3ee546ae309b72ecd8de1b2c927ace014d57c Mon Sep 17 00:00:00 2001 From: Tom Graupner Date: Mon, 21 Oct 2024 15:58:24 +0200 Subject: [PATCH] chore: rebase and work in progress on release automation --- .github/workflows/build.yml | 97 +++++++++++++++++++++-- .github/workflows/release.yml | 140 +--------------------------------- go.mod | 3 - main.go | 12 +-- version/version.go | 6 ++ 5 files changed, 98 insertions(+), 160 deletions(-) create mode 100644 version/version.go diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7794823..970ecbc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,9 +8,54 @@ on: jobs: - build: - name: Build - runs-on: ubuntu-22.04 + check-run: + name: Check PR run + uses: bitwarden/gh-actions/.github/workflows/check-run.yml@main + + build-artifact: + name: Build and verify artifact + runs-on: ${{ matrix.runner }} + needs: check-run + outputs: + module_name: ${{ steps.prepare-release.outputs.module_name }} + version: ${{ steps.prepare-release.outputs.version }} + strategy: + matrix: + os: [ ubuntu-22.04, darwin, windows ] + arch: [ amd64, arm64 ] + include: + - os: ubuntu-22.04 + arch: amd64 + runner: ubuntu-22.04 + build_target: build-linux-amd64 + verify_target: verify-binary-linux + dependencies: musl-tools + - os: ubuntu-22.04 + arch: arm64 + runner: Terraform-provider-bitwarden-sm-linux + build_target: build-linux-arm64 + verify-target: verify-binary-linux + dependencies: musl-tools + - os: darwin + arch: amd64 + runner: macos-14 + build_target: build-darwin-amd64 + verify_target: verify-binary-darwin-amd64 + - os: darwin + arch: arm64 + runner: macos-14 + build_target: build-darwin-arm64 + verify_target: verify-binary-darwin-arm64 + - os: windows + arch: amd64 + runner: ubuntu-22.04 + build_target: build-windows-amd64 + verify_target: verify-binary-windows-amd64 + dependencies: mingw-w64 + exclude: + - os: windows + arch: arm64 + steps: - name: Check out repo @@ -22,14 +67,50 @@ jobs: go-version-file: 'go.mod' cache: true + - name: Install dependencies (Linux only) + if: matrix.os == 'ubuntu-22.04' + run: sudo apt update && sudo apt install -y ${{ matrix.dependencies }} + + - name: Install dependencies (Windows cross-compile only) + if: matrix.os == 'windows' + run: sudo apt update && sudo apt install -y ${{ matrix.dependencies }} + - name: Install Go dependencies run: go mod tidy - - name: Install build dependencies - run: sudo apt update && sudo apt install musl-tools -y - - name: Build binary - run: make build-linux-amd64 + run: make ${{ matrix.build_target }} BINARY_VERSION="_${{ github.ref_name }}" - name: Verify binary - run: make verify-binary-linux + run: make ${{ matrix.verify_target }} BINARY_VERSION="_${{ github.ref_name }}" + + - name: Prepare release artifacts + id: prepare-release + run: | + MODULE_NAME=$(grep "^module" go.mod | awk -F'/' '{print $NF}') + BINARY_VERSION=$(echo ${{ github.ref_name }}) + ARCHIVE="${MODULE_NAME}_${BINARY_VERSION}_${{ matrix.os }}_${{ matrix.arch }}.zip" + + # Conditionally set the binary name with or without .exe extension + BINARY="${MODULE_NAME}_${BINARY_VERSION}" + if [ "${{ matrix.os }}" = "windows" ]; then + BINARY="${BINARY}.exe" + fi + + # Create ZIP archive + zip ${ARCHIVE} ${BINARY} + + echo "module_name=${MODULE_NAME}" >> "$GITHUB_OUTPUT" + echo "version=${BINARY_VERSION}" >> "$GITHUB_OUTPUT" + + echo "module_name=${MODULE_NAME}" >> "$GITHUB_ENV" + echo "binary_version=${BINARY_VERSION}" >> "$GITHUB_ENV" + echo "archive=${ARCHIVE}" >> "$GITHUB_ENV" + + - name: Upload artifacts + uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6 + with: + name: ${{ env.module_name }}_${{ env.binary_version }}_${{ matrix.os }}_${{ matrix.arch }} + retention-days: 5 + path: | + ${{ env.archive }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3c46a13..61402e7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,153 +1,15 @@ name: Release on: - push: - tags: - - "v[0-9]+.[0-9]+.[0-9]+" - - "v[0-9]+.[0-9]+.[0-9]+-pre" + workflow_dispatch: jobs: - check-run: - name: Check PR run - uses: bitwarden/gh-actions/.github/workflows/check-run.yml@main - - build-artifact: - name: Build and verify artifact - runs-on: ${{ matrix.runner }} - needs: check-run - outputs: - module_name: ${{ steps.prepare-release.outputs.module_name }} - version: ${{ steps.prepare-release.outputs.version }} - strategy: - matrix: - os: [ubuntu-22.04, darwin, windows] - arch: [amd64, arm64] - include: - - os: ubuntu-22.04 - arch: amd64 - runner: ubuntu-22.04 - build_target: build-linux-amd64 - verify_target: verify-binary-linux - dependencies: musl-tools - - os: ubuntu-22.04 - arch: arm64 - runner: Terraform-provider-bitwarden-sm-linux - build_target: build-linux-arm64 - verify-target: verify-binary-linux - dependencies: musl-tools - - os: darwin - arch: amd64 - runner: macos-14 - build_target: build-darwin-amd64 - verify_target: verify-binary-darwin-amd64 - - os: darwin - arch: arm64 - runner: macos-14 - build_target: build-darwin-arm64 - verify_target: verify-binary-darwin-arm64 - - os: windows - arch: amd64 - runner: ubuntu-22.04 - build_target: build-windows-amd64 - verify_target: verify-binary-windows-amd64 - dependencies: mingw-w64 - exclude: - - os: windows - arch: arm64 - - steps: - - - name: Check out repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - - - name: Setup Go - uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2 - with: - go-version-file: 'go.mod' - cache: true - - - name: Install dependencies (Linux only) - if: matrix.os == 'ubuntu-22.04' - run: sudo apt update && sudo apt install -y ${{ matrix.dependencies }} - - - name: Install dependencies (Windows cross-compile only) - if: matrix.os == 'windows' - run: sudo apt update && sudo apt install -y ${{ matrix.dependencies }} - - - name: Install Go dependencies - run: go mod tidy - - - name: Build binary - run: make ${{ matrix.build_target }} BINARY_VERSION="_${{ github.ref_name }}" - - - name: Verify binary - run: make ${{ matrix.verify_target }} BINARY_VERSION="_${{ github.ref_name }}" - - - name: Prepare release artifacts - id: prepare-release - run: | - MODULE_NAME=$(grep "^module" go.mod | awk -F'/' '{print $NF}') - BINARY_VERSION=$(echo ${{ github.ref_name }}) - ARCHIVE="${MODULE_NAME}_${BINARY_VERSION}_${{ matrix.os }}_${{ matrix.arch }}.zip" - - # Conditionally set the binary name with or without .exe extension - BINARY="${MODULE_NAME}_${BINARY_VERSION}" - if [ "${{ matrix.os }}" = "windows" ]; then - BINARY="${BINARY}.exe" - fi - - # Create ZIP archive - zip ${ARCHIVE} ${BINARY} - - echo "module_name=${MODULE_NAME}" >> "$GITHUB_OUTPUT" - echo "version=${BINARY_VERSION}" >> "$GITHUB_OUTPUT" - - echo "module_name=${MODULE_NAME}" >> "$GITHUB_ENV" - echo "binary_version=${BINARY_VERSION}" >> "$GITHUB_ENV" - echo "archive=${ARCHIVE}" >> "$GITHUB_ENV" - - - name: Upload artifacts - uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6 - with: - name: ${{ env.module_name }}_${{ env.binary_version }}_${{ matrix.os }}_${{ matrix.arch }} - retention-days: 5 - path: | - ${{ env.archive }} create-release: name: Create Release runs-on: ubuntu-22.04 - needs: build-artifact steps: - - name: Check out repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - - - name: Import GPG key - uses: crazy-max/ghaction-import-gpg@01dd5d3ca463c7f10f7f4f7b4f177225ac661ee4 # v6.1.0 - id: import_gpg - with: - gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} - passphrase: ${{ secrets.PASSPHRASE }} - - - name: Download ZIP files - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 - with: - pattern: ${{ needs.build-artifact.outputs.module_name }}_${{ needs.build-artifact.outputs.version }}_* - path: ./release - - - name: Generate SHA256SUMS - run: | - cd release - find . -type f -name "*.zip" -exec mv {} . \; - ls -lisah - shasum -a 256 *.zip > ${{ needs.build-artifact.outputs.module_name }}_${{ needs.build-artifact.outputs.version }}_SHA256SUMS - - - name: Sign SHA256SUMS - run: | - cd release - gpg --detach-sign ${{ needs.build-artifact.outputs.module_name }}_${{ needs.build-artifact.outputs.version }}_SHA256SUMS - - name: Release uses: softprops/action-gh-release@c062e08bd532815e2082a85e87e3ef29c3e6d191 # v2.0.8 with: diff --git a/go.mod b/go.mod index e923e20..c4b17c4 100644 --- a/go.mod +++ b/go.mod @@ -76,9 +76,6 @@ require ( go.abhg.dev/goldmark/frontmatter v0.2.0 // indirect golang.org/x/crypto v0.28.0 // indirect golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect - go.abhg.dev/goldmark/frontmatter v0.2.0 // indirect - golang.org/x/crypto v0.27.0 // indirect - golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect golang.org/x/mod v0.21.0 // indirect golang.org/x/sync v0.8.0 // indirect golang.org/x/sys v0.26.0 // indirect diff --git a/main.go b/main.go index 6b5741a..49f39bd 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "context" "flag" "github.com/bitwarden/terraform-provider-bitwarden-sm/internal/provider" + "github.com/bitwarden/terraform-provider-bitwarden-sm/version" "log" "github.com/hashicorp/terraform-plugin-framework/providerserver" @@ -19,15 +20,6 @@ import ( // can be customized. //go:generate go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs generate -var ( - // these will be set by the goreleaser configuration - // to appropriate values for the compiled binary. - version string = "dev" - - // goreleaser can pass other information to the main package, such as the specific commit - // https://goreleaser.com/cookbooks/using-main.version/ -) - func main() { var debug bool @@ -39,7 +31,7 @@ func main() { Debug: debug, } - err := providerserver.Serve(context.Background(), provider.New(version), opts) + err := providerserver.Serve(context.Background(), provider.New(version.ProviderVersion), opts) if err != nil { log.Fatal(err.Error()) diff --git a/version/version.go b/version/version.go new file mode 100644 index 0000000..fccf8c0 --- /dev/null +++ b/version/version.go @@ -0,0 +1,6 @@ +package version + +var ( + // ProviderVersion is set during release. + ProviderVersion string = "0.0.1" +)