diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..e91e944 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,13 @@ +# In code review, collapse generated files +docs/*.md linguist-generated=true + +################################# +# Configuration for 'git archive' +# See https://git-scm.com/docs/git-archive#ATTRIBUTES + +# Don't include examples in the distribution artifact, to reduce size. +# You may want to add additional exclusions for folders or files that users don't need. +examples export-ignore + +# Occasionally there's a need to "stamp" the release version into a file +ytt/version.bzl export-subst diff --git a/.github/workflows/ci.bazelrc b/.github/workflows/ci.bazelrc new file mode 100644 index 0000000..3b4aad2 --- /dev/null +++ b/.github/workflows/ci.bazelrc @@ -0,0 +1,15 @@ +# This file contains Bazel settings to apply on CI only. +# It is referenced with a --bazelrc option in the call to bazel in ci.yaml + +# Debug where options came from +build --announce_rc +# This directory is configured in GitHub actions to be persisted between runs. +# We do not enable the repository cache to cache downloaded external artifacts +# as these are generally faster to download again than to fetch them from the +# GitHub actions cache. +build --disk_cache=~/.cache/bazel +# Don't rely on test logs being easily accessible from the test runner, +# though it makes the log noisier. +test --test_output=errors +# Allows tests to run bazelisk-in-bazel, since this is the cache folder used +test --test_env=XDG_CACHE_HOME diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..555a53f --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,100 @@ +name: Main CI +on: + push: + branches: + - main + pull_request: + types: + - labeled + - unlabeled + - opened + - edited + - reopened + - synchronize + - ready_for_review + +concurrency: + group: ${{ github.ref }} + cancel-in-progress: true + +jobs: + bumper: + name: Validate Release Label and Notes + runs-on: ubuntu-latest + outputs: + version: ${{ steps.bump.outputs.version }} + steps: + - uses: actions/checkout@v4 + + - name: Set bump mode + id: mode + run: | + [[ ${{ github.ref }} == 'refs/heads/main' ]] && M="bump" || M="validate"; + echo "bump_mode=$M" >> $GITHUB_OUTPUT + + - uses: jefflinse/pr-semver-bump@v1.6.0 + name: Validate Pull Request Metadata + id: bump + with: + mode: ${{ steps.mode.outputs.bump_mode }} + repo-token: ${{ secrets.GITHUB_TOKEN }} + major-label: major release + minor-label: minor release + patch-label: patch release + noop-labels: not-a-release + release-notes-prefix: -- begin release notes -- + release-notes-suffix: -- end release notes -- + with-v: true + base-branch: true + + build: + name: Build and Test + runs-on: ubuntu-latest + needs: + - bumper + + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Cache Bazel + uses: actions/cache@v3 + with: + path: | + ~/.cache/bazel + key: bazel-cache-${{ hashFiles('**/BUILD.bazel', '**/*.bzl', 'WORKSPACE') }} + restore-keys: bazel-cache- + + - name: Build everything + env: + # Bazelisk will download bazel to here. + XDG_CACHE_HOME: ~/.cache/bazel-repo + run: bazel --bazelrc=.github/workflows/ci.bazelrc --bazelrc=.bazelrc build //... + + - name: Test everything + env: + # Bazelisk will download bazel to here. + XDG_CACHE_HOME: ~/.cache/bazel-repo + run: bazel --bazelrc=.github/workflows/ci.bazelrc --bazelrc=.bazelrc test //... + + release: + name: Release + runs-on: ubuntu-latest + if: ${{ github.ref == 'refs/heads/main' && needs.bumper.version != 'vnull' }} + needs: + - bumper + - build + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Prepare release notes and artifacts + run: .github/workflows/release_prep.sh ${{ needs.bumper.outputs.version }} > release_notes.txt + + - name: Release + uses: softprops/action-gh-release@v1 + with: + generate_release_notes: true + body_path: release_notes.txt + fail_on_unmatched_files: true + files: rules_ytt-*.tar.gz diff --git a/.github/workflows/release_prep.sh b/.github/workflows/release_prep.sh new file mode 100755 index 0000000..60b5cb0 --- /dev/null +++ b/.github/workflows/release_prep.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +set -o errexit -o nounset -o pipefail + +# Set by GH actions, see +# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables +TAG=${1} +# The prefix is chosen to match what GitHub generates for source archives +# This guarantees that users can easily switch from a released artifact to a source archive +# with minimal differences in their code (e.g. strip_prefix remains the same) +PREFIX="rules_ytt-${TAG:1}" +ARCHIVE="rules_ytt-$TAG.tar.gz" + +# NB: configuration for 'git archive' is in /.gitattributes +git archive --format=tar --prefix=${PREFIX}/ ${TAG} | gzip > $ARCHIVE +SHA=$(shasum -a 256 $ARCHIVE | awk '{print $1}') + +cat << EOF +Paste this snippet into your `WORKSPACE.bazel` file: + +\`\`\`starlark +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +http_archive( + name = "rules_ytt", + sha256 = "${SHA}", + strip_prefix = "${PREFIX}", + url = "https://github.com/ekhabarov/rules_ytt/releases/download/${TAG}/${ARCHIVE}", +) + +load("@rules_ytt//ytt:repositories.bzl", "rules_ytt_dependencies", "rules_ytt_register_toolchains") + +rules_ytt_dependencies() + +rules_ytt_register_toolchains() +\`\`\` +EOF