Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add CD #47

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/branch-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: main branch

on:
push:
branches:
- main

jobs:
run-molecule-tests:
strategy:
fail-fast: false
matrix:
role-names: [node, ws_health_exporter]
molecule-drivers: [docker, lxd]
# We test the latest version and minimum supported version
ansible-versions: [5.0.1, 8.4.0]
uses: ./.github/workflows/reusable-molecule.yml
with:
role-name: ${{ matrix.role-names }}
molecule-driver: ${{ matrix.molecule-drivers }}
ansible-version: ${{ matrix.ansible-versions }}
check-version:
uses: ./.github/workflows/reusable-check-version.yml
with:
compare-versions: false
deploy-galaxy:
needs: [run-molecule-tests, check-version]
uses: ./.github/workflows/reusable-galaxy-deploy.yml
secrets:
api-token: ${{ secrets.GALAXY_API_KEY }}
create-git-tag:
runs-on: ubuntu-22.04
needs: [deploy-galaxy, check-version]
env:
CURRENT_GALAXY_VERSION: ${{ needs.check-version.outputs.current-galaxy-version }}
steps:
- name: Print tag version
run: |
echo "Tag version: ${CURRENT_GALAXY_VERSION}"
- name: Create Tag
uses: actions/github-script@v6
with:
script: |
const {CURRENT_GALAXY_VERSION} = process.env
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${CURRENT_GALAXY_VERSION}`,
sha: context.sha
})
36 changes: 0 additions & 36 deletions .github/workflows/molecule.yml

This file was deleted.

25 changes: 0 additions & 25 deletions .github/workflows/node.yml

This file was deleted.

8 changes: 8 additions & 0 deletions .github/workflows/pr-check-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: check Galaxy version

on:
pull_request:

jobs:
check-version:
uses: ./.github/workflows/reusable-check-version.yml
18 changes: 18 additions & 0 deletions .github/workflows/pr-node.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: check PR (node)

on:
pull_request:
paths:
- roles/node/**
- .github/**

jobs:
run-molecule-tests:
strategy:
fail-fast: false
matrix:
molecule-driver: [lxd, docker]
uses: ./.github/workflows/reusable-molecule.yml
with:
role-name: node
molecule-driver: ${{ matrix.molecule-driver }}
18 changes: 18 additions & 0 deletions .github/workflows/pr-ws-health-exporter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: check PR (ws_health_exporter)

on:
pull_request:
paths:
- roles/ws_health_exporter/**
- .github/**

jobs:
run-molecule-tests:
strategy:
fail-fast: false
matrix:
molecule-driver: [lxd, docker]
uses: ./.github/workflows/reusable-molecule.yml
with:
role-name: ws_health_exporter
molecule-driver: ${{ matrix.molecule-driver }}
57 changes: 57 additions & 0 deletions .github/workflows/reusable-check-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
on:
workflow_call:
inputs:
compare-versions:
required: false
type: boolean
default: true
outputs:
current-galaxy-version:
description: "Current Galaxy version"
value: ${{ jobs.check-version.outputs.current-galaxy-version }}
jobs:
check-version:
runs-on: ubuntu-22.04
outputs:
current-galaxy-version: ${{ steps.check-current-version.outputs.current-galaxy-version }}
steps:
- name: Setup Python modules
run: pip3 install --no-cache-dir yq
- name: Checkout current ref
uses: actions/checkout@v4
with:
path: "${{ github.repository }}"
- name: Checkout main ref
if: ${{ inputs.compare-versions }}
uses: actions/checkout@v4
with:
ref: 'main'
path: "main/${{ github.repository }}"
- name: Check the current version
id: check-current-version
run: |
CURRENT_GALAXY_VERSION=$(cat ${GITHUB_REPOSITORY}/galaxy.yml | yq -r '.version' | tr -d '\n')
echo "Current Galaxy version: ${CURRENT_GALAXY_VERSION}"
if [ "$CURRENT_GALAXY_VERSION" != 'null' ]
then
echo "CURRENT_GALAXY_VERSION=${CURRENT_GALAXY_VERSION}" >> "${GITHUB_ENV}"
echo "current-galaxy-version=${CURRENT_GALAXY_VERSION}" >> "${GITHUB_OUTPUT}"
fi
- name: Check the version in the main branch
if: ${{ inputs.compare-versions }}
run: |
MAIN_GALAXY_VERSION=$(cat main/${GITHUB_REPOSITORY}/galaxy.yml | yq -r '.version' | tr -d '\n')
echo "Galaxy version in the main branch: ${MAIN_GALAXY_VERSION}"
echo "MAIN_GALAXY_VERSION=${MAIN_GALAXY_VERSION}" >> "${GITHUB_ENV}"
- name: Validate the current version
if: ${{ ! env.CURRENT_GALAXY_VERSION }}
uses: actions/github-script@v6
with:
script: |
core.setFailed('Your Galaxy version is absent or empty!')
- name: Compare versions
if: ${{ inputs.compare-versions && env.MAIN_GALAXY_VERSION >= env.CURRENT_GALAXY_VERSION }}
uses: actions/github-script@v6
with:
script: |
core.setFailed('Your Galaxy version is lower than the version in the main branch or equal. Please bump your version!')
40 changes: 40 additions & 0 deletions .github/workflows/reusable-galaxy-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
on:
workflow_call:
inputs:
ansible-version:
required: false
type: string
default: 8.4.0
secrets:
api-token:
required: true
jobs:
deploy-galaxy:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
with:
path: "${{ github.repository }}"
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Setup Python modules
# PyYAML==5.3.1 fixes the 'The license_file parameter is deprecated, use license_files instead.' error
# the 5.4.1 version still has the issue
run: pip3 install --no-cache-dir PyYAML==5.3.1 ansible==${{ inputs.ansible-version }} yq
- name: Print Ansible version
run: ansible --version
- name: Build collection
run: ansible-galaxy collection build "${{ github.repository }}"
- name: Save API token
run: echo '${{ secrets.api-token }}' > api-token
- name: Publish collection
run: |
GALAXY_NAMESPACE=$(cat ${GITHUB_REPOSITORY}/galaxy.yml | yq -r '.namespace' | tr -d '\n')
GALAXY_NAME=$(cat ${GITHUB_REPOSITORY}/galaxy.yml | yq -r '.name' | tr -d '\n')
VERSION=$(cat ${GITHUB_REPOSITORY}/galaxy.yml | yq -r '.version' | tr -d '\n')
ansible-galaxy collection publish ${GALAXY_NAMESPACE}-${GALAXY_NAME}-${VERSION}.tar.gz --api-key="$(cat api-token | tr -d '\n')"
- name: Remove API token
run: rm -v api-token
42 changes: 42 additions & 0 deletions .github/workflows/reusable-molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
on:
workflow_call:
inputs:
role-name:
required: true
type: string
molecule-driver:
required: true
type: string
ansible-version:
required: false
type: string
default: 8.4.0
jobs:
molecule:
runs-on: ubuntu-22.04
env:
DRIVER: ${{ inputs.molecule-driver }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
path: "${{ github.repository }}"
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Setup Python modules
# PyYAML==5.3.1 fixes the 'The license_file parameter is deprecated, use license_files instead.' error
# 5.4.1 version still has the issue
run: pip3 install --no-cache-dir PyYAML==5.3.1 yamllint ansible==${{ inputs.ansible-version }} ansible-lint molecule molecule-plugins[docker] molecule-lxd docker
- name: Print Ansible version
run: ansible --version
- name: Setup LXD
if: ${{ inputs.molecule-driver == 'lxd' }}
# https://github.com/canonical/setup-lxd
uses: canonical/[email protected]
with:
channel: latest/stable
- name: Run molecule tests
run: molecule test --all
working-directory: "${{ github.repository }}/roles/${{ inputs.role-name }}"
25 changes: 0 additions & 25 deletions .github/workflows/ws-health-exporter.yml

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ plan.out
*service-account-key.json
*.private_key_encrypted
.idea
/ansible/collections
/ansible/collections
venv
4 changes: 2 additions & 2 deletions galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
# The namespace of the collection. This can be a company/brand/organization or product namespace under which all
# content lives. May only contain alphanumeric lowercase characters and underscores. Namespaces cannot start with
# underscores or numbers and cannot contain consecutive underscores
namespace: parity
namespace: paritytech

# The name of the collection. Has the same character restrictions as 'namespace'
name: chain

# The version of the collection. Must be compatible with semantic versioning
version: 1.5.0
version: 1.5.1

# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
readme: README.md
Expand Down
1 change: 1 addition & 0 deletions meta/runtime.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requires_ansible: ">=2.12.10"
1 change: 1 addition & 0 deletions roles/key_inject/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# key_inject ansible role
1 change: 1 addition & 0 deletions roles/ws_health_exporter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# ws_health_exporter ansible role
4 changes: 0 additions & 4 deletions roles/ws_health_exporter/molecule/default/collections.yml

This file was deleted.

4 changes: 4 additions & 0 deletions roles/ws_health_exporter/molecule/default/collections.yml.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#collections:
# - name: https://github.com/paritytech/ansible-galaxy.git
# type: git
# version: main
5 changes: 2 additions & 3 deletions roles/ws_health_exporter/molecule/default/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
- name: "Include node alice"
# use include role to skip ansible-lint
ansible.builtin.include_role:
# use short name if you need local files or full name if you need specific version e.g. master
name: parity.chain.node
name: node
vars:
node_app_name: rococo-alice
node_data_root_path: "/opt/{{ node_app_name }}"
Expand All @@ -22,7 +21,7 @@
node_rpc_ws_port: "9944"
- name: "Include node bob"
ansible.builtin.include_role:
name: parity.chain.node
name: node
vars:
node_app_name: rococo-bob
node_data_root_path: "/opt/{{ node_app_name }}"
Expand Down
Loading