Skip to content

Commit

Permalink
only build package if they're not cached
Browse files Browse the repository at this point in the history
  • Loading branch information
pdabelf5 committed Apr 17, 2024
1 parent 000d7cc commit 1ff6f6b
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/build-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,46 @@ permissions:
contents: read

jobs:
vars:
name: Setup variables
runs-on: ubuntu-22.04
outputs:
go_code_md5: ${{ steps.vars.outputs.go_code_md5 }}
package_cache_hit: ${{ steps.package-cache.outputs.cache-hit }}
packaging_md5: ${{ steps.vars.outputs.packaging_md5 }}
actions_md5: ${{ steps.vars.outputs.actions_md5 }}
package_build_md5: ${{ steps.vars.outputs.package_build_md5 }}

steps:
- name: Checkout Repository
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2

- name: Output Variables
id: vars
run: |
go_code_md5=$(find . -type f \( -name "*.go" -o -name go.mod -o -name go.sum -o -name -o -name "*.proto" -o -name "*.pgo" -o -name "buf.yaml" -o -name "data-plane-api.yaml" \) -not -path "./site*" -exec md5sum {} + | LC_ALL=C sort | md5sum | awk '{ print $1 }')
echo "go_code_md5=$go_code_md5" >> $GITHUB_OUTPUT
packaging_md5=$(find scripts/packages nginx-agent.conf Makefile.packaging .nfpm.yml -type f -exec md5sum {} + | LC_ALL=C sort | md5sum | awk '{ print $1 }')
echo "packaging_md5=$packaging_md5" >> $GITHUB_OUTPUT
actions_md5=$(find .github -type f -exec md5sum {} + | LC_ALL=C sort | md5sum | awk '{ print $1 }')
echo "actions_md5=$actions_md5" >> $GITHUB_OUTPUT
package_build_md5=$(echo "$go_code_md5 $package_md5 | md5sum | awk '{ print $1 }'")
echo "package_build_md5=$package_build_md5" >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
- name: Fetch Cached Package Artifacts
id: package-cache
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: build
key: agent-packages-${{ steps.vars.outputs.package_build_md5 }}
lookup-only: true

build-packages:
if: ${{ needs.vars.outputs.package_cache_hit != 'true' }}
name: Build packages
runs-on: ubuntu-22.04
needs: [vars]
steps:
- name: Checkout Repository
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
Expand Down Expand Up @@ -60,3 +97,4 @@ jobs:
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: build
key: agent-v3-${{ needs.checks.outputs.go_code_md5 }}

0 comments on commit 1ff6f6b

Please sign in to comment.