Skip to content

Commit 68ddabe

Browse files
committed
improved caching
Signed-off-by: Akarsh Sahlot <akarshsahlot7@gmail.com>
1 parent a60ccfd commit 68ddabe

File tree

5 files changed

+85
-38
lines changed

5 files changed

+85
-38
lines changed

.github/workflows/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

.github/workflows/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
![act-logo](https://raw.githubusercontent.com/wiki/nektos/act/img/logo-150.png)
2+
3+
# Overview [![push](https://github.com/nektos/act/workflows/push/badge.svg?branch=master&event=push)](https://github.com/nektos/act/actions) [![Join the chat at https://gitter.im/nektos/act](https://badges.gitter.im/nektos/act.svg)](https://gitter.im/nektos/act?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Go Report Card](https://goreportcard.com/badge/github.com/nektos/act)](https://goreportcard.com/report/github.com/nektos/act) [![awesome-runners](https://img.shields.io/badge/listed%20on-awesome--runners-blue.svg)](https://github.com/jonico/awesome-runners)
4+
5+
> "Think globally, `act` locally"
6+
7+
Run your [GitHub Actions](https://developer.github.com/actions/) locally! Why would you want to do this? Two reasons:
8+
9+
- **Fast Feedback** - Rather than having to commit/push every time you want to test out the changes you are making to your `.github/workflows/` files (or for any changes to embedded GitHub actions), you can use `act` to run the actions locally. The [environment variables](https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables) and [filesystem](https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners#filesystems-on-github-hosted-runners) are all configured to match what GitHub provides.
10+
- **Local Task Runner** - I love [make](<https://en.wikipedia.org/wiki/Make_(software)>). However, I also hate repeating myself. With `act`, you can use the GitHub Actions defined in your `.github/workflows/` to replace your `Makefile`!
11+
12+
> [!TIP]
13+
> **Now Manage and Run Act Directly From VS Code!**<br/>
14+
> Check out the [GitHub Local Actions](https://sanjulaganepola.github.io/github-local-actions-docs/) Visual Studio Code extension which allows you to leverage the power of `act` to run and test workflows locally without leaving your editor.
15+
16+
# How Does It Work?
17+
18+
When you run `act` it reads in your GitHub Actions from `.github/workflows/` and determines the set of actions that need to be run. It uses the Docker API to either pull or build the necessary images, as defined in your workflow files and finally determines the execution path based on the dependencies that were defined. Once it has the execution path, it then uses the Docker API to run containers for each action based on the images prepared earlier. The [environment variables](https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables) and [filesystem](https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#file-systems) are all configured to match what GitHub provides.
19+
20+
Let's see it in action with a [sample repo](https://github.com/cplee/github-actions-demo)!
21+
22+
![Demo](https://raw.githubusercontent.com/wiki/nektos/act/quickstart/act-quickstart-2.gif)
23+
24+
# Act User Guide
25+
26+
Please look at the [act user guide](https://nektosact.com) for more documentation.
27+
28+
# Support
29+
30+
Need help? Ask on [Gitter](https://gitter.im/nektos/act)!
31+
32+
# Contributing
33+
34+
Want to contribute to act? Awesome! Check out the [contributing guidelines](CONTRIBUTING.md) to get involved.
35+
36+
## Manually building from source
37+
38+
- Install Go tools 1.20+ - (<https://golang.org/doc/install>)
39+
- Clone this repo `git clone git@github.com:nektos/act.git`
40+
- Run unit tests with `make test`
41+
- Build and install: `make install`
7.46 MB
Binary file not shown.
7.46 MB
Binary file not shown.
Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "build protobufs"
1+
name: "Build Protobufs"
22

33
on:
44
push:
@@ -14,24 +14,18 @@ on:
1414

1515
jobs:
1616
build:
17-
1817
strategy:
1918
matrix:
20-
# We only test on the oldest version we want to support and latest.
21-
# We trust that things also work for versions in the middle.
2219
os: [ubuntu-22.04, ubuntu-latest]
23-
# See Bazelisk README for legal values.
2420
bazel_version: [7.x, latest]
25-
# Don't abort other runs when one of them fails, to ease debugging.
2621
fail-fast: false
2722

2823
runs-on: ${{ matrix.os }}
2924

3025
env:
31-
# This tells Bazelisk (installed as `bazel`) to use specified version.
32-
# https://github.com/bazelbuild/bazelisk?tab=readme-ov-file#how-does-bazelisk-know-which-bazel-version-to-run
3326
USE_BAZEL_VERSION: ${{ matrix.bazel_version }}
3427
CACHE_KEY: ${{ matrix.os }}_bazel-${{ matrix.bazel_version }}
28+
BAZEL_DISK_CACHE: ~/.cache/bazel-disk
3529

3630
steps:
3731
- uses: actions/checkout@v4
@@ -41,10 +35,9 @@ jobs:
4135
- name: Mount bazel cache
4236
uses: actions/cache/restore@v4
4337
with:
44-
# See https://docs.bazel.build/versions/master/output_directories.html
45-
path: "~/.cache/bazel"
46-
# Create a new cache entry whenever Bazel files change.
47-
# See https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows
38+
path: |
39+
~/.cache/bazel
40+
~/.cache/bazel-disk
4841
key: ${{ env.CACHE_KEY }}-${{ hashFiles('**/*.bazel*', '**/*.bzl') }}
4942
restore-keys: |
5043
${{ env.CACHE_KEY }}
@@ -53,53 +46,45 @@ jobs:
5346
uses: josStorer/get-current-time@v2
5447
id: start-time
5548
with:
56-
# Unix timestamp -- seconds since 1970.
5749
format: X
5850

59-
- name: Build proto/
60-
run: cd proto && bazel build //... && bazel test //...
51+
- name: Build Protos
52+
run: |
53+
cd proto
54+
bazel build //... --disk_cache=${{ env.BAZEL_DISK_CACHE }} --jobs=$(nproc)
55+
bazel test //... --test_output=errors --jobs=$(nproc)
6156
62-
- name: Build bazel/example/using-bzlmod/
63-
run: cd bazel/example/using-bzlmod && bazel build //...
57+
- name: Build Bzlmod Example
58+
run: |
59+
cd bazel/example/using-bzlmod
60+
bazel build //... --disk_cache=${{ env.BAZEL_DISK_CACHE }} --jobs=$(nproc)
6461
65-
- name: Build bazel/example/using-workspace/
66-
run: cd bazel/example/using-workspace && bazel build //...
67-
# This is a legacy example that doesn't work beyond Bazel 7.x.
62+
- name: Build Workspace Example (Only for Bazel 7.x)
6863
if: ${{ env.USE_BAZEL_VERSION == '7.x' }}
64+
run: |
65+
cd bazel/example/using-workspace
66+
bazel build //... --disk_cache=${{ env.BAZEL_DISK_CACHE }} --jobs=$(nproc)
6967
7068
- name: Save end time
71-
# Always save the end time so we can calculate the build duration.
7269
if: always()
7370
uses: josStorer/get-current-time@v2
7471
id: end-time
7572
with:
76-
# Unix timestamp -- seconds since 1970.
7773
format: X
7874

79-
- name: Calculate build duration
80-
# Always calculate the build duration so we can update the cache if needed.
75+
- name: Calculate Build Duration
8176
if: always()
8277
run: |
8378
START=${{ steps.start-time.outputs.formattedTime }}
8479
END=${{ steps.end-time.outputs.formattedTime }}
85-
DURATION=$(( $END - $START ))
80+
DURATION=$(( END - START ))
8681
echo "duration=$DURATION" | tee "$GITHUB_ENV"
8782
88-
- name: Compress cache
89-
# Always compress the cache so we can update the cache if needed.
90-
if: always()
91-
run: rm -rf $(bazel info repository_cache)
92-
9383
- name: Save bazel cache
9484
uses: actions/cache/save@v4
95-
# Only create a new cache entry if we're on the main branch or the build takes >3mins.
96-
#
97-
# NOTE: Even though `always()` evaluates to true, and `true && x == x`,
98-
# the `always() &&` prefix is not redundant! The call to `always()` has a
99-
# side effect, which is to override the default behavior of automagically
100-
# canceling this step if a previous step failed.
101-
# (Don't blame me, blame GitHub Actions!)
10285
if: always() && (github.ref_name == 'main' || env.duration > 180)
10386
with:
104-
path: "~/.cache/bazel"
87+
path: |
88+
~/.cache/bazel
89+
~/.cache/bazel-disk
10590
key: ${{ env.CACHE_KEY }}-${{ hashFiles('**/*.bazel*', '**/*.bzl') }}-${{ github.run_id }}

0 commit comments

Comments
 (0)