Skip to content

Commit

Permalink
actions: build artifacts in parallel
Browse files Browse the repository at this point in the history
Build the artifacts in parallel to speed up the build workflow and to
make it easier to only download the artifacts necessary when testing.

Signed-off-by: Ryan Cragun <[email protected]>
  • Loading branch information
ryancragun committed Jul 11, 2024
1 parent c4507ef commit 2dd2be8
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .github/actions/build-flight-control/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ runs:
steps:
- name: Install upx
run: |
curl -Lo upx.tar.xz https://github.com/upx/upx/releases/download/v4.2.2/upx-4.2.2-amd64_linux.tar.xz
curl -Lo upx.tar.xz https://github.com/upx/upx/releases/download/v4.2.4/upx-4.2.4-amd64_linux.tar.xz
tar -xvf upx.tar.xz
sudo mv upx*/upx /usr/local/sbin/
shell: bash
Expand Down
53 changes: 28 additions & 25 deletions .github/actions/build-provider/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,42 @@ name: Build provider
description: Build the enos-provider
inputs:
target:
description: The platform and operation system to build, i.e linux/amd64.. By default all supported targets are built
description: The platform and operation system to build, i.e linux/amd64.
required: true
default: all
default: linux/amd64
outputs:
arch:
description: The target artifact os
value: ${{ steps.meta.outputs.arch }}
name:
description: The target artifact name
value: ${{ steps.gen-output.outputs.targets }}
os:
description: The target artifact os
value: ${{ steps.meta.outputs.os }}

runs:
using: composite
steps:
- uses: ./.github/actions/build-flight-control
- if: ${{ inputs.target == 'all' || inputs.target == 'linux/amd64' }}
name: Build enos-provider linux/amd64
env:
PROVIDER_BIN_OS: linux
PROVIDER_BIN_ARCH: amd64
run: make build
- id: meta
shell: bash
- if: ${{ inputs.target == 'all' || inputs.target == 'linux/arm64' }}
name: Build enos-provider linux/arm64
run: |
{
os=$(cut -d "/" -f1 "${{ inputs.target }}")
arch=$(cut -d "/" -f2 "${{ inputs.target }}")
echo "os=$os"
echo "arch=$arch"
} | tee -a "$GITHUB_OUTPUT"
- name: Build enos-provider ${{ inputs.target }}
env:
PROVIDER_BIN_OS: linux
PROVIDER_BIN_ARCH: arm64
PROVIDER_BIN_OS: ${{ steps.split.outputs.os }}
PROVIDER_BIN_ARCH: ${{ steps.split.outputs.arch }}
run: make build
shell: bash
- if: ${{ inputs.target == 'all' || inputs.target == 'darwin/amd64' }}
name: Build enos-provider darwin/amd64
env:
PROVIDER_BIN_OS: darwin
PROVIDER_BIN_ARCH: amd64
run: make build
shell: bash
- if: ${{ inputs.target == 'all' || inputs.target == 'darwin/arm64' }}
name: Build enos-provider darwin/arm64
env:
PROVIDER_BIN_OS: darwin
PROVIDER_BIN_ARCH: arm64
run: make build
- id: gen-output
shell: bash
run: |
{
echo "artifact=$(ls dist)"
} | tee -a "$GITHUB_OUTPUT"
2 changes: 0 additions & 2 deletions .github/actions/set-up-golangci-lint/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ description: Set up golangci-lint from Github releases
inputs:
destination:
description: "Where to install the golangci-lint binary (default: $HOME/bin/golangci-lint)"
type: boolean
default: "$HOME/bin/golangci-lint"
version:
description: "The version to install (default: latest)"
type: string
default: Latest

outputs:
Expand Down
33 changes: 25 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,39 @@ on:
jobs:
build:
runs-on: ubuntu-latest
outputs:
linux-amd64-artifact: ${{ steps.outputs.outputs.linux-amd64-artifact }}
strategy:
fail-fast: true
matrix:
arch:
- amd64
- arm64
os:
- darwin
- linux
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
with:
ref: ${{ inputs.sha }} # checkout out our sha to get the version
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version-file: go.mod
- uses: ./.github/actions/build-provider
- name: Upload artifacts
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
- id: build
uses: ./.github/actions/build-provider
with:
name: release-artifacts
path: dist
target: ${{matrix.os}}/${{ matrix.arch }}
- uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
with:
name: ${{ steps.build.outputs.name }}
path: dist/${{ steps.build.outputs.name }}
if-no-files-found: error
retention-days: 1
overwrite: true
- id: outputs
run: |
{
echo "linux-amd64-artifact=terraform-provider-enos_$(cat VERSION)_linux_amd64"
} | tee -a "$GITHUB_OUTPUT"
test-build-artifacts:
needs: build
Expand All @@ -35,7 +52,7 @@ jobs:
secrets: inherit
with:
sample-name: dev
download: release-artifacts
download: ${{ needs.build.outputs.linux-amd64-artifact }}

release:
needs:
Expand All @@ -52,7 +69,7 @@ jobs:
- uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7
with:
path: dist
name: release-artifacts
name: terraform-provider-enos*
merge-multiple: true
- run: |
ls -al ./dist
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/run-sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,34 @@ name: run-samples
on:
workflow_dispatch:
inputs:
download:
type: string
required: false
max:
description: The maximum number of scenarios to sample
type: number
default: 8
min:
description: The minimum number of scenarios to sample
type: number
default: 1
sample-name:
description: The sample name
required: true
type: string
workflow_call:
inputs:
download:
description: The name of the artifact to download
type: string
required: false
required: true
max:
description: The maximum number of scenarios to sample
type: number
default: 8
min:
description: The minimum number of scenarios to sample
type: number
default: 1
sample-name:
description: The sample name
required: true
type: string

Expand Down
19 changes: 4 additions & 15 deletions .github/workflows/run-scenario.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@ name: run-scenario
on:
workflow_dispatch:
inputs:
download:
type: string
required: false
scenario-filter:
description: The filter of the scenario to run
required: true
type: string
build-dev:
type: boolean
default: false
workflow_call:
inputs:
download:
Expand All @@ -21,9 +16,6 @@ on:
scenario-filter:
required: true
type: string
build-dev:
type: boolean
default: false

jobs:
run:
Expand Down Expand Up @@ -59,19 +51,16 @@ jobs:
chmod 600 enos/support/enos-ci-ssh-key.pem
chmod 600 enos/support/vault.hclic
chmod 600 enos/support/consul.hclic
- if: inputs.build-dev == true
- if: github.event_name == 'workflow_dispatch'
uses: ./.github/actions/build-provider
with:
target: linux/amd64
- if: inputs.download != ''
- if: github.event_name == 'workflow_call'
uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7
with:
path: dist
name: ${{ inputs.download }}
merge-multiple: true
- run: |
ls -al ./dist
chmod +x ./dist/*
- run: chmod +x ./dist/*
- run: enos scenario run ${{ inputs.scenario-filter }}
working-directory: enos
- if: ${{ always() }}
Expand Down
39 changes: 28 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,37 @@ jobs:
build:
name: build
runs-on: ubuntu-latest
outputs:
linux-amd64-artifact: ${{ steps.outputs.outputs.linux-amd64-artifact }}
strategy:
fail-fast: true
matrix:
arch:
- amd64
- arm64
os:
- darwin
- linux
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
# Build all provider targets here to ensure they all compile
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version-file: go.mod
- uses: ./.github/actions/build-provider
- run: ls -al ./dist
- name: Upload artifacts
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
- id: build
uses: ./.github/actions/build-provider
with:
name: test-artifacts
path: dist
target: ${{matrix.os}}/${{ matrix.arch }}
- uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
with:
name: ${{ steps.build.outputs.name }}
path: dist/${{ steps.build.outputs.name }}
if-no-files-found: error
retention-days: 1
overwrite: true
- id: outputs
run: |
{
echo "linux-amd64-artifact=terraform-provider-enos_$(cat VERSION)_linux_amd64"
} | tee -a "$GITHUB_OUTPUT"
go:
name: go test
Expand Down Expand Up @@ -90,14 +105,16 @@ jobs:
validate-terraform-examples:
name: terraform validate examples
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version-file: go.mod
- uses: ./.github/actions/build-provider
- uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7
with:
target: linux/amd64
path: dist
name: ${{ needs.build.outputs.linux-amd64-artifact }}
- uses: hashicorp/setup-terraform@v3
- name: Run terraform --chdir=examples/* validate
run: |
Expand All @@ -115,7 +132,7 @@ jobs:
secrets: inherit
with:
sample-name: dev
download: test-artifacts
download: ${{ needs.build.outputs.linux-amd64-artifact }}

static-analysis:
name: static analysis
Expand Down

0 comments on commit 2dd2be8

Please sign in to comment.