Airdrop — Speed up your Laravel deployments by skipping asset compilation.

GitHub Actions Driver

Hammerstone Refine has not launched yet. Sign up for the early access list to stay up to date!

The GitHub Actions driver works as a part of your GitHub Workflows to cache built assets from run to run, even across branches.

When using the GitHub driver, there is no need for a remote disk anywhere. Instead, we rely on the Cache Action to cache the built files for us.

Configuration

The GitHub driver is an extension of the Filesystem driver so much of the configuration is the same, although fewer items are needed.

config/airdrop.php

1[
2 'drivers' => [
3 'github' => [
4 // Use in conjunction with the Cache step in GitHub Actions.
5 'class' => GithubActionsDriver::class,
6 
7 // Make sure this matches the `path` key in the
8 // cache step of your GitHub Actions Workflow.
9 'local_tmp_directory' => env('AIRDROP_LOCAL_TMP_DIR', '/tmp/'),
10 
11 // The skip file is an empty file that will be created to
12 // indicate that asset building can be skipped.
13 'skip_file' => env('AIRDROP_SKIP_FILE', base_path('.airdrop_skip')),
14 ]
15 ],
16]

local_tmp_directory is a place that Airdrop can use to create the .zip file before it is uploaded. This needs to match that path that you put in your [workflow].yml file.

skip_file is the file we referenced in the deploying section. It's used as a signal to other processes that the built files have been successfully restored, and they do not need to be built again.

GitHub Workflow Configuration

There are a couple steps you'll need to add to your GitHub Workflow to take advantage of the asset caching.

The first step is to calculate the hash of the inputs and save it in the environment for the cache step to use:

.github/workflows/deploy.yml

1- name: Generate Airdrop Hash
2 run: echo "AIRDROP_HASH=$(php artisan airdrop:hash)" >> $GITHUB_ENV
Code highlighting powered by torchlight.dev, a Hammerstone product.

This command is going to run php artisan airdrop:hash to calculate the hash of all the inputs, and then it is going to store it as an environment variable named AIRDROP_HASH. This allows the cache step to look for the right key.

The next step you'll need to add is the cache step:

.github/workflows/deploy.yml

1- name: Generate Airdrop Hash
2 run: echo "AIRDROP_HASH=$(php artisan airdrop:hash)" >> $GITHUB_ENV
3 
4- name: Cache Airdrop Assets
5 uses: actions/cache@v2
6 with:
7 key: ${{ runner.os }}-airdrop-${{ env.AIRDROP_HASH }}
8 path: /tmp/airdrop-*

This step will cache the built zip file from Airdrop, and save it for up to seven days, per GitHub's usage limits. (Remember that if a cache misses, your app will simply rebuild the assets!)