Skip to content

Commit

Permalink
Improve CI. (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein authored Jun 14, 2021
1 parent 0b25643 commit 1913a0d
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/extra-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: CI
on:
# Run CI against all pushes (direct commits, also merged PRs), Pull Requests
push:
pull_request:
# Run CI once per day (at 06:00 UTC)
# This ensures that even if there haven't been commits that we are still testing against latest version of ansible-test for each ansible-base version
schedule:
- cron: '0 6 * * *'
env:
NAMESPACE: community
COLLECTION_NAME: routeros

jobs:
extra-sanity:
name: Extra Sanity
runs-on: ubuntu-latest
steps:

- name: Check out code
uses: actions/checkout@v2
with:
path: ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Install ansible-core
run: pip install https://github.com/ansible/ansible/archive/devel.tar.gz --disable-pip-version-check

- name: Install collection dependencies
run: git clone --depth=1 --single-branch https://github.com/ansible-collections/community.internal_test_tools.git ./ansible_collections/community/internal_test_tools
# NOTE: we're installing with git to work around Galaxy being a huge PITA (https://github.com/ansible/galaxy/issues/2429)
# run: ansible-galaxy collection install community.internal_test_tools -p .

- name: Run sanity tests
run: ../../community/internal_test_tools/tools/run.py --color
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
82 changes: 82 additions & 0 deletions .github/workflows/import-galaxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: import-galaxy
on:
# Run CI against all pushes (direct commits, also merged PRs) to main, and all Pull Requests
push:
branches:
- main
pull_request:

env:
# Adjust this to your collection
NAMESPACE: community
COLLECTION_NAME: routeros

jobs:
build-collection:
name: Build collection artifact
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
with:
path: ./checkout

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Install ansible-core
run: pip install https://github.com/ansible/ansible/archive/devel.tar.gz --disable-pip-version-check

- name: Make sure galaxy.yml has version entry
run: >-
python -c
'import yaml ;
f = open("galaxy.yml", "rb") ;
data = yaml.safe_load(f) ;
f.close() ;
data["version"] = data.get("version") or "0.0.1" ;
f = open("galaxy.yml", "wb") ;
f.write(yaml.dump(data).encode("utf-8")) ;
f.close() ;
'
working-directory: ./checkout

- name: Build collection
run: ansible-galaxy collection build
working-directory: ./checkout

- name: Copy artifact into subdirectory
run: mkdir ./artifact && mv ./checkout/${{ env.NAMESPACE }}-${{ env.COLLECTION_NAME }}-*.tar.gz ./artifact

- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: ${{ env.NAMESPACE }}-${{ env.COLLECTION_NAME }}-${{ github.sha }}
path: ./artifact/

import-galaxy:
name: Import artifact with Galaxy importer
runs-on: ubuntu-latest
needs:
- build-collection
steps:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Install ansible-core
run: pip install https://github.com/ansible/ansible/archive/devel.tar.gz --disable-pip-version-check

- name: Install galaxy-importer
run: pip install galaxy-importer --disable-pip-version-check

- name: Download artifact
uses: actions/download-artifact@v2
with:
name: ${{ env.NAMESPACE }}-${{ env.COLLECTION_NAME }}-${{ github.sha }}

- name: Run Galaxy importer
run: python -m galaxy_importer.main ${{ env.NAMESPACE }}-${{ env.COLLECTION_NAME }}-*.tar.gz
10 changes: 10 additions & 0 deletions tests/sanity/extra/extra-docs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"include_symlinks": false,
"prefixes": [
"docs/docsite/"
],
"output": "path-line-column-message",
"requirements": [
"antsibull"
]
}
23 changes: 23 additions & 0 deletions tests/sanity/extra/extra-docs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
"""Check extra collection docs with antsibull-lint."""
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

import os
import sys
import subprocess


def main():
"""Main entry point."""
if not os.path.isdir(os.path.join('docs', 'docsite')):
return
p = subprocess.run(['antsibull-lint', 'collection-docs', '.'], check=False)
if p.returncode not in (0, 3):
print('{0}:0:0: unexpected return code {1}'.format(sys.argv[0], p.returncode))


if __name__ == '__main__':
main()
7 changes: 7 additions & 0 deletions tests/sanity/extra/no-unwanted-files.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"include_symlinks": true,
"prefixes": [
"plugins/"
],
"output": "path-message"
}
43 changes: 43 additions & 0 deletions tests/sanity/extra/no-unwanted-files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
"""Prevent unwanted files from being added to the source tree."""
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

import os
import sys


def main():
"""Main entry point."""
paths = sys.argv[1:] or sys.stdin.read().splitlines()

allowed_extensions = (
'.cs',
'.ps1',
'.psm1',
'.py',
)

skip_paths = set([
])

skip_directories = (
)

for path in paths:
if path in skip_paths:
continue

if any(path.startswith(skip_directory) for skip_directory in skip_directories):
continue

ext = os.path.splitext(path)[1]

if ext not in allowed_extensions:
print('%s: extension must be one of: %s' % (path, ', '.join(allowed_extensions)))


if __name__ == '__main__':
main()

0 comments on commit 1913a0d

Please sign in to comment.