Skip to content

Commit

Permalink
Cache Charm Builds (#78)
Browse files Browse the repository at this point in the history
Implement a caching step in the build charms action to speed up the testing process.
  • Loading branch information
mateoflorido authored Apr 25, 2024
1 parent 81caac3 commit d5ddc02
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
25 changes: 23 additions & 2 deletions .github/workflows/build-charm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,37 @@ jobs:
steps:
- uses: actions/[email protected]
- uses: canonical/[email protected]

- name: Get hash of the source
run: echo "SRC_HASH=${{ hashFiles('**/charms/**/*.yaml', '**/charms/**/*.py', '**/charms/**/requirements.txt') }}" >> $GITHUB_ENV

- name: Extract charm name
working-directory: ${{ inputs.working-directory }}
run: echo "CHARM_NAME=$([ -f charmcraft.yaml ] && yq '.name' charmcraft.yaml || echo UNKNOWN)" >> $GITHUB_ENV

- name: Cache charm output
id: cache-charm
uses: actions/cache@v4
with:
path: ${{ inputs.working-directory }}packed/
key: ${{ runner.os}}-${{ env.CHARM_NAME }}-charm-${{ env.SRC_HASH }}

- name: Use cached charm
if: ${{ env.CHARM_NAME != 'UNKNOWN' && steps.cache-charm.outputs.cache-hit == 'true' }}
working-directory: ${{ inputs.working-directory }}/${{ matrix.path }}
run: |
echo "CHARM_FILE=$(ls packed/${{env.CHARM_NAME}}_*.charm)" >> $GITHUB_ENV
- name: Pack charm
if: ${{ env.CHARM_NAME != 'UNKNOWN' && !cancelled() }}
if: ${{ env.CHARM_NAME != 'UNKNOWN' && !cancelled() && steps.cache-charm.outputs.cache-hit != 'true' }}
working-directory: ${{ inputs.working-directory }}/${{ matrix.path }}
run: |
sudo snap install charmcraft --classic --channel latest/stable
charmcraft pack -v
echo "CHARM_FILE=$(ls ${{env.CHARM_NAME}}_*.charm)" >> $GITHUB_ENV
mkdir -p packed
mv *.charm packed/
echo "CHARM_FILE=$(ls packed/${{env.CHARM_NAME}}_*.charm)" >> $GITHUB_ENV
- name: Upload charm artifact
if: ${{ env.CHARM_FILE != '' && !cancelled() }}
uses: actions/upload-artifact@v4
Expand Down
17 changes: 10 additions & 7 deletions charms/worker/k8s/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
ops >= 2.2.0
cosl == 0.0.8
pydantic == 1.*
charm-lib-reconciler @ git+https://github.com/charmed-kubernetes/charm-lib-reconciler@main
charm-lib-contextual-status @ git+https://github.com/charmed-kubernetes/charm-lib-contextual-status@main
charm-lib-node-base @ git+https://github.com/charmed-kubernetes/layer-kubernetes-node-base@main#subdirectory=ops
charm-lib-interface-external-cloud-provider @ git+https://github.com/charmed-kubernetes/charm-lib-interface-external-cloud-provider@main
charm-lib-contextual-status @ git+https://github.com/charmed-kubernetes/charm-lib-contextual-status@255dd4a23defc16dcdac832306e5f460a0f1200c
charm-lib-interface-external-cloud-provider @ git+https://github.com/charmed-kubernetes/charm-lib-interface-external-cloud-provider@e1c5fc69e98100a7d43c0ad5a7969bba1ecbcd40
charm-lib-node-base @ git+https://github.com/charmed-kubernetes/layer-kubernetes-node-base@9b212854e768f13c26cc907bed51444e97e51b50#subdirectory=ops
charm-lib-reconciler @ git+https://github.com/charmed-kubernetes/charm-lib-reconciler@f818cc30d1a22be43ffdfecf7fbd9c3fd2967502
cosl==0.0.8
ops==2.12.0
pydantic==1.10.15
PyYAML==6.0.1
typing_extensions==4.11.0
websocket-client==1.8.0

0 comments on commit d5ddc02

Please sign in to comment.