pulumi/.github/workflows/ci-build-binaries.yml

134 lines
4.1 KiB
YAML
Raw Permalink Normal View History

2022-09-02 05:40:13 +00:00
name: Build Binaries
permissions:
contents: read
on:
workflow_call:
inputs:
ref:
required: true
description: "GitHub ref to use"
type: string
os:
required: true
description: "Target OS (i.e.: GOOS)"
type: string
arch:
required: true
2022-10-26 08:18:39 +00:00
description: "Target Architecture (i.e.: GOARCH)"
2022-09-02 05:40:13 +00:00
type: string
build-platform:
required: false
default: ubuntu-latest
description: 'Build platform (i.e.: runs-on) for job'
type: string
dev-version:
required: false
description: "Dev version to bake into the binary"
type: string
2022-09-02 05:40:13 +00:00
version:
required: true
description: "Version to produce"
type: string
version-set:
2022-09-02 05:40:13 +00:00
required: false
description: "Set of language versions to use for builds, lints, releases, etc."
2022-09-02 05:40:13 +00:00
type: string
ci: Track code coverage **Overview** This re-enables tracking of code coverage. For Go, there are two kinds of coverage at play: unit test and integration test coverage. Unit tests follow the usual pattern of running `go test -cover -coverprofile=whatever.cov`. For integration tests, we use the new integration test profiling support [added in Go 1.20](https://go.dev/testing/coverage/). In short, the way it works is: # Build a coverage instrumented binary: go build -cover # Set GOCOVERDIR to a directory and run the integration tests # that will invoke this coverage-instrumented binary. GOCOVERDIR=$(pwd)/coverage go test ./tests # $GOCOVERDIR will now be filled with coverage data # from every invocation of the coverage-instrumented binary. # Combine it into a single coverage file: go tool covdata textfmt -i=$(GOCOVERDIR) -o=out.cov # The resulting file can be uploaded to codecov as-is. The above replaces the prior, partially working hacks we had in place to get coverage-instrumented binaries with `go test -c` and hijacking the TestMain. **Notable changes** - TestMain hijacking is deleted from the Pulumi CLI. We no longer need this to build coverage-instrumented binaries. - ProgramTest no longer tracks or passes PULUMI_TEST_COVERAGE_PATH because the Pulumi binary no longer accepts a test.coverprofile flag. This information is now in the GOCOVERDIR environment variable. - We add an `enable-coverage` parameter to the `ci-build-binaries` workflow to mirror some of the other workflows. It will produce coverage-instrumented binaries if this is true. These binaries are then used by `ci-run-test` which will set `GOCOVERDIR` and merge the coverage results from it. - Coverage configuration no longer counts tests, testdata, and Protobuf-generated code against coverage. - go-wrapper.sh: Because we're no longer relying on the `go test -c` hack, this no longer excludes Windows and language providers from coverage tracking. - go-test.py and go-wrapper.sh will include pulumi-language-go and pulumi-language-nodejs in covered packages. *Other changes* - go-test.py: Fixed a bug where `args` parameters added for coverage were ignored. Note that this change DOES NOT track coverage for calls made to Pulumi packages by plugins downloaded from external sources, e.g. provider plugins. Arguably, that's out of scope of coverage trackcing for the Pulumi repository. Resolves #8615, #11419
2023-06-27 16:57:36 +00:00
enable-coverage:
description: "Build coverage instrumented binaries"
default: false
required: false
type: boolean
2022-09-02 05:40:13 +00:00
defaults:
run:
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
build:
name: ${{ inputs.os }}-${{ inputs.arch }}
runs-on: ${{ inputs.build-platform }}
permissions:
id-token: write
2022-09-02 05:40:13 +00:00
steps:
- name: "Windows cache workaround"
# https://github.com/actions/cache/issues/752#issuecomment-1222415717
# but only modify the path by adding tar.exe
if: ${{ runner.os == 'Windows' }}
2022-09-02 05:40:13 +00:00
env:
TOOL_BIN: ${{ runner.temp }}/tar-bin
run: |
set -x
mkdir -p "${TOOL_BIN}"
cp "C:/Program Files/Git/usr/bin/tar.exe" "${TOOL_BIN}"
PATH="${TOOL_BIN}:${PATH}"
echo "$TOOL_BIN" | tee -a "$GITHUB_PATH"
command -v tar
tar --version
- uses: actions/checkout@v3
with:
ref: ${{ inputs.ref }}
- name: Configure Go Cache Key
2022-09-02 05:40:13 +00:00
env:
CACHE_KEY: "${{ fromJson(inputs.version-set).go }}-${{ runner.os }}-${{ runner.arch }}"
2022-09-02 05:40:13 +00:00
run: echo "$CACHE_KEY" > .gocache.tmp
- uses: actions/setup-go@v3
with:
go-version: ${{ fromJson(inputs.version-set).go }}
2022-09-02 05:40:13 +00:00
cache: true
cache-dependency-path: |
pkg/go.sum
.gocache.tmp
- name: Setup versioning env vars
run: |
./scripts/versions.sh | tee -a "${GITHUB_ENV}"
- name: Install GoReleaser
uses: goreleaser/goreleaser-action@v3
with:
install-only: true
distribution: goreleaser-pro
# TODO[pulumi/pulumi#13312: Change this to not pin to a version after
# addressing the root cause of why GoReleaser v1.19.0 fails to read
# the configuration.
version: v1.18.2
- name: Set up bin dir
env:
GITHUB_TOKEN: ${{ secrets.PULUMI_BOT_TOKEN }}
GOOS: ${{ inputs.os }}
GOARCH: ${{ inputs.arch }}
run: ./scripts/prep-for-goreleaser.sh local
- name: Show files and permissions
if: ${{ runner.os != 'macOS'}}
run: find bin -type f -printf "%M %p/"\\n
- name: Show files and permissions
if: ${{ runner.os == 'macOS'}}
2022-09-02 05:40:13 +00:00
run: |
brew install findutils
gfind bin -type f -printf "%M %p/"\\n
2022-09-02 05:40:13 +00:00
- name: Package
shell: bash
env:
GORELEASER_CURRENT_TAG: v${{ inputs.version }}
PULUMI_VERSION: ${{ inputs.dev-version || inputs.version }}
ci: Track code coverage **Overview** This re-enables tracking of code coverage. For Go, there are two kinds of coverage at play: unit test and integration test coverage. Unit tests follow the usual pattern of running `go test -cover -coverprofile=whatever.cov`. For integration tests, we use the new integration test profiling support [added in Go 1.20](https://go.dev/testing/coverage/). In short, the way it works is: # Build a coverage instrumented binary: go build -cover # Set GOCOVERDIR to a directory and run the integration tests # that will invoke this coverage-instrumented binary. GOCOVERDIR=$(pwd)/coverage go test ./tests # $GOCOVERDIR will now be filled with coverage data # from every invocation of the coverage-instrumented binary. # Combine it into a single coverage file: go tool covdata textfmt -i=$(GOCOVERDIR) -o=out.cov # The resulting file can be uploaded to codecov as-is. The above replaces the prior, partially working hacks we had in place to get coverage-instrumented binaries with `go test -c` and hijacking the TestMain. **Notable changes** - TestMain hijacking is deleted from the Pulumi CLI. We no longer need this to build coverage-instrumented binaries. - ProgramTest no longer tracks or passes PULUMI_TEST_COVERAGE_PATH because the Pulumi binary no longer accepts a test.coverprofile flag. This information is now in the GOCOVERDIR environment variable. - We add an `enable-coverage` parameter to the `ci-build-binaries` workflow to mirror some of the other workflows. It will produce coverage-instrumented binaries if this is true. These binaries are then used by `ci-run-test` which will set `GOCOVERDIR` and merge the coverage results from it. - Coverage configuration no longer counts tests, testdata, and Protobuf-generated code against coverage. - go-wrapper.sh: Because we're no longer relying on the `go test -c` hack, this no longer excludes Windows and language providers from coverage tracking. - go-test.py and go-wrapper.sh will include pulumi-language-go and pulumi-language-nodejs in covered packages. *Other changes* - go-test.py: Fixed a bug where `args` parameters added for coverage were ignored. Note that this change DOES NOT track coverage for calls made to Pulumi packages by plugins downloaded from external sources, e.g. provider plugins. Arguably, that's out of scope of coverage trackcing for the Pulumi repository. Resolves #8615, #11419
2023-06-27 16:57:36 +00:00
PULUMI_BUILD_MODE: ${{ inputs.enable-coverage && 'coverage' || 'normal' }}
2022-09-02 05:40:13 +00:00
run: |
set -euxo pipefail
# Spurious, this command requires piping via stdin
# shellcheck disable=SC2002
cat .goreleaser.yml \
| go run github.com/t0yv0/goreleaser-filter@v0.3.0 -goos ${{ inputs.os }} -goarch ${{ inputs.arch }} \
| goreleaser release -f - -p 5 --skip-validate --clean --snapshot
2022-09-02 05:40:13 +00:00
- uses: actions/upload-artifact@v2
with:
name: artifacts-cli-${{ inputs.os }}-${{ inputs.arch }}
retention-days: 1
path: |
goreleaser/*.tar.gz
goreleaser/*.zip