Homebrew Testing #20
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: Homebrew Testing | |
on: | |
workflow_dispatch: | |
inputs: | |
skip_signing: | |
description: 'Skip code signing' | |
required: true | |
default: false | |
type: boolean | |
release_tag: | |
description: 'Release tag' | |
required: true | |
type: string | |
push: | |
tags: | |
- 'v*' | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
INIT_IMAGE_NAME: ${{ github.repository }}-init | |
permissions: | |
contents: write | |
pull-requests: write | |
packages: write | |
id-token: write | |
attestations: write | |
jobs: | |
build-linux: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | |
- name: Setup Go | |
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2 | |
with: | |
go-version-file: 'go.mod' | |
- name: Run GoReleaser | |
uses: goreleaser/goreleaser-action@286f3b13b1b49da4ac219696163fb8c1c93e1200 #v6.0.0 | |
with: | |
version: latest | |
distribution: goreleaser | |
args: release --clean --snapshot --config ./.goreleaser.linux.yaml | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Upload Linux artifacts | |
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 | |
with: | |
name: dist-linux | |
if-no-files-found: error | |
retention-days: 7 | |
path: | | |
./dist/*.tar.gz | |
# Creates a release with the artifacts from the previous steps. | |
# workflow_dispatch triggered versions will be draft releases. | |
# CLI docs are not updated for workflow_dispatch triggered versions. | |
release: | |
runs-on: ubuntu-latest | |
needs: [build-linux] | |
steps: | |
# checkout the current repository | |
- name: Checkout kitops | |
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | |
with: | |
path: kitops | |
- name: List dirs after checkout kitops | |
run: | | |
ls | |
- name: List sub-dirs of kitops | |
run: | | |
shopt -s failglob | |
pushd kitops | |
ls | |
popd | |
- name: Merge built artifacts | |
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.3 | |
with: | |
path: dist | |
pattern: dist-* | |
merge-multiple: true | |
- name: List dirs after merge build artifacts | |
run: | | |
ls | |
- name: List sub-dirs of dist | |
run: | | |
shopt -s failglob | |
pushd dist | |
ls | |
popd | |
- name: Create Checksums | |
env: | |
TAG_NAME: ${{ inputs.release_tag}} | |
run: | | |
shopt -s failglob | |
pushd dist | |
shasum -a 256 kitops-* > checksums.txt | |
mv checksums.txt kitops_${TAG_NAME}_checksums.txt | |
ls | |
popd | |
# uses the checksums created above to generate the | |
# homebrew-metadata.txt file needed to generate the | |
# homebrew formula (kitops.rb) for the homebrew tap | |
# 'jozu-ai/homebrew-kitops' | |
- name: Create homebrew-metadata.txt | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
TAG_NAME: ${{ inputs.release_tag}} | |
REPO: ${{ github.repository }} | |
run: | | |
shopt -s failglob | |
pushd dist | |
awk ' | |
BEGIN { tag_name = ENVIRON["TAG_NAME"]; repo = ENVIRON["REPO"];} | |
/.tar.gz$/ { | |
print "\""$1"\"", | |
"\"https://github.com/" repo "/releases/download/" tag_name "/" $2 "\"", | |
$2, | |
tag_name }' kitops_${TAG_NAME}_checksums.txt | | |
awk '{ sub(/.tar.gz/, "", $3); print $1, $2, $3, $4 }' | | |
awk '{ sub(/kitops-/, "", $3); print $1, $2, $3, $4 }' | | |
awk '{sub(/v/, "", $4); print $1, $2, $3, $4 }' > homebrew-metadata.txt | |
mv homebrew-metadata.txt ../kitops/build/homebrew/homebrew-metadata.txt | |
popd | |
- name: List contents of kitops/build/homebrew dir | |
run: | | |
shopt -s failglob | |
pushd kitops/build/homebrew | |
ls | |
popd | |
# uses the homebrew-metadata.txt file generated in the | |
# previous step to generate the homebrew formula (kitops.rb) | |
# for the homebrew tap 'jozu-ai/homebrew-kitops' | |
- name: Create homebrew formula | |
run: | | |
shopt -s failglob | |
pushd kitops/build/homebrew | |
awk -f create-homebrew-recipe.awk homebrew-metadata.txt | |
popd | |
mkdir homebrew-recipe | |
cp ./kitops/build/homebrew/kitops.rb ./homebrew-recipe/. | |
- name: List contents of homebrew-recipe dir | |
run: | | |
shopt -s failglob | |
ls | |
pushd homebrew-recipe | |
ls | |
popd | |
# Commit the Homebrew Formula to the current repo: jozu-ai/kitops | |
- name: Commit Homebrew Formula | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
pushd kitops | |
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
PR_BRANCH="${{ github.ref_name }}-homebrew-update" | |
git fetch origin main | |
git branch "$PR_BRANCH" | |
git checkout "$PR_BRANCH" | |
git pull origin --ff-only "${PR_BRANCH}" || true | |
git config --global user.name "${GITHUB_ACTOR}" | |
git config --global user.email "${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com" | |
cd build/homebrew | |
git add --all | |
git commit -m "homebrew: update Homebrew Formula for ${{ github.ref_name }}" | |
git push origin "${PR_BRANCH}" | |
gh pr create --fill --base main --head "${PR_BRANCH}" | |
git checkout "${CURRENT_BRANCH}" | |
popd | |
# upload the homebrew recipe directory (and its contents) | |
# as an artifact to be used later when committing it to | |
# the repository: 'jozu-ai/homebrew-kitops', | |
# from within a separate job. | |
- name: Upload homebrew recipe as a build artifact | |
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 | |
with: | |
name: homebrew-recipe | |
if-no-files-found: error | |
retention-days: 7 | |
path: | | |
./homebrew-recipe | |
- name: Create Release | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
TAG_NAME: ${{ inputs.release_tag || github.ref_name}} | |
REPO: ${{ github.repository }} | |
DRAFT_RELEASE: ${{ github.event_name == 'workflow_dispatch' }} | |
run: | | |
echo "Creating release for ${TAG_NAME}" | |
release_args=( | |
${TAG_NAME} | |
./dist/*.* | |
--title "Release ${TAG_NAME}" | |
--generate-notes | |
--repo ${REPO} | |
) | |
if [[ "${DRAFT_RELEASE}" == "false" ]]; then | |
previous_release="$(gh release list --repo $REPO --limit 1 --json tagName --jq '.[] | .tagName ')" | |
echo "Previous release: ${previous_release}" | |
release_args+=( --latest ) | |
release_args+=( --verify-tag ) | |
release_args+=( --notes-start-tag "${previous_release}" ) | |
else | |
release_args+=( --draft ) | |
fi | |
gh release create "${release_args[@]}" | |
- name: Generate CLI documentation | |
shell: bash | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
TAG_NAME: ${{ inputs.release_tag || github.ref_name}} | |
run: | | |
pushd kitops | |
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
PR_BRANCH="${{ github.ref_name }}-docs-update" | |
git fetch origin main | |
git branch "$PR_BRANCH" | |
git checkout "$PR_BRANCH" | |
git pull origin --ff-only "${PR_BRANCH}" || true | |
git config --global user.name "${GITHUB_ACTOR}" | |
git config --global user.email "${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com" | |
(cd docs; npm pkg set version=$TAG_NAME) | |
./docs/src/docs/cli/generate.sh > /dev/null | |
git add --all | |
git commit -m "docs: update CLI documentation for ${{ github.ref_name }}" | |
git push origin "${PR_BRANCH}" | |
gh pr create --fill --base main --head "${PR_BRANCH}" | |
git checkout "${CURRENT_BRANCH}" | |
popd | |
# Publish the homebrew recipe (kitops.rb) to the repository: | |
# 'jozu-ai/homebrew-kitops' | |
publish-homebrew-tap-formula: | |
runs-on: ubuntu-latest | |
needs: [release] | |
steps: | |
# checkout the homebrew-kitops repository (jozu-ai/homebrew-kitops) | |
- name: Checkout homebrew-kitops | |
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | |
with: | |
###### CHANGE THIS TO jozu-ai/homebrew-kitops ###### | |
repository: brett-hodges/homebrew-kitops | |
ref: 'main' | |
path: homebrew-kitops | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: List dirs after checkout homebrew-kitops | |
run: | | |
ls | |
- name: List contents of homebrew-kitops | |
run: | | |
shopt -s failglob | |
pushd homebrew-kitops | |
ls | |
popd | |
- name: Download the build artifact for the homebrew recipe | |
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.3 | |
with: | |
name: homebrew-recipe | |
path: homebrew-recipe | |
merge-multiple: true | |
- name: List dirs after downloading homebrew-recipe artifact | |
run: | | |
ls | |
- name: List contents of homebrew-recipe | |
run: | | |
shopt -s failglob | |
pushd homebrew-recipe | |
ls | |
popd | |
# unset git config from previous checkout | |
- name: Unset git config | |
run: | | |
pushd homebrew-kitops | |
git config --unset-all http.https://github.com/.extraheader | |
popd | |
# checkout the homebrew-kitops repository (jozu-ai/homebrew-kitops) | |
- name: Checkout homebrew-kitops | |
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | |
with: | |
###### CHANGE THIS TO jozu-ai/homebrew-kitops ###### | |
repository: brett-hodges/homebrew-kitops | |
ref: 'main' | |
path: homebrew-kitops | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Commit Homebrew Formula to Tap | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
TAG_NAME: ${{ inputs.release_tag}} | |
##### CHANGE REPO TO jozu-ai/homebrew-kitops | |
REPO: "brett-hodges/homebrew-kitops" | |
run: | | |
pushd homebrew-kitops | |
cp ../homebrew-recipe/kitops.rb . | |
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
PR_BRANCH="${{ github.ref_name }}-homebrew-tap-update" | |
git fetch origin main | |
git branch "$PR_BRANCH" | |
git checkout "$PR_BRANCH" | |
git pull origin --ff-only "${PR_BRANCH}" || true | |
git config --global user.name "${GITHUB_ACTOR}" | |
git config --global user.email "${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com" | |
git add --all | |
git commit -m "homebrew: update Homebrew Tap Formula for ${{ github.ref_name }}" | |
git push origin "${PR_BRANCH}" | |
gh pr create --fill --base main --head "${PR_BRANCH}" | |
git checkout "${CURRENT_BRANCH}" | |
popd |