windows_exporter/.github/workflows/release.yml

166 lines
5.7 KiB
YAML
Raw Normal View History

name: Releases
# Trigger on releases.
on:
push:
branches:
- master
pull_request:
release:
types:
- published
- edited
permissions:
contents: write
packages: write
env:
PROMU_VER: '0.14.0'
jobs:
build:
runs-on: windows-2022
steps:
2024-05-09 13:32:26 +00:00
- uses: actions/checkout@v4
with:
# fetch-depth required for gitversion in `Build` step
fetch-depth: 0
2024-05-09 13:32:26 +00:00
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
2024-07-22 13:21:05 +00:00
# https://github.com/pl4nty/Windows-Containers/blob/Main/helpful_tools/Install-BuildKit-GitHubActions/workflow.yaml
- name: Setup containerd
run: |
$version = "1.7.20"
2024-07-22 13:21:05 +00:00
curl.exe -L https://github.com/containerd/containerd/releases/download/v$version/containerd-$version-windows-amd64.tar.gz -o containerd.tar.gz
tar.exe xvf containerd.tar.gz
.\bin\containerd.exe --register-service
Start-Service containerd
- name: Setup BuildKit
run: |
$version = "v0.15.0"
2024-07-22 13:21:05 +00:00
curl.exe -L https://github.com/moby/buildkit/releases/download/$version/buildkit-$version.windows-amd64.tar.gz -o buildkit.tar.gz
tar.exe xvf buildkit.tar.gz
.\bin\buildkitd.exe --register-service
Start-Service buildkitd
- name: Setup Docker Buildx
run: |
$version = "v0.16.1"
2024-07-22 13:21:05 +00:00
curl.exe -L https://github.com/docker/buildx/releases/download/$version/buildx-$version.windows-amd64.exe -o $env:ProgramData\Docker\cli-plugins\docker-buildx.exe
- uses: docker/setup-buildx-action@v3
with:
driver: remote
endpoint: npipe:////./pipe/buildkitd
- name: Install WiX
run: dotnet tool install --global wix
- name: Install WiX extensions
run: |
wix extension add -g WixToolset.Util.wixext
wix extension add -g WixToolset.Firewall.wixext
- name: Install Build deps
run: |
Invoke-WebRequest -Uri https://github.com/prometheus/promu/releases/download/v$($Env:PROMU_VER)/promu-$($Env:PROMU_VER).windows-amd64.zip -OutFile promu-$($Env:PROMU_VER).windows-amd64.zip
Expand-Archive -Path promu-$($Env:PROMU_VER).windows-amd64.zip -DestinationPath .
Copy-Item -Path promu-$($Env:PROMU_VER).windows-amd64\promu.exe -Destination "$(go env GOPATH)\bin"
2024-05-07 11:23:43 +00:00
# GOPATH\bin dir must be added to PATH else the `promu` commands won't be found
echo "$(go env GOPATH)\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Build
run: |
$ErrorActionPreference = "Stop"
2024-05-11 23:46:05 +00:00
$Version = git describe --tags --always
$Version = $Version -replace 'v', ''
2024-05-11 23:46:05 +00:00
# '+' symbols are invalid characters in image tags
$Version = $Version -replace '\+', '_'
$Version | Set-Content VERSION -PassThru
2024-05-11 23:46:05 +00:00
make build-all
# GH requires all files to have different names, so add version/arch to differentiate
foreach($Arch in "amd64", "arm64") {
Move-Item output\$Arch\windows_exporter.exe output\windows_exporter-$Version-$Arch.exe
}
2024-05-12 08:04:33 +00:00
Get-ChildItem -Path output
- name: Upload Artifacts
2024-05-09 13:32:26 +00:00
uses: actions/upload-artifact@v4
with:
name: windows_exporter_binaries
path: output\windows_exporter-*.exe
- name: Build Release Artifacts
run: |
$ErrorActionPreference = "Stop"
$Version = Get-Content VERSION
2024-05-11 23:27:54 +00:00
foreach($Arch in "amd64", "arm64") {
Write-Host "Building windows_exporter $Version msi for $Arch"
.\installer\build.ps1 -PathToExecutable .\output\windows_exporter-$Version-$Arch.exe -Version $Version -Arch "$Arch"
}
2024-05-12 08:04:33 +00:00
Move-Item installer\*.msi output\
Get-ChildItem -Path output\
promu checksum output\
- name: Build Docker Artifacts
run: make build-all
env:
VERSION: >-
${{
startsWith(github.ref, 'refs/tags/') && 'latest' ||
(
github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || github.ref_name
)
}}
- name: Login to Docker Hub
if: ${{ github.event_name != 'pull_request' }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_LOGIN }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
2024-05-15 00:38:01 +00:00
#- name: Login to quay.io
# if: ${{ github.event_name != 'pull_request' }}
# uses: docker/login-action@v3
# with:
# registry: quay.io
# username: 'robot'
# password: ${{ secrets.QUAY_IO_API_TOKEN }}
- name: Login to GitHub container registry
if: ${{ github.event_name != 'pull_request' }}
2024-05-09 13:32:26 +00:00
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push Latest image
if: ${{ github.event_name != 'pull_request' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ startsWith(github.ref, 'refs/tags/') && 'latest' || github.ref_name }}
run: |
make push-all
- name: Release
if: startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$TagName = $env:GITHUB_REF -replace 'refs/tags/', ''
Get-ChildItem -Path output\* -Include @('windows_exporter*.msi', 'windows_exporter*.exe', 'sha256sums.txt') | Foreach-Object {gh release upload $TagName $_}
make push-all