diff --git a/.github/workflows/build-charm.yaml b/.github/workflows/build-charm.yaml index 8caf7a53..638022bf 100644 --- a/.github/workflows/build-charm.yaml +++ b/.github/workflows/build-charm.yaml @@ -22,20 +22,35 @@ jobs: steps: - uses: actions/checkout@v4.1.1 - uses: canonical/setup-lxd@v0.1.1 + + - 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