From 8e5517d559e8c8497c594915dd2c8881d05bb615 Mon Sep 17 00:00:00 2001 From: Mohammad Iskandarany <43501040+M7mdisk@users.noreply.github.com> Date: Fri, 26 Jul 2024 13:34:28 +0300 Subject: [PATCH] CI: add publish_charm workflow (#1909) --- .github/workflows/publish_charm.yaml | 89 ++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 .github/workflows/publish_charm.yaml diff --git a/.github/workflows/publish_charm.yaml b/.github/workflows/publish_charm.yaml new file mode 100644 index 000000000..f839b001c --- /dev/null +++ b/.github/workflows/publish_charm.yaml @@ -0,0 +1,89 @@ +name: Build and publish charm +on: + push: + branches: + - charming-charmhub # TODO(mhdisk): Change this to main once we are ready to deploy +env: + CHARMCRAFT_ENABLE_EXPERIMENTAL_EXTENSIONS: true + ROCKCRAFT_ENABLE_EXPERIMENTAL_EXTENSIONS: true + +jobs: + pack-charm: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup LXD + uses: canonical/setup-lxd@main + + - name: Setup charmcraft + run: sudo snap install charmcraft --classic --channel=latest/edge + + - name: Fetch libs + run: | + cd ./charm + charmcraft fetch-libs + + - name: Pack charm + run: charmcraft pack -v --project-dir ./charm + + - name: Upload charm + env: + CHARMCRAFT_AUTH: ${{ secrets.CHARMHUB_TOKEN }} + run: charmcraft upload ./*.charm + + pack-rock: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Use Node.js + uses: actions/setup-node@v3 + + - name: Build assets + run: | + yarn install + yarn run build + + - name: Setup LXD + uses: canonical/setup-lxd@main + + - name: Setup rockcraft + run: sudo snap install rockcraft --classic --channel=latest/edge + + - name: Pack rock + run: rockcraft pack + + - name: Upload rock + uses: actions/upload-artifact@v3 + with: + name: charmhub-io-rock + path: ./*.rock + + publish-image: + runs-on: ubuntu-latest + needs: pack-rock + outputs: + image_url: ${{ steps.set_image_url.outputs.image_url }} + image_digest: ${{ steps.set_image_digest.outputs.image_url }} + steps: + - name: Get Rock + uses: actions/download-artifact@v3 + with: + name: charmhub-io-rock + + - name: Set image URL + id: set_image_url + run: echo "image_url=ghcr.io/canonical/charmhub.io:$(date +%s)-${GITHUB_SHA:0:7}" >> $GITHUB_OUTPUT + + - name: Push to GHCR + run: skopeo --insecure-policy copy oci-archive:$(ls *.rock) docker://${{ steps.set_image_url.outputs.image_url }} --dest-creds "canonical:${{ secrets.GITHUB_TOKEN }}" + - name: get image digest + id: set_image_digest + run: skopeo inspect --creds "canonical:${{ secrets.GITHUB_TOKEN }}" docker://${{ steps.set_image_url.outputs.image_url }} | jq '.Digest' >> $GITHUB_OUTPUT + - name: upload flask OCI image + env: + CHARMCRAFT_AUTH: ${{ secrets.CHARMHUB_TOKEN }} + run: charmcraft upload-resource charmhub-io flask-app-image --image=${{ needs.publish-image.outputs.image_url }} --verbosity=trace