Skip to content

Commit

Permalink
Merge pull request #184 from cisco-en-programmability/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
bvargasre authored Sep 3, 2024
2 parents 0a344f5 + d99c193 commit 44f9fbe
Show file tree
Hide file tree
Showing 37 changed files with 5,183 additions and 619 deletions.
172 changes: 138 additions & 34 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@ parameters:
run-setup:
type: boolean
default: true
continued:
type: boolean
default: false
GHA_Event:
type: string
default: ""
GHA_Actor:
type: string
default: ""
GHA_Action:
type: string
default: ""
GHA_Meta:
type: string
default: ""
run-any:
type: boolean
default: false
Expand Down Expand Up @@ -53,20 +68,18 @@ parameters:
default: false
run-networkcompliance:
type: boolean
default: false
default: false
ansible_cisco_dnac_version:
type: string
default: "6.17.0"

jobs:

pre:
parameters:
ansible_cisco_dnac_version:
type: string
default: "6.9.0"

#machine: true
docker:
- image: python:3.8.10
resource_class: madhansansel/dnacenter-ansible
resource_class: madhansansel/dnacenter-ansible

steps:
- run:
Expand All @@ -77,16 +90,11 @@ jobs:
echo "CIRCLE_PROJECT_REPONAME: $CIRCLE_PROJECT_REPONAME"
echo "CIRCLE_PROJECT_BRANCHNAME: $CIRCLE_PROJECT_BRANCHNAME"
build:
parameters:
ansible_cisco_dnac_version:
type: string
default: "6.9.0"

build:
#machine: true
docker:
- image: python:3.8.10
resource_class: madhansansel/dnacenter-ansible
resource_class: madhansansel/dnacenter-ansible
steps:
- run:
name: Debug information
Expand Down Expand Up @@ -120,7 +128,7 @@ jobs:
# Install ansible, dnacentersdk
pip install --upgrade pip
pip install -r test-requirements.txt
# Build collection and store resulting tarball in directory $HOME/.cache/v<< parameters.ansible_cisco_dnac_version >>/collection-tarballs
# Build collection and store resulting tarball in directory $HOME/.cache/v<< pipeline.parameters.ansible_cisco_dnac_version >>/collection-tarballs
ansible-galaxy collection build --force --output-path workspace/
- save_cache:
key: collection-<< pipeline.git.revision >>
Expand All @@ -132,10 +140,14 @@ jobs:
- ~/.cache/pip

addrole:
parameters:
run-all:
type: boolean
default: false
#machine: true
docker:
- image: python:3.8.10
resource_class: madhansansel/dnacenter-ansible
resource_class: madhansansel/dnacenter-ansible

steps:
- run:
Expand Down Expand Up @@ -257,17 +269,21 @@ jobs:
paths:
- 'ccc_roles.yml'
sanity-tests:
parameters:
ansible_cisco_dnac_version:
type: string
default: "6.9.0"

#machine: true
docker:
- image: python:3.8.10
resource_class: madhansansel/dnacenter-ansible
resource_class: madhansansel/dnacenter-ansible
parallelism: 4
steps:
- when:
condition:
not: << pipeline.parameters.run-any >>
steps:
- run:
name: Finish sanity tests as there is nothing to execute
command: |
circleci-agent step halt
- run:
name: Debug information
command: |
Expand Down Expand Up @@ -319,15 +335,24 @@ jobs:
export ANSIBLE_ROLES_PATH=$PWD/tests/integration
cat ccc_roles.yml
echo $(circleci tests glob "tests/integration/*")
cat ccc_roles.yml | circleci tests run --command "xargs ./run_tests.sh" --split-by=timings --timings-type=name
echo -n 0 > rc
cat ccc_roles.yml | circleci tests run --command "xargs ./run_tests.sh" --split-by=timings --timings-type=name || echo -n $? > rc
echo ${LOGS_SSH_KEY} | base64 -d > ~/id_ssh
chmod 600 ~/id_ssh
export NO_PROXY=""
export no_proxy=""
ssh $LOGS_MACHINE -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ~/id_ssh mkdir -p /var/www/html/madhan-logs/$CIRCLE_BUILD_NUM
scp -i ~/id_ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null sanity_tests_logs_$CIRCLE_NODE_INDEX $LOGS_MACHINE:/var/www/html/madhan-logs/$CIRCLE_BUILD_NUM
echo "LOGS URL: http://10.195.243.37/madhan-logs/$CIRCLE_BUILD_NUM/sanity_tests_logs_$CIRCLE_NODE_INDEX"
if [[ $(cat rc) != "0" ]]; then exit 1; fi
no_output_timeout: 120m

post_pnp_testing:
#machine: true
docker:
- image: python:3.8.10
resource_class: madhansansel/dnacenter-ansible
resource_class: madhansansel/dnacenter-ansible

steps:
- when:
Expand All @@ -337,18 +362,56 @@ jobs:
command: |
python ${HOME}/static/pnp_script.py #TODO
main-pr:
docker:
- image: maniator/gh:v2.49.2
resource_class: madhansansel/dnacenter-ansible
steps:
- run:
name: Clone repo to workspace
command: git clone --depth=1 -b $CIRCLE_BRANCH https://github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME.git .
- run:
name: Create release pr to main
command: |
gh repo set-default $CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME
gh pr create --base main --head $CIRCLE_BRANCH --title "Release v<< pipeline.parameters.ansible_cisco_dnac_version >>" --body "Release v<< pipeline.parameters.ansible_cisco_dnac_version >>"
release-job:
docker:
- image: python:3.8.10
resource_class: madhansansel/dnacenter-ansible
steps:
- run:
name: Clone repo to workspace
command: |
git clone --depth=1 https://github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME.git .
git fetch origin $CIRCLE_BRANCH:work
git checkout work
- restore_cache:
keys:
- collection-<< pipeline.git.revision >>
# - add_ssh_keys:
# fingerprints:
# - "KEY_FINGERPRINT"
- run:
echo create release
#git tag -a v<< pipeline.parameters.ansible_cisco_dnac_version >> -m "Ansible DNACCollection Version v<< pipeline.parameters.ansible_cisco_dnac_version >>"
#gh release create "v<< pipeline.parameters.ansible_cisco_dnac_version >>" --title "DNAC Collection Version v<< pipeline.parameters.ansible_cisco_dnac_version >>" --latest
#ansible-galaxy collection publish workspace/*.tar.gz --api-key=$GALAXYKEY

workflows:

building:
when: << pipeline.parameters.run-setup >>
when:
and:
- or:
- equal: [ run-tests, << pipeline.parameters.GHA_Meta >> ]
# - equal: [ true, << pipeline.parameters.run-setup >> ]
- not: << pipeline.parameters.continued >>
jobs:
- pre

- build:
matrix:
parameters:
ansible_cisco_dnac_version:
- "6.9.0"
requires:
- pre

Expand All @@ -359,6 +422,7 @@ workflows:
config-path: .circleci/config.yml
mapping: |
.* run-setup false
.* continued true
plugins/.* run-any true
tests/integration/.* run-any true
Expand Down Expand Up @@ -394,19 +458,59 @@ workflows:
tests/integration/ccc_network_compliance_management/.* run-networkcompliance true
testing:
when: << pipeline.parameters.run-any >>
when:
or:
- equal: [ true, << pipeline.parameters.run-any >> ]
- equal: [ true, << pipeline.parameters.continued >> ]
jobs:
- addrole
- sanity-tests:
requires:
- addrole
context:
- dnac-servers
matrix:
parameters:
ansible_cisco_dnac_version:
- "6.9.0"
- logs-vm
# - post_pnp_testing:
# requires:
# - sanity-tests

release-candidate:
when:
or:
- equal: [ run-release-prep, << pipeline.parameters.GHA_Meta >> ]
jobs:
- build
- addrole:
matrix:
parameters:
run-all:
- true
- sanity-tests:
requires:
- addrole
- build
context:
- dnac-servers
- hold:
type: approval
requires:
- sanity-tests

- main-pr:
context:
- gh-token
requires:
- hold

release:
when:
or:
- equal: [ run-release, << pipeline.parameters.GHA_Meta >> ]
jobs:
- build
- release-job:
requires:
- build
context:
- gh-token
- galaxy-token
35 changes: 35 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## Description
Please include a summary of the changes and the related issue. Also, include relevant motivation and context.

## Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation update

## Checklist
- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream modules
- [ ] All the sanity checks have been completed and the sanity test cases have been executed

## Ansible Best Practices
- [ ] Tasks are idempotent (can be run multiple times without changing state)
- [ ] Variables and secrets are handled securely (e.g., using `ansible-vault` or environment variables)
- [ ] Playbooks are modular and reusable
- [ ] Handlers are used for actions that need to run on change

## Documentation
- [ ] All options and parameters are documented clearly.
- [ ] Examples are provided and tested.
- [ ] Notes and limitations are clearly stated.

## Screenshots (if applicable)

## Notes to Reviewers

25 changes: 25 additions & 0 deletions .github/workflows/automerge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: automerge
on:
pull_request:
types:
- labeled
- unlabeled
- synchronize
- opened
- edited
- ready_for_review
- reopened
- unlocked
pull_request_review:
types: [submitted]
jobs:
automerge-job:
runs-on: ubuntu-latest
steps:
- uses: reitermarkus/automerge@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
merge-method: rebase
do-not-merge-labels: never-merge
# pull-request: ${{ github.event.inputs.pull-request }}
dry-run: false
22 changes: 22 additions & 0 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: integration-tests
on:
workflow_run:
workflows:
- main
jobs:
trigger-circleci:
runs-on: ubuntu-20.04
if: github.event.workflow_run.conclusion == 'success'
steps:
- uses: actions/download-artifact@v4
with:
name: github_ref-${{ github.event.workflow_run.id }}
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Trigger circleci
run: |
printf '{"branch": "%s" ,"parameters": {"GHA_Meta":"run-tests"}}' $(cat github_ref) > req_body
curl -X POST --location "https://circleci.com/api/v2/project/gh/madhansansel/dnacenter-ansible/pipeline" \
-H "Content-Type: application/json" \
-H "Circle-Token: ${{ secrets.CCI_TOKEN }}" \
-d "@req_body"
15 changes: 15 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: main
on:
pull_request_review:
types: [submitted]
jobs:
trigger-circleci:
if: github.event.review.state == 'approved'
runs-on: ubuntu-20.04
steps:
- run: echo -n "${GITHUB_REF}" | sed -r 's/^refs\///' | sed -r 's/merge/head/' > github_ref
- name: Store ref for circleci trigger
uses: actions/upload-artifact@v4
with:
name: github_ref-${{ github.run_id }}
path: github_ref
Loading

0 comments on commit 44f9fbe

Please sign in to comment.