From b7fbff14611e953f4caf3e7ec7b38c912201524d Mon Sep 17 00:00:00 2001 From: Ryan Parman Date: Sat, 30 Mar 2024 00:12:10 -0600 Subject: [PATCH] Added yamlfmt. --- .github/workflows/build-yamlfmt.yml | 96 +++++++++++++++++++++++++++++ packages/yamlfmt/.goreleaser.yml | 23 +++++++ packages/yamlfmt/download.sh | 18 ++++++ 3 files changed, 137 insertions(+) create mode 100644 .github/workflows/build-yamlfmt.yml create mode 100644 packages/yamlfmt/.goreleaser.yml create mode 100644 packages/yamlfmt/download.sh diff --git a/.github/workflows/build-yamlfmt.yml b/.github/workflows/build-yamlfmt.yml new file mode 100644 index 0000000..b480b07 --- /dev/null +++ b/.github/workflows/build-yamlfmt.yml @@ -0,0 +1,96 @@ +--- +# This workflow uses actions that are not certified by GitHub. They are provided +# by a third-party and are governed by separate terms of service, privacy +# policy, and support documentation. + +################################################################################ +# DO NOT EDIT THIS FILE! +# +# 1. Edit the *.gotmpl.yml files instead. +# 2. Run 'go run generate-workflow.go -p {package} -t {template}'. +################################################################################ + +name: Build yamlfmt +on: + workflow_dispatch: + push: + branches: [main] + paths: + - ".github/workflows/build-yamlfmt.yml" + pull_request: + branches: [main] + paths: + - ".github/workflows/build-yamlfmt.yml" + schedule: + - cron: '20 17 * * *' + +# Variables available to all jobs defined in this file +env: + DOCKER_BUILDKIT: 1 + REGISTRY: ${{ vars.REGISTRY }} + +# Declare default permissions as read only. +permissions: read-all + +jobs: + lookup: + runs-on: ubuntu-latest + name: Lookup current version + permissions: + packages: write + contents: read + strategy: + fail-fast: false + + container: + image: ghcr.io/northwood-labs/package-builder/ubuntu-v22.04:latest + credentials: + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + outputs: + cache_hit: ${{ steps.check.outputs.cache-hit }} + package_version: ${{ steps.lookup_version.outputs.package_version }} + + steps: + - name: Lookup latest version of package + id: lookup_version + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + echo "package_version=$(download-asset latest-tag -r 'google/yamlfmt' -s)" >> $GITHUB_OUTPUT + + - name: Check to see if we've already built this version + uses: actions/cache/restore@v4 + id: check + with: + key: "tenv-${{ steps.lookup_version.outputs.package_version }}" + path: "packages/yamlfmt/dist" + lookup-only: true + + build: + if: needs.lookup.outputs.cache_hit != 'true' + needs: lookup + name: Build and cache + uses: northwood-labs/package-building/.github/workflows/build-and-cache.yml@main + secrets: inherit + with: + package-name: "yamlfmt" + package-version: ${{ needs.lookup.outputs.package_version }} + + upload: + if: needs.lookup.outputs.cache_hit != 'true' + needs: build + name: Upload to S3 + uses: northwood-labs/package-building/.github/workflows/upload-to-s3.yml@main + secrets: inherit + with: + package-name: "yamlfmt" + package-version: ${{ needs.lookup.outputs.package_version }} + + metadata: + if: needs.lookup.outputs.cache_hit != 'true' + needs: upload + name: Generate metadata + uses: northwood-labs/package-building/.github/workflows/generate-rpm-meta.yml@main + secrets: inherit diff --git a/packages/yamlfmt/.goreleaser.yml b/packages/yamlfmt/.goreleaser.yml new file mode 100644 index 0000000..f1693ba --- /dev/null +++ b/packages/yamlfmt/.goreleaser.yml @@ -0,0 +1,23 @@ +--- +# https://goreleaser.com/customization/project/ +project_name: yamlfmt + +variables: + Vendor: yamlfmt authors + VendorHomepage: https://github.com/google/yamlfmt + License: MIT + Description: | + An extensible command line tool or library to format YAML files. + +# https://goreleaser.com/customization/includes/ +includes: + - from_file: + path: ../shared.yml + +# https://goreleaser.com/customization/hooks/ +before: + hooks: + - cmd: | + bash ./download.sh + output: true + dir: . diff --git a/packages/yamlfmt/download.sh b/packages/yamlfmt/download.sh new file mode 100644 index 0000000..2e31792 --- /dev/null +++ b/packages/yamlfmt/download.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +set -euo pipefail + +# linux/amd64 (Intel64) +download-asset get \ + --owner-repo "google/yamlfmt" \ + --pattern "yamlfmt_{{.Ver}}_Linux_x86_64.{{.Ext}}" \ + --archive-path "yamlfmt" \ + --write-to-bin "yamlfmt_amd64" \ + ; + +# linux/arm64 (ARM64) +download-asset get \ + --owner-repo "google/yamlfmt" \ + --pattern "yamlfmt_{{.Ver}}_Linux_arm64.{{.Ext}}" \ + --archive-path "yamlfmt" \ + --write-to-bin "yamlfmt_arm64" \ + ;