Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: attempting to cleanup ci #113

Merged
merged 14 commits into from
Jan 25, 2024
169 changes: 0 additions & 169 deletions .github/workflows/bazel.yaml

This file was deleted.

70 changes: 70 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Build and test
on:
push:
branches:
- "main"
pull_request:
merge_group:
jobs:
bazel:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: ./.github/workflows/setup-bazel
name: Setup bazel

########################################
# Build and test
########################################
- name: Set GIT_HASH variable
run: |
set -eExou pipefail
# Set GIT_HASH variable based on the type of GitHub reference
if [[ "$GITHUB_REF_TYPE" == "tag" ]]; then
echo "GIT_HASH=$GITHUB_REF_NAME" >> "$GITHUB_ENV" # Embed tag name as GIT_HASH
else
echo "GIT_HASH=$GITHUB_SHA" >> "$GITHUB_ENV" # Embed commit SHA as GIT_HASH
fi
- run: bazel build ...
name: Building
- run: bazel test ...
name: Testing

########################################
# Prepare release
########################################
- name: Upload artifact for release
uses: actions/upload-artifact@v2
if: startsWith(github.ref, 'refs/tags/v')
with:
name: dre
path: bazel-out/k8-opt/bin/rs/cli/dre
- name: Call prepare release
if: startsWith(github.ref, 'refs/tags/v')
uses: ./.github/workflows/prepare-release.yml

########################################
# Upload container images
########################################
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push images to GitHub Container Registry
if: ${{ startsWith(github.ref, 'refs/tags/v') || startsWith(github.ref, 'refs/heads/container') || (github.ref == 'refs/heads/main') }}
run: bazel query --noshow_progress 'kind("oci_push", ...)' | xargs -I_target bazel run _target -- --tag ${GITHUB_SHA}

########################################
# Update k8s deployments
########################################
- name: Update k8s deployments
if: ${{ startsWith(github.ref, 'refs/tags/v') || startsWith(github.ref, 'refs/heads/container') || (github.ref == 'refs/heads/main') }}
uses: ./.github/workflows/update-k8s-deployments.yml

########################################
# Optimize bazel cache by hard-linking duplicate files
########################################
- name: Optimize bazel cache directory before uploading
run: bin/optimize-bazel-cache.sh
38 changes: 38 additions & 0 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Prepare release
on:
workflow_call:
inputs:
ARTIFACT_NAME:
required: true
description: "Name of the artifact to download"
type: string

jobs:
prepare:
runs-on: ubuntu-20.04
steps:
- name: Download built artifact
uses: actions/download-artifact@v2
with:
name: ${{ inputs.ARTIFACT_NAME }}

- name: Chmod
env:
ARTIFACT_NAME: ${{ inputs.ARTIFACT_NAME }}
run: chmod +x $ARTIFACT_NAME

- name: Prepare release
# v0.1.15
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844
with:
token: ${{ secrets.GITHUB_TOKEN }}
body_path: CHANGELOG.md
generate_release_notes: true
draft: true
prerelease: true
files: |
release/*
- uses: geekyeggo/delete-artifact@v4
with:
name: dre
31 changes: 31 additions & 0 deletions .github/workflows/setup-bazel/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Setup bazel
description: Reusable action for setting up bazel

runs:
using: composite
steps:
########################################
# Setup
########################################
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@v1.3.1
with:
# this might remove tools that are actually needed,
# when set to "true" but frees about 6 GB
tool-cache: true
large-packages: false # this is slow
- uses: bazelbuild/setup-bazelisk@v2

########################################
# Download and unpack cache
########################################
- name: Mount bazel cache
uses: actions/cache@v3
with:
path: "~/.cache/bazel"
# Configure cache updates
# https://github.com/actions/cache/blob/main/tips-and-workarounds.md#update-a-cache
# https://github.com/actions/cache/blob/main/examples.md#---bazel
key: ${{ runner.os }}-bazel-${{ hashFiles('.bazelversion', '.bazelrc', 'WORKSPACE', 'WORKSPACE.bazel', 'MODULE.bazel', 'Cargo.Bazel.lock') }}
restore-keys: |
${{ runner.os }}-bazel-
48 changes: 48 additions & 0 deletions .github/workflows/update-dependencies.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Update dependencies
on:
schedule:
# * is a special character in YAML so you have to quote this string
- cron: '30 1 * * *'

jobs:
update:
runs-on: ubuntu-20.04
steps:
- uses: ./.github/workflows/setup-bazel

########################################
# Once per night, update dependencies and completely delete and recreate bazel cache
########################################
- uses: actions/setup-python@v4
with:
python-version: "3.11"
- uses: snok/install-poetry@v1

- name: Completely delete bazel cache then update deps
run: |
set -eExou pipefail
#
# Completely delete bazel cache
#
sudo rm -rf ~/.cache/bazel/*
#
# Update dependencies
#
cargo update
poetry update
./bin/poetry-export.sh
CARGO_BAZEL_REPIN=true bazel query //...
- name: Build
run: bazel build ...

- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit-message: "chore: Update dependencies"
branch: bot-update-deps

########################################
# Optimize bazel cache by hard-linking duplicate files
########################################
- name: Optimize bazel cache directory before uploading
run: bin/optimize-bazel-cache.sh
Loading
Loading