Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

Commit

Permalink
ci(GITHUB): add caching to workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
niall-byrne committed Feb 17, 2023
1 parent fd41c14 commit 9077d14
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 39 deletions.
25 changes: 25 additions & 0 deletions .github/scripts/ansible_cache.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# .github/scripts/ansible_cache.sh
# Creates symlinks for attaching an external cache folder for Ansible.
# Separate folders for Roles, and Collections are maintained.

# 1: The absolute path of the mount point of the external cache folder.
# 2: The absolute path of the usage point of the cache on the system.

# CI only script

set -eo pipefail

main () {

MOUNT_FOLDER="${1}"
USAGE_FOLDER="${2}"

mkdir -p "${MOUNT_FOLDER}"

ln -sf "${MOUNT_FOLDER}" "${USAGE_FOLDER}"

}

main "$@"
17 changes: 0 additions & 17 deletions .github/scripts/build.sh

This file was deleted.

16 changes: 16 additions & 0 deletions .github/scripts/poetry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# .github/scripts/poetry.sh
# Centralized management of poetry installs.

# CI only script

set -eo pipefail

main () {

pip3 install poetry

}

main "$@"
3 changes: 2 additions & 1 deletion .github/scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ main() {
{
echo "ANSIBLE_ROLES_PATH=.."
echo "BRANCH_OR_TAG=${BRANCH_OR_TAG}"
echo "WEBHOOK_URL=${WEBHOOK_URL}"
echo "CACHE_TTL=$(date +%d)"
echo "NOTIFICATION=${PROJECT_NAME} [<${WORKFLOW_URL}|${BRANCH_OR_TAG}>]"
echo "WEBHOOK_URL=${WEBHOOK_URL}"
} >> "$GITHUB_ENV"

}
Expand Down
103 changes: 90 additions & 13 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,35 +174,65 @@ jobs:
steps:
- name: Molecule Lint -- Checkout Repository
uses: actions/checkout@v3
with:
path: 'role'

- name: Molecule Lint -- Setup Environment
run: |
source ./role/.github/scripts/setup.sh
env:
WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}

- name: Molecule Lint -- Install Poetry
run: |
source ./role/.github/scripts/poetry.sh
- name: Molecule Lint -- Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Molecule Lint -- Setup Environment
- name: Molecule Lint -- Initialize Cache Locations
run: |
source ./.github/scripts/setup.sh
env:
WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
mkdir -p ~/.cache/pypoetry/virtualenvs/
source ./role/.github/scripts/ansible_cache.sh \
"$(pwd)/ansible_cache/ansible-compat" \
~/.cache/ansible-compat
source ./role/.github/scripts/ansible_cache.sh \
"$(pwd)/ansible_cache/molecule" \
~/.cache/molecule
- name: Molecule Lint -- Mount Ansible Cache
uses: actions/cache@v3
with:
key: ansible-${{ hashFiles('./role/requirements.yml') }}-${{ env.CACHE_TTL }}
path: ansible_cache

- name: Molecule Lint -- Mount Poetry Cache
uses: actions/cache@v3
with:
key: poetry-${{ hashFiles('./role/pyproject.toml') }}-${{ runner.os }}-${{ env.CACHE_TTL }}
path: ~/.cache/pypoetry/virtualenvs/

- name: Molecule Lint -- Install Requirements
run: |
source ./.github/scripts/build.sh
cd role
poetry install
- name: Molecule Lint -- Run Linter
run: |
cd role
poetry run molecule lint
- name: Molecule Lint -- Report Job Status (Success)
if: env.VERBOSE_NOTIFICATIONS == '1'
run: |
./.github/scripts/notifications.sh "${NOTIFICATION}" ":white_check_mark: molecule linting was successful!"
./role/.github/scripts/notifications.sh "${NOTIFICATION}" ":white_check_mark: molecule linting was successful!"
- name: Molecule Lint -- Report Job Status (Failure)
if: failure()
run: |
./.github/scripts/notifications.sh "${NOTIFICATION}" ":x: molecule linting has failed!"
./role/.github/scripts/notifications.sh "${NOTIFICATION}" ":x: molecule linting has failed!"
osx_build:

Expand All @@ -218,36 +248,83 @@ jobs:
steps:
- name: OSX Build -- Checkout
uses: actions/checkout@v3
with:
path: 'role'

- name: OSX Build -- Setup Environment
run: |
source ./role/.github/scripts/setup.sh
env:
WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}

- name: OSX Build -- Install Poetry
run: |
source ./role/.github/scripts/poetry.sh
- name: OSX Build -- Setup python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: OSX Build -- Setup Environment
- name: OSX Build -- Initialize Cache Locations
run: |
source ./.github/scripts/setup.sh
source ./.github/scripts/build.sh
mkdir -p ~/.cache/pypoetry/virtualenvs
source ./role/.github/scripts/ansible_cache.sh \
"$(pwd)/ansible_cache/ansible-compat" \
~/.cache/ansible-compat
source ./role/.github/scripts/ansible_cache.sh \
"$(pwd)/ansible_cache/molecule" \
~/.cache/molecule
- name: OSX Build -- Mount Ansible Cache
uses: actions/cache@v3
with:
key: ansible-${{ hashFiles('./role/requirements.yml') }}-${{ env.CACHE_TTL }}
path: ansible_cache

- name: OSX Build -- Mount Poetry Cache
uses: actions/cache@v3
with:
key: poetry-${{ hashFiles('./role/pyproject.toml') }}-${{ runner.os }}-${{ env.CACHE_TTL }}
path: ~/Library/Caches/pypoetry/virtualenvs

- name: OSX Build -- Install Requirements
run: |
cd role
poetry install
- name: OSX Build -- Reuse Cached Dependencies as Scenario
run: |
cd role
poetry run molecule dependency
mv ~/.cache/molecule/role/default ~/.cache/molecule/role/"${SCENARIO}"
env:
WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
SCENARIO: ${{ matrix.scenario }}

- name: OSX Build -- Molecule Scenario
run: |
cd role
poetry run molecule test -s "${SCENARIO}"
env:
SCENARIO: ${{ matrix.scenario }}

- name: OSX Build -- Reuse Scenario Dependencies as Cache
run: |
mv ~/.cache/molecule/role/"${SCENARIO}" ~/.cache/molecule/role/default
env:
SCENARIO: ${{ matrix.scenario }}

- name: OSX Build -- Report Job Status (Success)
if: env.VERBOSE_NOTIFICATIONS == '1'
run: |
./.github/scripts/notifications.sh "${NOTIFICATION}" ":white_check_mark: OSX ${{ matrix.os }}, molecule test scenario '${SCENARIO}' was successful"
./role/.github/scripts/notifications.sh "${NOTIFICATION}" ":white_check_mark: OSX ${{ matrix.os }}, molecule test scenario '${SCENARIO}' was successful"
env:
SCENARIO: ${{ matrix.scenario }}

- name: OSX Build -- Report Job Status (Failure)
if: failure()
run: |
./.github/scripts/notifications.sh "${NOTIFICATION}" ":x: OSX ${{ matrix.os }}, molecule test scenario '${SCENARIO}' failed!"
./role/.github/scripts/notifications.sh "${NOTIFICATION}" ":x: OSX ${{ matrix.os }}, molecule test scenario '${SCENARIO}' failed!"
env:
SCENARIO: ${{ matrix.scenario }}

Expand Down
33 changes: 25 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,41 +34,58 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
path: 'role'
ref: ${{ github.event.inputs.TAG }}

- name: Publish to Galaxy -- Code Checkout (published release)
if: github.event_name != 'workflow_dispatch'
uses: actions/checkout@v3
with:
fetch-depth: 0
path: 'role'

- name: Publish to Galaxy -- Setup Environment
run: |
source ./role/.github/scripts/setup.sh
env:
WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}

- name: Publish to Galaxy -- Install Poetry
run: |
source ./role/.github/scripts/poetry.sh
- name: Publish to Galaxy -- Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Publish to Galaxy -- Setup Environment
- name: Publish to Galaxy -- Initialize Cache Locations
run: |
source .github/scripts/setup.sh
env:
WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
mkdir -p ~/.cache/pypoetry/virtualenvs/
- name: Publish to Galaxy -- Mount Poetry Cache
uses: actions/cache@v3
with:
key: poetry-${{ hashFiles('./role/pyproject.toml') }}-${{ runner.os }}-${{ env.CACHE_TTL }}
path: ~/.cache/pypoetry/virtualenvs/

- name: Publish to Galaxy -- Install Requirements
run: |
pip install poetry
cd role
poetry install
- name: Publish to Galaxy -- Trigger Ansible Galaxy Import
run: |
poetry run ansible-galaxy role import ${USERNAME} ${PROJECT_NAME} --token ${API_KEY}
cd role
poetry run ansible-galaxy role import ${USERNAME} ${PROJECT_NAME} --token ${API_KEY}
env:
API_KEY: ${{ secrets.GALAXY_API_KEY }}

- name: Publish to Galaxy -- Report Job Status (Success)
run: |
./.github/scripts/notifications.sh "${NOTIFICATION}" ":white_check_mark: automated ansible galaxy import has been completed!"
./role/.github/scripts/notifications.sh "${NOTIFICATION}" ":white_check_mark: automated ansible galaxy import has been completed!"
- name: Publish to Galaxy -- Report Job Status (Failure)
if: failure()
run: |
./.github/scripts/notifications.sh "${NOTIFICATION}" ":x: automated ansible galaxy import has failed!"
./role/.github/scripts/notifications.sh "${NOTIFICATION}" ":x: automated ansible galaxy import has failed!"

0 comments on commit 9077d14

Please sign in to comment.