Skip to content

Commit

Permalink
fix(ci): Prepare releases as a GH composite action instead of a workf…
Browse files Browse the repository at this point in the history
…low (#134)

* fix(ci): Prepare releases as a GH composite action instead of a workflow

* Provide shell

* Final touches

* Restore releasing only on tags
  • Loading branch information
sasa-tomic committed Jan 30, 2024
1 parent 3d44ffd commit d1fe2c7
Show file tree
Hide file tree
Showing 12 changed files with 161 additions and 171 deletions.
29 changes: 11 additions & 18 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,50 +17,43 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- name: Setup runner
- name: "☁️ Setup runner"
uses: ./.github/workflows/manage-runner-pre

########################################
# Build and test
########################################
- run: bazel build ...
name: Building
- name: "🚀 Building"
run: bazel build ...
- run: bazel test ...
name: Testing
name: "🚀 Testing"

########################################
# Prepare release
########################################
- name: Upload artifact for release
uses: actions/upload-artifact@v2
if: startsWith(github.ref, 'refs/tags/v')
- name: "🚢 Prepare release"
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
uses: ./.github/workflows/prepare-release
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
with:
ARTIFACT_NAME: dre
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

########################################
# Upload container images
########################################
- name: Login to GitHub Container Registry
- 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
- name: "📦 Push images to GitHub Container Registry"
if: ${{ startsWith(github.ref, 'refs/tags/v') || startsWith(github.head_ref, 'container') || 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
- name: "🤖 Update k8s deployments"
if: ${{ startsWith(github.ref, 'refs/tags/v') || startsWith(github.head_ref, 'container') || startsWith(github.ref, 'refs/heads/container') || (github.ref == 'refs/heads/main') }}
uses: ./.github/workflows/update-k8s-deployments
with:
Expand All @@ -70,4 +63,4 @@ jobs:
# Clean up runner
########################################
- uses: ./.github/workflows/manage-runner-post
name: Tear down runner
name: "🪓 Tear down runner"
4 changes: 2 additions & 2 deletions .github/workflows/manage-runner-post/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ runs:
########################################
# Optimize bazel cache by hard-linking duplicate files
########################################
- name: Optimize bazel cache directory before uploading
- name: "🧹 Optimize bazel cache directory before uploading"
if: ${{ github.ref == 'refs/heads/main' }}
run: ./bin/optimize-bazel-cache.sh
shell: bash
Expand All @@ -18,7 +18,7 @@ runs:
# Cache is saved on main only to avoid cache evictions due to github restrictions:
# https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache
########################################
- name: Saving cache on main only
- name: "☁️ ⬆️ Saving cache on main only"
if: ${{ github.ref == 'refs/heads/main' }}
uses: actions/cache/save@v3
with:
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/manage-runner-pre/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ runs:
########################################
# Setup
########################################
- name: Free Disk Space (Ubuntu)
- name: "🔧 Free Up Disk Space"
uses: jlumbroso/free-disk-space@v1.3.1
with:
# this might remove tools that are actually needed,
Expand All @@ -19,7 +19,7 @@ runs:
########################################
# Download and unpack cache
########################################
- name: Mount bazel cache
- name: "☁️ ⬇️ Restore bazel cache"
uses: actions/cache/restore@v3
with:
path: "~/.cache/bazel"
Expand All @@ -29,3 +29,9 @@ runs:
key: ${{ runner.os }}-bazel-${{ hashFiles('.bazelversion', '.bazelrc', 'WORKSPACE', 'WORKSPACE.bazel', 'MODULE.bazel', 'Cargo.Bazel.lock') }}
restore-keys: |
${{ runner.os }}-bazel-
- name: "🧹 Clean bazel cache if we're preparing a new release"
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
# This is desirable to make sure bazel does not use stale pre-built binaries
# Bazel actually keeps all intermediate objects so builds are still fast
run: bazel clean
shell: bash
8 changes: 4 additions & 4 deletions .github/workflows/mkdocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ jobs:
runs-on: ubuntu-22.04

steps:
- name: Checkout Repository
- name: "☁️ ⬇️ Checkout Repository"
uses: actions/checkout@v3

- name: Set up Python
- name: "🔧 Set up Python"
uses: actions/setup-python@v2
with:
python-version: 3.x

- name: Install dependencies
- name: "🔧 Install dependencies"
run: |
python -m pip install --upgrade pip
pip install mkdocs mkdocs-material
- name: Deploy to GitHub Pages
- name: "🚢 Deploy to GitHub Pages"
run: |
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Actions"
Expand Down
42 changes: 0 additions & 42 deletions .github/workflows/prepare-release.yml

This file was deleted.

29 changes: 29 additions & 0 deletions .github/workflows/prepare-release/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Prepare release
description: Prepare a new GitHub release

inputs:
github_token:
description: 'A GitHub token with permissions to create releases'
required: true

runs:
using: composite
steps:
- name: "⚒️ Extract binaries from bazel, so they can be pushed as GitHub artifacts in the next steps"
shell: bash
run: |
set -eExuo pipefail
# query the location of the bazel "dre" binary and copy it to the "release" directory
mkdir -p release
cp --dereference bazel-out/k8-opt/bin/rs/cli/dre release/dre
- name: "🆕 📢 Prepare release"
# v0.1.15
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844
with:
token: ${{ inputs.GITHUB_TOKEN }}
body_path: CHANGELOG.md
generate_release_notes: true
draft: true
prerelease: true
files: |
release/*
19 changes: 11 additions & 8 deletions .github/workflows/update-dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: ./.github/workflows/manage-runner-pre
name: Setup runner
- name: "🔧 Setup runner"
uses: ./.github/workflows/manage-runner-pre

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

- name: Completely delete bazel cache and then recreate it
- name: "⚒️ Completely delete bazel cache and then recreate it"
run: |
set -eExou pipefail
#
Expand All @@ -37,10 +39,11 @@ jobs:
sudo rm -rf ~/.cache/bazel/*
CARGO_BAZEL_REPIN=true bazel build ...
- uses: peter-evans/create-pull-request@v5
- name: "🆕 Create a new Pull Request with the changes"
uses: peter-evans/create-pull-request@v5
with:
commit-message: "chore: Update dependencies"
branch: bot-update-deps

- uses: ./.github/workflows/manage-runner-post
name: Tear down runner
- name: "🪓 Tear down runner"
uses: ./.github/workflows/manage-runner-post
3 changes: 2 additions & 1 deletion .github/workflows/update-k8s-deployments/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ inputs:
runs:
using: composite
steps:
- env:
- name: "☸️ Update k8s deployments"
env:
GITLAB_API_TOKEN: ${{ inputs.gitlab_api_token }}
shell: bash
run: |
Expand Down
Loading

0 comments on commit d1fe2c7

Please sign in to comment.