Bump softprops/action-gh-release from 1 to 2 #64
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
push: | |
paths: | |
- 'source/**.go' | |
- 'go.mod' | |
- 'go.sum' | |
- 'Dockerfile' | |
- '.github/workflows/*.yml' | |
branches: | |
- '**' | |
tags: | |
- '*.*.*' | |
workflow_dispatch: | |
env: | |
PROJECT_NAME: apc-ups-exporter | |
DOCKER_REGISTRY_DOMAIN: ghcr.io | |
DOCKER_IMAGE_NAME: apc-ups-exporter | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-22.04 | |
strategy: | |
matrix: | |
operatingSystem: [ 'linux', 'windows' ] | |
architecture: [ 'amd64', '386', 'arm64', 'arm' ] | |
library: [ '', 'glibc', 'musl' ] | |
exclude: | |
- operatingSystem: windows | |
library: glibc | |
- operatingSystem: windows | |
library: musl | |
- operatingSystem: linux | |
library: '' | |
permissions: | |
contents: read | |
steps: | |
- name: Clone repository | |
uses: actions/checkout@v4 | |
- name: Setup Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: '1.20' | |
- name: Install build tools | |
if: ${{ matrix.library == 'musl' }} | |
run: sudo apt-get install --no-install-recommends --yes musl-tools | |
- name: Create artifact & executable name | |
id: names | |
env: | |
PROJECT_NAME: ${{ env.PROJECT_NAME }} | |
OPERATING_SYSTEM: ${{ matrix.operatingSystem }} | |
ARCHITECTURE: ${{ matrix.architecture }} | |
LIBRARY: ${{ matrix.library }} | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const { PROJECT_NAME, OPERATING_SYSTEM, ARCHITECTURE, LIBRARY } = process.env; | |
const artifactName = [ PROJECT_NAME, OPERATING_SYSTEM, ARCHITECTURE, LIBRARY ] | |
.filter( value => value != '' ) | |
.join( '-' ); | |
const executableName = artifactName + ( OPERATING_SYSTEM == 'windows' ? '.exe' : '' ); | |
core.setOutput( 'artifact', artifactName ); | |
core.setOutput( 'executable', executableName ); | |
- name: Build executable | |
env: | |
GOOS: ${{ matrix.operatingSystem }} | |
GOARCH: ${{ matrix.architecture }} | |
CC: ${{ matrix.library == 'musl' && '/usr/bin/musl-gcc' || '' }} | |
run: go build -v -ldflags='-s -w' -o ${{ steps.names.outputs.executable }} ./source/ | |
- name: Upload build artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ steps.names.outputs.artifact }} | |
path: ${{ steps.names.outputs.executable }} | |
docker: | |
name: Docker | |
runs-on: ubuntu-22.04 | |
needs: build | |
strategy: | |
matrix: | |
distribution: [ 'ubuntu', 'alpine' ] | |
architecture: [ 'amd64', 'arm64' ] | |
include: | |
- distribution: Ubuntu | |
image: ubuntu:23.04 | |
library: glibc | |
- distribution: alpine | |
image: alpine:3.18 | |
library: musl | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Clone repository | |
uses: actions/checkout@v4 | |
- name: Setup QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Setup Docker | |
uses: docker/setup-buildx-action@v3 | |
with: | |
platforms: linux/${{ matrix.architecture }} | |
- name: Login to GitHub Container Registry | |
if: ${{ github.event_name != 'pull_request' && !startsWith( github.ref_name, 'dependabot/' ) }} | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.DOCKER_REGISTRY_DOMAIN }} | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Download build artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: ${{ env.PROJECT_NAME }}-linux-${{ matrix.architecture }}-${{ matrix.library }} | |
path: artifact | |
- name: Create metadata for Docker image | |
id: metadata | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }} | |
flavor: | | |
latest=${{ matrix.distribution == 'ubuntu' }} | |
suffix=-${{ matrix.distribution }}-${{ matrix.architecture }},onlatest=true | |
tags: | | |
type=ref,event=pr | |
type=ref,event=branch | |
type=semver,pattern={{major}} | |
type=semver,pattern={{major}}.{{minor}} | |
type=semver,pattern={{major}}.{{minor}}.{{patch}} | |
labels: | | |
org.opencontainers.image.title=APC UPS Exporter (${{matrix.distribution}}-based) | |
org.opencontainers.image.vendor=${{ github.repository_owner }} | |
com.docker.extension.publisher-url=https://viral32111.com | |
- name: Build & push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
push: ${{ github.event_name != 'pull_request' && !startsWith( github.ref_name, 'dependabot/' ) }} | |
file: Dockerfile | |
context: artifact | |
tags: ${{ steps.metadata.outputs.tags }} | |
labels: ${{ steps.metadata.outputs.labels }} | |
platforms: linux/${{ matrix.architecture }} | |
provenance: false | |
no-cache: true | |
pull: true | |
build-args: | | |
BASE_IMAGE=${{ matrix.image }} | |
maintenance: | |
name: Maintenance | |
runs-on: ubuntu-22.04 | |
needs: docker | |
if: ${{ github.event_name != 'pull_request' && !startsWith( github.ref_name, 'dependabot/' ) }} | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Clone repository | |
uses: actions/checkout@v4 | |
- name: Setup Docker | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.DOCKER_REGISTRY_DOMAIN }} | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
#- name: Combine Docker image tags | |
# uses: viral32111/fat-manifest@v1 | |
# with: | |
# image: ${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }} | |
# tags: | | |
# type=latest,variants=ubuntu;alpine,architectures=amd64;arm64 | |
# type=ref,event=branch,variants=ubuntu;alpine,architectures=amd64;arm64 | |
# type=semver,pattern={{major}},variants=ubuntu;alpine,architectures=amd64;arm64 | |
# type=semver,pattern={{major}}.{{minor}},variants=ubuntu;alpine,architectures=amd64;arm64 | |
# type=semver,pattern={{major}}.{{minor}}.{{patch}},variants=ubuntu;alpine,architectures=amd64;arm64 | |
# type=latest,variants=ubuntu,architectures=amd64;arm64 | |
# latest-ubuntu-amd64, latest-ubuntu-arm64 > latest-ubuntu | |
# latest-alpine-amd64, latest-alpine-arm64 > latest-alpine | |
# main-ubuntu-amd64, main-ubuntu-arm64 > main-ubuntu | |
# main-alpine-amd64, main-alpine-arm64 > main-alpine | |
# 1.0.0-ubuntu-amd64, 1.0.0-ubuntu-arm64 > 1.0.0-ubuntu | |
# 1.0.0-alpine-amd64, 1.0.0-alpine-arm64 > 1.0.0-alpine | |
# 1.0-ubuntu-amd64, 1.0-ubuntu-arm64 > 1.0-ubuntu | |
# 1.0-alpine-amd64, 1.0-alpine-arm64 > 1.0-alpine | |
# 1-ubuntu-amd64, 1-ubuntu-arm64 > 1-ubuntu | |
# 1-alpine-amd64, 1-alpine-arm64 > 1-alpine | |
# latest-ubuntu-amd64, latest-ubuntu-amd64 > latest | |
- name: Create Docker image manifests | |
run: | | |
docker manifest create ${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:latest \ | |
--amend ${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:latest-ubuntu-amd64 \ | |
--amend ${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:latest-ubuntu-arm64 | |
docker manifest annotate --os linux --arch amd64 \ | |
${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:latest \ | |
${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:latest-ubuntu-amd64 | |
docker manifest annotate --os linux --arch arm64 \ | |
${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:latest \ | |
${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:latest-ubuntu-arm64 | |
docker manifest create ${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:latest-ubuntu \ | |
--amend ${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:latest-ubuntu-amd64 \ | |
--amend ${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:latest-ubuntu-arm64 | |
docker manifest annotate --os linux --arch amd64 \ | |
${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:latest-ubuntu \ | |
${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:latest-ubuntu-amd64 | |
docker manifest annotate --os linux --arch arm64 \ | |
${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:latest-ubuntu \ | |
${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:latest-ubuntu-arm64 | |
docker manifest create ${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:${{ github.ref_name }}-ubuntu \ | |
--amend ${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:${{ github.ref_name }}-ubuntu-amd64 \ | |
--amend ${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:${{ github.ref_name }}-ubuntu-arm64 | |
docker manifest annotate --os linux --arch amd64 \ | |
${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:${{ github.ref_name }}-ubuntu \ | |
${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:${{ github.ref_name }}-ubuntu-amd64 | |
docker manifest annotate --os linux --arch arm64 \ | |
${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:${{ github.ref_name }}-ubuntu \ | |
${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:${{ github.ref_name }}-ubuntu-arm64 | |
docker manifest create ${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:${{ github.ref_name }}-alpine \ | |
--amend ${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:${{ github.ref_name }}-alpine-amd64 \ | |
--amend ${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:${{ github.ref_name }}-alpine-arm64 | |
docker manifest annotate --os linux --arch amd64 \ | |
${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:${{ github.ref_name }}-alpine \ | |
${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:${{ github.ref_name }}-alpine-amd64 | |
docker manifest annotate --os linux --arch arm64 \ | |
${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:${{ github.ref_name }}-alpine \ | |
${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:${{ github.ref_name }}-alpine-arm64 | |
- name: Push Docker image manifests | |
run: | | |
docker manifest push ${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:latest | |
docker manifest push ${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:latest-ubuntu | |
docker manifest push ${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:${{ github.ref_name }}-ubuntu | |
docker manifest push ${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:${{ github.ref_name }}-alpine | |
- name: Delete old Docker images | |
uses: snok/container-retention-policy@v2 | |
with: | |
image-names: ${{ env.DOCKER_IMAGE_NAME }} | |
cut-off: 24 hours ago UTC | |
keep-at-least: 1 | |
untagged-only: true | |
skip-tags: latest | |
account-type: personal | |
token: ${{ secrets.PERSONAL_ACCESS_TOKEN_PACKAGES }} | |
release: | |
name: Release | |
runs-on: ubuntu-22.04 | |
needs: build | |
if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }} | |
permissions: | |
contents: write | |
steps: | |
- name: Download build artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
path: artifacts | |
- name: Move executables | |
run: | | |
mv -v artifacts/${{ env.PROJECT_NAME }}-*/${{ env.PROJECT_NAME }}-* ./ | |
rm -v -r artifacts | |
- name: Calculate checksums | |
run: | | |
md5sum ${{ env.PROJECT_NAME }}-* > MD5SUMS.txt | |
sha1sum ${{ env.PROJECT_NAME }}-* > SHA1SUMS.txt | |
sha256sum ${{ env.PROJECT_NAME }}-* > SHA256SUMS.txt | |
sha512sum ${{ env.PROJECT_NAME }}-* > SHA512SUMS.txt | |
- name: Create draft release | |
uses: softprops/action-gh-release@v2 | |
with: | |
draft: true | |
tag_name: ${{ github.ref_name }} | |
files: | | |
${{ env.PROJECT_NAME }}-* | |
*SUMS.txt | |
token: ${{ secrets.GITHUB_TOKEN }} |