Skip to content

Merge pull request #16 from alvarosanchez/agent/profile-list-repo-name #12

Merge pull request #16 from alvarosanchez/agent/profile-list-repo-name

Merge pull request #16 from alvarosanchez/agent/profile-list-repo-name #12

Workflow file for this run

name: Release
on:
push:
tags:
- "v*"
permissions:
contents: write
jobs:
build-native:
name: Build (${{ matrix.artifact_suffix }})
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- runner: ubuntu-latest
artifact_suffix: linux-x86_64
extension: ""
run_verification: true
- runner: windows-latest
artifact_suffix: windows-x86_64
extension: ".exe"
run_verification: false
- runner: macos-15-intel
artifact_suffix: macos-x86_64
extension: ""
run_verification: false
- runner: macos-latest
artifact_suffix: macos-aarch64
extension: ""
run_verification: false
steps:
- name: Checkout source
uses: actions/checkout@v6
- name: Set up Oracle GraalVM for JDK 25
uses: graalvm/setup-graalvm@v1
with:
java-version: "25"
distribution: "graalvm"
github-token: ${{ secrets.GITHUB_TOKEN }}
cache: gradle
native-image-job-reports: "true"
- name: Derive version from tag
id: version
shell: bash
run: |
TAG="${GITHUB_REF_NAME}"
VERSION="${TAG#v}"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
- name: Run build
if: ${{ matrix.run_verification }}
shell: bash
run: ./gradlew --no-daemon -PreleaseVersion="${{ steps.version.outputs.version }}" build
- name: Run native tests
if: ${{ matrix.run_verification }}
shell: bash
run: ./gradlew --no-daemon -PreleaseVersion="${{ steps.version.outputs.version }}" nativeTest
- name: Build native executable
shell: bash
run: ./gradlew --no-daemon -PreleaseVersion="${{ steps.version.outputs.version }}" nativeCompile
- name: Package artifact
shell: bash
run: |
mkdir -p dist
SOURCE_BIN="build/native/nativeCompile/ocp${{ matrix.extension }}"
TARGET_BIN="dist/ocp-${{ steps.version.outputs.version }}-${{ matrix.artifact_suffix }}${{ matrix.extension }}"
cp "$SOURCE_BIN" "$TARGET_BIN"
- name: Upload artifact
uses: actions/upload-artifact@v6
with:
name: ocp-${{ matrix.artifact_suffix }}
path: dist/*
publish:
name: Publish Release
needs: build-native
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: actions/download-artifact@v7
with:
path: dist
merge-multiple: true
- name: Generate checksums
shell: bash
run: |
cd dist
shasum -a 256 * > checksums.txt
- name: Create GitHub release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: ocp ${{ github.ref_name }}
generate_release_notes: true
files: dist/*
update-homebrew-tap:
name: Update Homebrew Tap
needs: publish
if: ${{ startsWith(github.ref_name, 'v') }}
runs-on: ubuntu-latest
steps:
- name: Derive release metadata
id: meta
shell: bash
run: |
set -euo pipefail
TAG="${GITHUB_REF_NAME}"
VERSION="${TAG#v}"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
- name: Fetch checksums from published release
id: checksums
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
set -euo pipefail
TAG="${{ steps.meta.outputs.tag }}"
VERSION="${{ steps.meta.outputs.version }}"
gh api "repos/${{ github.repository }}/releases/tags/${TAG}" > release.json
CHECKSUMS_URL=$(jq -r '.assets[]? | select(.name == "checksums.txt") | .browser_download_url' release.json)
if [ -z "${CHECKSUMS_URL}" ] || [ "${CHECKSUMS_URL}" = "null" ]; then
echo "checksums.txt release asset is missing for ${TAG}" >&2
exit 1
fi
curl --fail --silent --show-error --location --retry 5 --retry-delay 2 --retry-all-errors "${CHECKSUMS_URL}" -o checksums.txt
linux_sha=$(awk -v version="${VERSION}" '$2 == "ocp-" version "-linux-x86_64" { print $1 }' checksums.txt)
macos_x86_sha=$(awk -v version="${VERSION}" '$2 == "ocp-" version "-macos-x86_64" { print $1 }' checksums.txt)
macos_arm_sha=$(awk -v version="${VERSION}" '$2 == "ocp-" version "-macos-aarch64" { print $1 }' checksums.txt)
if [ -z "${linux_sha}" ] || [ -z "${macos_x86_sha}" ] || [ -z "${macos_arm_sha}" ]; then
echo "Failed to resolve release checksums from checksums.txt" >&2
cat checksums.txt >&2
exit 1
fi
echo "linux_sha=${linux_sha}" >> "$GITHUB_OUTPUT"
echo "macos_x86_sha=${macos_x86_sha}" >> "$GITHUB_OUTPUT"
echo "macos_arm_sha=${macos_arm_sha}" >> "$GITHUB_OUTPUT"
- name: Checkout tap repository
uses: actions/checkout@v6
with:
repository: alvarosanchez/homebrew-tap
token: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}
path: tap
- name: Update ocp formula
shell: bash
env:
VERSION: ${{ steps.meta.outputs.version }}
LINUX_SHA: ${{ steps.checksums.outputs.linux_sha }}
MACOS_X86_SHA: ${{ steps.checksums.outputs.macos_x86_sha }}
MACOS_ARM_SHA: ${{ steps.checksums.outputs.macos_arm_sha }}
run: |
set -euo pipefail
FORMULA_PATH="tap/Formula/ocp.rb"
export FORMULA_PATH
ruby <<'RUBY'
formula_path = ENV.fetch("FORMULA_PATH")
version = ENV.fetch("VERSION")
linux_sha = ENV.fetch("LINUX_SHA")
macos_x86_sha = ENV.fetch("MACOS_X86_SHA")
macos_arm_sha = ENV.fetch("MACOS_ARM_SHA")
content = File.read(formula_path)
updated = content.dup
version_pattern = /^ version ".*"$/
raise "Formula version line not found" unless updated.match?(version_pattern)
updated.sub!(version_pattern, " version \"#{version}\"")
sha_rules = [
[%r{(ocp-\#\{version\}-macos-aarch64"\n\s+sha256 ")([^"]+)(")}, macos_arm_sha, "macOS arm64"],
[%r{(ocp-\#\{version\}-macos-x86_64"\n\s+sha256 ")([^"]+)(")}, macos_x86_sha, "macOS x86_64"],
[%r{(ocp-\#\{version\}-linux-x86_64"\n\s+sha256 ")([^"]+)(")}, linux_sha, "Linux x86_64"]
]
sha_rules.each do |pattern, checksum, label|
replaced = updated.sub!(pattern, "\\1#{checksum}\\3")
raise "Could not update #{label} sha256 in formula" if replaced.nil?
end
File.write(formula_path, updated) if updated != content
RUBY
- name: Commit and push formula update
shell: bash
working-directory: tap
env:
VERSION: ${{ steps.meta.outputs.version }}
run: |
set -euo pipefail
if git diff --quiet -- Formula/ocp.rb; then
echo "No formula update needed"
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add Formula/ocp.rb
git commit -m "ocp ${VERSION}"
git push origin main