Skip to content

Commit

Permalink
Use caching step
Browse files Browse the repository at this point in the history
  • Loading branch information
mateoflorido committed Apr 23, 2024
1 parent 653378b commit 05f31cd
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions .github/workflows/build-charm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,35 @@ 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: 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
with:
name: ${{ env.CHARM_NAME }}-charm
path: ${{ inputs.working-directory }}/${{ env.CHARM_FILE }}
path: ${{ inputs.working-directory }}/packed/${{ env.CHARM_FILE }}
if-no-files-found: error

0 comments on commit 05f31cd

Please sign in to comment.