Skip to content

use runner_temp dir to be OS independent #3

use runner_temp dir to be OS independent

use runner_temp dir to be OS independent #3

name: Reusable GoReleaser CI workflow

Check failure on line 1 in .github/workflows/base-ci-goreleaser.yaml

View workflow run for this annotation

GitHub Actions / .github/workflows/base-ci-goreleaser.yaml

Invalid workflow file

(Line: 71, Col: 12): Unrecognized named-value: 'steps'. Located at position 1 within expression: steps.prep.outputs.version
on:
workflow_call:
inputs:
distribution:
required: true
type: string
goos:
required: true
type: string
goarch:
required: true
type: string
runner_os:
required: false
type: string
default: ubuntu-24.04
nightly:
required: false
type: boolean
default: false
description: "Set to true to fetch latest otelcol-contrib main branch version instead of building the version in this repo"
config_file:
required: false
type: string
default: default-config.yaml
docker_run_options:
required: false
type: string
otelcol_run_options:
required: false
type: string
permissions:
contents: read
env:
# renovate: datasource=github-releases packageName=goreleaser/goreleaser-pro
GORELEASER_PRO_VERSION: v2.12.5
jobs:
check-goreleaser:
strategy:
matrix:
GOOS: ${{ fromJSON( inputs.goos) }}
GOARCH: ${{ fromJSON( inputs.goarch) }}
exclude:
- GOOS: darwin
GOARCH: "386"
- GOOS: darwin
GOARCH: s390x
- GOOS: windows
GOARCH: arm64
- GOOS: darwin
GOARCH: arm
- GOOS: windows
GOARCH: arm
- GOOS: windows
GOARCH: s390x
- GOOS: darwin
GOARCH: ppc64le
- GOOS: windows
GOARCH: ppc64le
- GOOS: darwin
GOARCH: riscv64
- GOOS: windows
GOARCH: riscv64
runs-on: ${{ inputs.runner_os }}
env:
TAG: ${{ inputs.distribution }}:${{ steps.prep.outputs.version }}-${{ steps.prep.outputs.arch }}
outputs:
version: ${{ steps.prep.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
fetch-depth: 0
- name: Setup QEMU
if: runner.os != 'Windows'
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
with:
platforms: arm64,ppc64le,linux/arm/v7,s390x,riscv64
- name: Setup wixl # Required to build MSI packages for Windows
if: runner.os != 'Windows'
run: |
sudo apt-get update
sudo apt-get install -y wixl
- name: Setup Docker Buildx
if: runner.os != 'Windows'
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
- name: Setup Go
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
with:
go-version: "~1.25.0"
check-latest: true
- name: Create artifacts directory to store build artifacts
if: inputs.distribution == 'otelcol-contrib'
run: mkdir -p distributions/otelcol-contrib/artifacts
- name: "[Nightly] Get latest finished run ID from contrib repo build-and-test"
id: get-run-id
if: inputs.distribution == 'otelcol-contrib' && inputs.nightly == true && matrix.GOARCH == 'amd64' && matrix.GOOS == 'linux'
env:
GH_TOKEN: ${{ github.token }}
run: |
run_id=$(gh run list \
--branch main \
--workflow build-and-test \
--repo open-telemetry/opentelemetry-collector-contrib \
--limit 1 \
--status success \
--json databaseId \
--jq '.[0].databaseId' \
)
echo "Found run ID: $run_id"
echo "run_id=$run_id" >> "$GITHUB_OUTPUT"
- name: "[Nightly] Create sub-directory for otelcol-contrib nightly build"
if: inputs.distribution == 'otelcol-contrib' && inputs.nightly == true && matrix.GOARCH == 'amd64' && matrix.GOOS == 'linux'
run: mkdir -p distributions/otelcol-contrib/artifacts/otelcol-contrib_linux_amd64_v1
- name: "[Nightly] Download built otelcol-contrib artifact from contrib repo"
if: inputs.distribution == 'otelcol-contrib' && inputs.nightly == true && matrix.GOARCH == 'amd64' && matrix.GOOS == 'linux'
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
with:
name: collector-binaries-linux-amd64
repository: open-telemetry/opentelemetry-collector-contrib
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ steps.get-run-id.outputs.run_id }}
- name: "[Nightly] Move downloaded artifact"
if: inputs.distribution == 'otelcol-contrib' && inputs.nightly == true && matrix.GOARCH == 'amd64' && matrix.GOOS == 'linux'
env:
folder: distributions/otelcol-contrib/artifacts/otelcol-contrib-linux_linux_amd64_v1/
run: |
mkdir -p ${{ env.folder }}
mv otelcontribcol_linux_amd64 ${{ env.folder }}/otelcol-contrib
- name: Generate the sources for ${{ inputs.distribution }}
if: inputs.nightly != true
env:
DISTRIBUTIONS: ${{ inputs.distribution }}
run: make generate-sources
# otelcol-contrib is built in a separate stage
- name: Build ${{ inputs.distribution }}
if: inputs.distribution == 'otelcol-contrib' && inputs.nightly != true
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
with:
distribution: goreleaser-pro
version: ${{ env.GORELEASER_PRO_VERSION }}
workdir: distributions/otelcol-contrib
args: --snapshot --clean --timeout 2h --split --config .goreleaser-build.yaml
env:
GOOS: ${{ matrix.GOOS }}
GOARCH: ${{ matrix.GOARCH }}
GOARM: "7" # Default is 6
GOAMD64: v1
GOPPC64: power8
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
- name: Move built artifacts
if: inputs.distribution == 'otelcol-contrib' && inputs.nightly != true
run: mv distributions/otelcol-contrib/dist/**/* distributions/otelcol-contrib/artifacts/
- name: Show built or downloaded content
if: inputs.distribution == 'otelcol-contrib' && runner.os != 'Windows'
run: ls -laR distributions/otelcol-contrib/artifacts
- name: Run GoReleaser for ${{ inputs.distribution }}
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
with:
distribution: goreleaser-pro
version: ${{ env.GORELEASER_PRO_VERSION }}
workdir: distributions/${{ inputs.distribution }}
args: --snapshot --clean --skip=sign,sbom --timeout 2h --split
env:
GOOS: ${{ matrix.GOOS }}
GOARCH: ${{ matrix.GOARCH }}
GOARM: "7" # Default is 6
GOAMD64: v1
GOPPC64: power8
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
- name: Print built artifacts
run: cat ./distributions/${{ inputs.distribution }}/dist/**/artifacts.json
- name: Print metadata
run: cat ./distributions/${{ inputs.distribution }}/dist/**/metadata.json
- name: Print dist folder contents
if: always() && runner.os != 'Windows'
run: ls -laR ./distributions/${{ inputs.distribution }}/dist
- name: Upload linux service packages
if: ${{ matrix.GOOS == 'linux' && matrix.GOARCH == 'amd64' && (inputs.distribution == 'otelcol-contrib' || inputs.distribution == 'otelcol') }}
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: linux-packages
path: distributions/${{ inputs.distribution }}/dist/linux_amd64_v1/*
if-no-files-found: error
- name: Upload MSI packages
if: matrix.GOOS == 'windows' && matrix.GOARCH == 'amd64' && (inputs.distribution == 'otelcol-contrib' || inputs.distribution == 'otelcol')
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: msi-packages
path: distributions/${{ inputs.distribution }}/dist/windows_amd64_v1/**/*.msi
if-no-files-found: error
- name: Prepare variables
if: matrix.GOOS == 'linux' || matrix.GOOS == 'windows'
shell: bash
id: prep
run: |
# Find version number and types of built artifacts
echo "version=$(cat ./distributions/${{ inputs.distribution }}/dist/**/metadata.json | jq -r '.version')" >> $GITHUB_OUTPUT
echo "types=$(cat ./distributions/${{ inputs.distribution }}/dist/**/artifacts.json | jq '[.[].type]' | tr -d '\n' )" >> $GITHUB_OUTPUT
echo "arch=${{ matrix.GOOS }}-${{ matrix.GOARCH }}" >> $GITHUB_OUTPUT
echo "binary-path=$(cat ./distributions/${{ inputs.distribution }}/dist/**/artifacts.json | jq -r 'map(select(any(.type; contains("Binary")))) | .[].path')" >> $GITHUB_OUTPUT
- name: Print version and target
if: matrix.GOOS == 'linux' || matrix.GOOS == 'windows'
shell: bash
run: |
echo 'Version: ${{ steps.prep.outputs.version }}'
echo 'Types: ${{ steps.prep.outputs.types }}'
echo 'Arch: ${{ steps.prep.outputs.arch }}'
echo 'Images?: ${{ steps.prep.outputs.container-images }}'
- name: Copy binary to distro root folder
if: matrix.GOOS == 'linux' || matrix.GOOS == 'windows'
run: cp ./distributions/${{ inputs.distribution }}/${{ steps.prep.outputs.binary-path }} ./distributions/${{ inputs.distribution }}
- name: Build container images locally
if: matrix.GOOS == 'linux' && contains(steps.prep.outputs.types, 'Docker Image')
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
with:
context: ./distributions/${{ inputs.distribution }}
push: false
load: true
tags: ${{ env.TAG }}
- name: Build container images locally
if: matrix.GOOS == 'windows' && contains(steps.prep.outputs.types, 'Docker Image')
run: |
docker build -f ./distributions/${{ inputs.distribution }}/Windows.dockerfile -t ${{ env.TAG }} ./distributions/${{ inputs.distribution }}/
- name: Export container image to tarball
if: (matrix.GOOS == 'linux' || matrix.GOOS == 'windows') && contains(steps.prep.outputs.types, 'Docker Image')
run: |
docker save ${{ env.TAG }} > ${{ runner.temp }}/${{ inputs.distribution }}.tar
- name: Upload container image artifact
if: (matrix.GOOS == 'linux' || matrix.GOOS == 'windows') && contains(steps.prep.outputs.types, 'Docker Image')
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: ${{ inputs.distribution }}-image-${{ steps.prep.outputs.version }}-${{ steps.prep.outputs.arch }}
path: ${{ runner.temp }}/${{ inputs.distribution }}.tar
retention-days: 7
docker-tests:
needs:
- check-goreleaser
strategy:
matrix:
GOOS: ${{ fromJSON( inputs.goos) }}
GOARCH: ${{ fromJSON( inputs.goarch) }}
exclude:
- GOOS: darwin
runs-on: ${{ inputs.runner_os }}
# if: startsWith(inputs.runner_os, 'ubuntu')
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- name: Setup QEMU
if: runner.os != 'Windows'
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
with:
platforms: arm64,ppc64le,linux/arm/v7,s390x,riscv64
- name: Download container image artifact
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
with:
name: ${{ inputs.distribution }}-image-${{ needs.check-goreleaser.outputs.version }}-${{ matrix.GOOS }}-${{ matrix.GOARCH }}
- name: Load image into docker
run: |
docker image load --input ./${{ inputs.distribution }}.tar
docker image ls
docker image inspect ${{ inputs.distribution }}:${{ needs.check-goreleaser.outputs.version }}-${{ matrix.GOOS }}-${{ matrix.GOARCH }}
- name: Run container image
run: |
echo "Running container..."
docker run --name ${{ inputs.distribution }} \
-d \
${{ inputs.docker_run_options }} \
-v ${PWD}/tests/docker-tests/${{ inputs.config_file }}:/config.yaml \
${{ inputs.distribution }}:${{ needs.check-goreleaser.outputs.version }}-${{ matrix.GOOS }}-${{ matrix.GOARCH }} \
${{ inputs.otelcol_run_options }} --config /config.yaml
echo "docker ps:"
echo ""
docker ps
echo "Sleeping for a bit..."
sleep 10
echo "Checking logs for correct startup..."
docker logs ${{ inputs.distribution }} >& docker-logs-${{ inputs.distribution }}.log
if cat docker-logs-${{ inputs.distribution }}.log | grep "Everything is ready."; then
echo "${{ inputs.distribution }} started up correctly"
else
echo "${{ inputs.distribution }} failed to start"
echo "Printing container logs below..."
echo ""
cat docker-logs-${{ inputs.distribution }}.log
exit 1
fi
- name: Run golden tests
if: matrix.GOOS == 'linux' && matrix.GOARCH == 'amd64' && inputs.distribution == 'otelcol-contrib'
run: |
echo "Running golden tests..."
cd tests/golden
MY_UID="$(id -u)" MY_GID="$(id -g)" IMG=${{ inputs.distribution }}:${{ needs.check-goreleaser.outputs.version }}-${{ matrix.GOOS }}-${{ matrix.GOARCH }} docker compose up -d --wait
exit_code=$(docker wait golden)
docker logs golden
if [ "$exit_code" -ne 0 ]; then
docker logs collector
exit 1
fi