WD-22448 - rocks deployment #17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Pack and Deploy | |
on: | |
push: | |
branches: | |
- main | |
- staging | |
workflow_dispatch: | |
inputs: | |
environment: | |
description: 'Environment (Production or Staging)' | |
required: true | |
type: choice | |
options: | |
- Staging | |
# - Production | |
pull_request: | |
jobs: | |
setup: | |
name: Setup | |
runs-on: ubuntu-latest | |
outputs: | |
environment: ${{ steps.set_env.outputs.environment }} | |
charm_changed: ${{ steps.check.outputs.charm_changed }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
# change environment=Production for refs/head/main when it's set up | |
# change target_ref=refs/heads/staging | |
- name: Determine environment | |
id: set_env | |
run: | | |
if [[ -n "${{ github.event.inputs.environment }}" ]]; then | |
echo "environment=${{ github.event.inputs.environment }}" >> "$GITHUB_OUTPUT" | |
elif [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then | |
echo "environment=Staging" >> "$GITHUB_OUTPUT" | |
echo "target_ref=refs/heads/main" >> "$GITHUB_OUTPUT" | |
else | |
echo "environment=Staging" >> "$GITHUB_OUTPUT" | |
echo "target_ref=refs/remotes/origin/staging" >> "$GITHUB_OUTPUT" | |
fi | |
- name: Check for charm/ changes | |
id: check | |
run: | | |
if [[ $(git diff --name-only ${{ steps.set_env.outputs.target_ref }} ${{ github.sha }} | grep '^charm/') ]]; then | |
echo "charm_changed=true" >> "$GITHUB_OUTPUT" | |
else | |
echo "charm_changed=false" >> "$GITHUB_OUTPUT" | |
fi | |
pack-rock: | |
name: Pack Rock | |
runs-on: ubuntu-latest | |
needs: setup | |
environment: ${{ needs.setup.outputs.environment }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
- 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 | |
- name: Pack rock | |
run: rockcraft pack | |
- name: Upload rock | |
id: upload | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ vars.CHARM_NAME }}-rock | |
path: ./*.rock | |
pack-charm: | |
name: Pack Charm | |
runs-on: ubuntu-latest | |
needs: setup | |
if: needs.setup.outputs.charm_changed == 'true' | |
environment: ${{ needs.setup.outputs.environment }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup LXD | |
uses: canonical/setup-lxd@main | |
- name: Setup charmcraft | |
run: sudo snap install charmcraft --classic --channel=latest/stable | |
- name: Fetch libs | |
run: | | |
cd ./charm | |
charmcraft fetch-libs | |
- name: Pack charm | |
run: charmcraft pack -v --project-dir ./charm | |
- name: Upload charm | |
id: upload | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ vars.CHARM_NAME }}-charm | |
path: ./*.charm |