Skip to content

Build and Release

Build and Release #6

name: Build and Release
on:
workflow_dispatch:
inputs:
release_version:
description: 'Release version (leave empty for GitVersion)'
required: false
type: string
jobs:
build-and-release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Docker
uses: docker/setup-buildx-action@v3
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21' # Make sure this matches your go.mod file
- name: Install GitVersion
uses: gittools/actions/gitversion/[email protected]
with:
versionSpec: '5.x'
- name: Determine Version
id: gitversion
uses: gittools/actions/gitversion/[email protected]
if: inputs.release_version == ''
- name: Set version
id: set_version
run: |
if [ -n "${{ inputs.release_version }}" ]; then
echo "version=${{ inputs.release_version }}" >> $GITHUB_OUTPUT
else
echo "version=${{ steps.gitversion.outputs.semVer }}" >> $GITHUB_OUTPUT
fi
- name: Cache Go modules
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Build
run: |
cd redfish-exporter
# Generate API
cd api
make
cd ..
# Main build
go mod tidy
go mod verify
make
working-directory: ${{ github.workspace }}
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: redfish-exporter-${{ steps.set_version.outputs.version }}
path: redfish-exporter/amd-redfish-exporter
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.set_version.outputs.version }}
name: Release ${{ steps.set_version.outputs.version }}
draft: false
prerelease: false
files: |
./redfish-exporter/amd-redfish-exporter
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}