Skip to content

Commit

Permalink
Add CI.
Browse files Browse the repository at this point in the history
  • Loading branch information
ekhabarov committed Dec 11, 2023
1 parent e72ff9a commit 2366f9b
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions .github/workflows/ci.bazelrc
Original file line number Diff line number Diff line change
@@ -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
108 changes: 108 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
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/[email protected]
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.check-pr.version != 'vnull'
if: ${{ 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: Relnotes
run: echo "release notes" > release_notes.txt

- name: Reldata
run: echo "test" > data.txt

- name: Release
uses: softprops/action-gh-release@v1
with:
prerelease: true
draft: true
generate_release_notes: true
body_path: release_notes.txt
fail_on_unmatched_files: true
files: data.txt
37 changes: 37 additions & 0 deletions .github/workflows/release_prep.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2366f9b

Please sign in to comment.