Skip to content

Commit

Permalink
Move testing into reusable actions
Browse files Browse the repository at this point in the history
  • Loading branch information
mkjpryor committed Aug 17, 2023
1 parent f2e2847 commit b2e9102
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 95 deletions.
18 changes: 18 additions & 0 deletions .github/actions/destroy/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Azimuth CI destroy
description: Destroys an Azimuth CI environment.
inputs:
azimuth-ops-version:
description: >
The azimuth-ops version to use. If not given, the default version is used.
required: true
default: ""
runs:
using: composite
steps:
- name: Destroy Azimuth
shell: bash
# Make sure to source the ci environment before running the destroy
run: |
set -e
source ./ci.env
./bin/ci-exec destroy
30 changes: 30 additions & 0 deletions .github/actions/provision/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Azimuth CI provision
description: Provisions an Azimuth environment using the CI config.
inputs:
azimuth-ops-version:
description: >
The azimuth-ops version to use. If not given, the default version is used.
required: true
default: ""
runs:
using: composite
steps:
- name: Update azimuth-ops version in requirements.yml
shell: bash
run: cat > requirements.yml <<< "$REQUIREMENTS_CONTENT"
env:
REQUIREMENTS_CONTENT: |
---
collections:
- name: https://github.com/stackhpc/ansible-collection-azimuth-ops.git
type: git
version: ${{ inputs.azimuth-ops-version }}
if: ${{ inputs.azimuth-ops-version != '' }}

- name: Deploy Azimuth
shell: bash
# Make sure to source the ci environment before running the provision
run: |
set -e
source ./ci.env
./bin/ci-exec provision
47 changes: 47 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Azimuth CI setup
description: Sets up an environment for running Azimuth CI.
inputs:
config-ref:
description: The ref of the azimuth-config repo to check out.
required: true
default: feature/ci-external-actions
os-clouds:
description: The contents of the clouds.yaml to use.
required: true
os-cloud-name:
description: The name of the cloud within the clouds.yaml to use.
required: true
default: openstack
environment-prefix:
description: >
The environment prefix to use. The run ID will be appended to this,
separated by a hyphen.
required: true
default: ci
runs:
using: composite
steps:
- name: Checkout azimuth-config repo
uses: actions/checkout@v3
with:
repository: stackhpc/azimuth-config
ref: ${{ inputs.config-ref }}

- name: Write clouds.yaml
shell: bash
run: cat > ./clouds.yaml <<< "$OS_CLOUDS"
env:
OS_CLOUDS: ${{ inputs.os-clouds }}

# This environment file will be sourced before running any other actions
- name: Write environment file
shell: bash
run: cat > ./ci.env <<< "$CI_ENV"
env:
CI_ENV: |
set -a
OS_CLOUD="${{ inputs.os-cloud-name }}"
OS_CLIENT_CONFIG_FILE="$PWD/clouds.yaml"
AZIMUTH_CONFIG_ENVIRONMENT=ci
AZIMUTH_ENVIRONMENT="${{ inputs.environment-prefix }}-${{ github.run_id }}"
set +a
14 changes: 14 additions & 0 deletions .github/actions/test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Azimuth CI tests
description: Tests an Azimuth environment using the CI config.
# inputs:
runs:
using: composite
steps:
- name: Check expected alerts are pending or firing
shell: bash
# Make sure to source the ci environment before running the tests
run: |
set -e
source ./ci.env
source ./bin/activate $AZIMUTH_CONFIG_ENVIRONMENT $AZIMUTH_ENVIRONMENT
./bin/check-alerts
56 changes: 0 additions & 56 deletions .github/workflows/demo-deploy.yml

This file was deleted.

39 changes: 0 additions & 39 deletions .github/workflows/deployment-test.yml

This file was deleted.

54 changes: 54 additions & 0 deletions .github/workflows/test-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Test Azimuth deployment

on:
pull_request:
types:
- opened
- synchronize
- ready_for_review
- reopened
branches:
- main
paths-ignore:
- 'docs/**'

concurrency:
group: ${{ github.head_ref }}
cancel-in-progress: true

jobs:
# This job exists so that PRs from outside the main repo are rejected
fail_on_remote:
runs-on: ubuntu-latest
steps:
- name: PR must be from a branch in the azimuth-images repo
run: exit ${{ github.repository == 'stackhpc/azimuth-config' && '0' || '1' }}

# This job exists so that draft PRs see the check as failed
fail_on_draft:
runs-on: ubuntu-latest
steps:
- name: PR must be marked as ready for review before tests will run
run: exit ${{ github.event.pull_request.draft && '1' || '0' }}

run_azimuth_tests:
needs: [fail_on_remote, fail_on_draft]
runs-on: ubuntu-latest
steps:
- name: Set up Azimuth environment
uses: ./.github/actions/setup
with:
# Make sure to check out the config version under test
config-ref: ${{ github.sha }}
os-clouds: ${{ secrets.CLOUD }}
environment-prefix: ci

- name: Provision Azimuth
uses: ./.github/actions/provision

- name: Run Azimuth tests
uses: ./.github/actions/test

- name: Destroy Azimuth
uses: ./.github/actions/destroy
if: ${{ always() }}

0 comments on commit b2e9102

Please sign in to comment.