Skip to content

Commit

Permalink
chore: rebase and work in progress on release automation
Browse files Browse the repository at this point in the history
  • Loading branch information
tgraupne committed Oct 29, 2024
1 parent c563f11 commit f8f3ee5
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 160 deletions.
97 changes: 89 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
140 changes: 1 addition & 139 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 2 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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

Expand All @@ -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())
Expand Down
6 changes: 6 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package version

var (
// ProviderVersion is set during release.
ProviderVersion string = "0.0.1"
)

0 comments on commit f8f3ee5

Please sign in to comment.