diff --git a/.github/workflows/branch-main.yml b/.github/workflows/branch-main.yml new file mode 100644 index 0000000..10119b6 --- /dev/null +++ b/.github/workflows/branch-main.yml @@ -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 + }) diff --git a/.github/workflows/molecule.yml b/.github/workflows/molecule.yml deleted file mode 100644 index e4f5e58..0000000 --- a/.github/workflows/molecule.yml +++ /dev/null @@ -1,36 +0,0 @@ -on: - workflow_call: - inputs: - role-path: - required: true - type: string - molecule-driver: - required: true - type: string -jobs: - molecule: - runs-on: ubuntu-22.04 - strategy: - fail-fast: false - env: - DRIVER: ${{ inputs.molecule-driver }} - steps: - - run: git config --global --add safe.directory "${{ github.repository }}" - - name: Checkout - uses: actions/checkout@v2 - with: - path: "${{ github.repository }}" - - name: Setup Python modules - uses: actions/setup-python@v2 - with: - python-version: '3.x' - - name: Setup LXD - if: ${{ inputs.molecule-driver == 'lxd' }} - uses: canonical/setup-lxd@v0.1.1 # https://github.com/canonical/setup-lxd - with: - channel: latest/stable - - name: Setup Python modules - run: pip3 install PyYAML==5.3.1 yamllint ansible ansible-lint molecule molecule-plugins[docker] molecule-lxd docker - - name: Run molecule - run: molecule test --all - working-directory: "${{ github.repository }}/${{ inputs.role-path }}" diff --git a/.github/workflows/node.yml b/.github/workflows/node.yml deleted file mode 100644 index 61d4cc7..0000000 --- a/.github/workflows/node.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: node role - -on: - pull_request: - paths: - - roles/node/** - - .github/** - push: - branches: - - main - paths: - - roles/node/** - - .github/** - -jobs: - call-workflow-molecule-with-lxd: - uses: ./.github/workflows/molecule.yml - with: - role-path: roles/node - molecule-driver: lxd - call-workflow-molecule-with-docker: - uses: ./.github/workflows/molecule.yml - with: - role-path: roles/node - molecule-driver: docker \ No newline at end of file diff --git a/.github/workflows/pr-check-version.yml b/.github/workflows/pr-check-version.yml new file mode 100644 index 0000000..61be3fd --- /dev/null +++ b/.github/workflows/pr-check-version.yml @@ -0,0 +1,8 @@ +name: check Galaxy version + +on: + pull_request: + +jobs: + check-version: + uses: ./.github/workflows/reusable-check-version.yml diff --git a/.github/workflows/pr-node.yml b/.github/workflows/pr-node.yml new file mode 100644 index 0000000..c8f1d0f --- /dev/null +++ b/.github/workflows/pr-node.yml @@ -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 }} diff --git a/.github/workflows/pr-ws-health-exporter.yml b/.github/workflows/pr-ws-health-exporter.yml new file mode 100644 index 0000000..88423c4 --- /dev/null +++ b/.github/workflows/pr-ws-health-exporter.yml @@ -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 }} diff --git a/.github/workflows/reusable-check-version.yml b/.github/workflows/reusable-check-version.yml new file mode 100644 index 0000000..35d3209 --- /dev/null +++ b/.github/workflows/reusable-check-version.yml @@ -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!') diff --git a/.github/workflows/reusable-galaxy-deploy.yml b/.github/workflows/reusable-galaxy-deploy.yml new file mode 100644 index 0000000..84de1a8 --- /dev/null +++ b/.github/workflows/reusable-galaxy-deploy.yml @@ -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 diff --git a/.github/workflows/reusable-molecule.yml b/.github/workflows/reusable-molecule.yml new file mode 100644 index 0000000..8a73cce --- /dev/null +++ b/.github/workflows/reusable-molecule.yml @@ -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/setup-lxd@v0.1.1 + with: + channel: latest/stable + - name: Run molecule tests + run: molecule test --all + working-directory: "${{ github.repository }}/roles/${{ inputs.role-name }}" diff --git a/.github/workflows/ws-health-exporter.yml b/.github/workflows/ws-health-exporter.yml deleted file mode 100644 index 7272dc1..0000000 --- a/.github/workflows/ws-health-exporter.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: ws_health_exporter role - -on: - pull_request: - paths: - - roles/ws_health_exporter/** - - .github/** - push: - branches: - - main - paths: - - roles/ws_health_exporter/** - - .github/** - -jobs: - call-workflow-molecule-with-lxd: - uses: ./.github/workflows/molecule.yml - with: - role-path: roles/ws_health_exporter - molecule-driver: lxd - call-workflow-molecule-with-docker: - uses: ./.github/workflows/molecule.yml - with: - role-path: roles/ws_health_exporter - molecule-driver: docker \ No newline at end of file diff --git a/.gitignore b/.gitignore index 9b847da..e0fdbf9 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ plan.out *service-account-key.json *.private_key_encrypted .idea -/ansible/collections \ No newline at end of file +/ansible/collections +venv \ No newline at end of file diff --git a/galaxy.yml b/galaxy.yml index 255d3ec..183fe0c 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -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 diff --git a/meta/runtime.yml b/meta/runtime.yml new file mode 100644 index 0000000..aafabf1 --- /dev/null +++ b/meta/runtime.yml @@ -0,0 +1 @@ +requires_ansible: ">=2.12.10" \ No newline at end of file diff --git a/roles/key_inject/README.md b/roles/key_inject/README.md new file mode 100644 index 0000000..2672394 --- /dev/null +++ b/roles/key_inject/README.md @@ -0,0 +1 @@ +# key_inject ansible role diff --git a/roles/ws_health_exporter/README.md b/roles/ws_health_exporter/README.md new file mode 100644 index 0000000..508a697 --- /dev/null +++ b/roles/ws_health_exporter/README.md @@ -0,0 +1 @@ +# ws_health_exporter ansible role diff --git a/roles/ws_health_exporter/molecule/default/collections.yml b/roles/ws_health_exporter/molecule/default/collections.yml deleted file mode 100644 index 7a0c167..0000000 --- a/roles/ws_health_exporter/molecule/default/collections.yml +++ /dev/null @@ -1,4 +0,0 @@ -collections: - - name: https://github.com/paritytech/ansible-galaxy.git - type: git - version: main diff --git a/roles/ws_health_exporter/molecule/default/collections.yml.bak b/roles/ws_health_exporter/molecule/default/collections.yml.bak new file mode 100644 index 0000000..7650095 --- /dev/null +++ b/roles/ws_health_exporter/molecule/default/collections.yml.bak @@ -0,0 +1,4 @@ +#collections: +# - name: https://github.com/paritytech/ansible-galaxy.git +# type: git +# version: main diff --git a/roles/ws_health_exporter/molecule/default/prepare.yml b/roles/ws_health_exporter/molecule/default/prepare.yml index 31a4d54..80a18fb 100644 --- a/roles/ws_health_exporter/molecule/default/prepare.yml +++ b/roles/ws_health_exporter/molecule/default/prepare.yml @@ -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 }}" @@ -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 }}" diff --git a/roles/ws_health_exporter/tasks/main.yml b/roles/ws_health_exporter/tasks/main.yml index a2abe7b..11895c4 100644 --- a/roles/ws_health_exporter/tasks/main.yml +++ b/roles/ws_health_exporter/tasks/main.yml @@ -36,7 +36,7 @@ - "prometheus-client==0.16.0" - "websocket-client==1.5.1" - "apscheduler==3.10.1" - - "flask==2.2.3" + - "flask==3.0.0" - "environs==9.5.0" - "waitress==2.1.2" virtualenv: "{{ _ws_health_exporter_venv }}"