Skip to content

Commit

Permalink
feat(ci): Nightly update dependencies and cache (#102)
Browse files Browse the repository at this point in the history
* feat(ci): Enable grouping of dependabot PRs

* Update Python version and delete Bazel cache

* repin after update

* Automatically push updated files also

* fix push

* fixup

* fixup

* fixup

* fixup

* git gymanistics

* fix(ci): Update the reference to the gitlab api token (#98)

* fix(ci): Update the reference to the gitlab api token

* Fix reference to GitLab API token (#99)

* fix(ci): Cloning k8s repo to the correct directory (#103)

* fix(dashboard): Use Debian Slim base image for OCI images by default (#105)

* fix(dashboard): Use Ubuntu 22.04 base image for OCI images by default

* Use generic ubuntu image

* Use debian slim instead of Ubuntu, since ubuntu isn't defined

* fixup

* another attempt

* Use existing github action instead of reinventing the wheel

* Update dependencies

* Ready for prime time

---------

Co-authored-by: sasa-tomic <sasa-tomic@users.noreply.github.com>
  • Loading branch information
sasa-tomic and sasa-tomic committed Jan 24, 2024
1 parent c6a0501 commit 54491c6
Show file tree
Hide file tree
Showing 5 changed files with 1,150 additions and 1,138 deletions.
74 changes: 65 additions & 9 deletions .github/workflows/bazel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ jobs:
bazel:
runs-on: ubuntu-22.04
steps:

########################################
# Setup
########################################
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@v1.3.1
with:
Expand All @@ -21,6 +25,10 @@ jobs:
large-packages: false # this is slow
- uses: actions/checkout@v4
- uses: bazelbuild/setup-bazelisk@v2

########################################
# Download and unpack cache
########################################
- name: Mount bazel cache
uses: actions/cache@v3
with:
Expand All @@ -31,9 +39,39 @@ jobs:
key: ${{ runner.os }}-bazel-${{ hashFiles('.bazelversion', '.bazelrc', 'WORKSPACE', 'WORKSPACE.bazel', 'MODULE.bazel', 'Cargo.Bazel.lock') }}
restore-keys: |
${{ runner.os }}-bazel-
- name: If running on schedule (at night) and on main, completely delete bazel cache
########################################
# Once per night, update dependencies and completely delete and recreate bazel cache
########################################
- uses: actions/setup-python@v4
if: "${{github.event.schedule == '30 1 * * *' && github.ref == 'refs/heads/main'}}"
with:
python-version: "3.11"
- uses: snok/install-poetry@v1
if: "${{github.event.schedule == '30 1 * * *' && github.ref == 'refs/heads/main'}}"
- name: If running on schedule (at night) and on main, completely delete bazel cache then update deps
if: "${{github.event.schedule == '30 1 * * *' && github.ref == 'refs/heads/main'}}"
run: sudo rm -rf ~/.cache/bazel/*
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 //...
- uses: stefanzweifel/git-auto-commit-action@v5
if: "${{github.event.schedule == '30 1 * * *' && github.ref == 'refs/heads/main'}}"
with:
commit_message: Update dependencies

########################################
# Build and test
########################################
- name: Set GIT_HASH variable
run: |
set -eExou pipefail
Expand All @@ -45,15 +83,13 @@ jobs:
fi
- run: bazel build ...
- run: bazel test ...

########################################
# Prepare release
########################################
- name: Optimize bazel cache directory before uploading
run: bin/optimize-bazel-cache.sh
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get bazel binaries, so they can be pushed as GitHub artifacts in the next step
- name: Extract binaries from bazel, so they can be pushed as GitHub artifacts in the next steps
if: startsWith(github.ref, 'refs/tags/v')
run: |
set -eExuo pipefail
Expand All @@ -73,10 +109,24 @@ jobs:
prerelease: true
files: |
release/*
########################################
# 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') }}
env:
Expand Down Expand Up @@ -114,3 +164,9 @@ jobs:
-o merge_request.title="[nomrbot] - Updating container image refs mainnet-dashboard [$GITHUB_SHA]" \
-o merge_request.description="Changes to the release repository - [here](https://github.com/dfinity/dre/commit/$GITHUB_SHA)" \
--force --set-upstream origin "update-image-tag-${GITHUB_SHA}"
########################################
# Optimize bazel cache by hard-linking duplicate files
########################################
- name: Optimize bazel cache directory before uploading
run: bin/optimize-bazel-cache.sh

0 comments on commit 54491c6

Please sign in to comment.