Skip to content

Commit

Permalink
Merge pull request #37 from Dynatrace/add-github-action-for-sanity-check
Browse files Browse the repository at this point in the history
Add build and test stage
  • Loading branch information
WStechura authored Jun 21, 2024
2 parents 7957517 + 27ed92c commit 42b8298
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/actions/build-collection/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2024 Dynatrace LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: build-collection
description: Builds the collection

runs:
using: composite
steps:
- name: Download certificate
shell: bash
run: mkdir -p $FILES_DIR && wget https://ca.dynatrace.com/dt-root.cert.pem -P $FILES_DIR
- name: Build the collection
shell: bash
run: ansible-galaxy collection build . -vvv
26 changes: 26 additions & 0 deletions .github/actions/run-tests/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2024 Dynatrace LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: run-tests
description: Runs the tests

runs:
using: composite
steps:
- name: Install the collection
shell: bash
run: ansible-galaxy collection install dynatrace-oneagent*
- name: Run sanity test
shell: bash
run: pushd ~/.ansible/collections/ansible_collections/dynatrace/oneagent && ansible-test sanity && popd
26 changes: 26 additions & 0 deletions .github/actions/setup-build-environment/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2024 Dynatrace LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: setup-build-environment
description: Prepares build environment

runs:
using: composite
steps:
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install dependencies
shell: bash
run: pip install ansible
26 changes: 26 additions & 0 deletions .github/actions/upload-collection/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2024 Dynatrace LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: upload-collection
description: Uploads the collection locally

runs:
using: composite
steps:
- name: Publish artifact
uses: actions/upload-artifact@v4
with:
name: dynatrace-oneagent-${{ github.sha }}
retention-days: 7
path: dynatrace-oneagent*
37 changes: 37 additions & 0 deletions .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2024 Dynatrace LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Build and test
on:
pull_request:
branches: [ "*" ]
push:
branches: [ "*" ]
workflow_dispatch:
workflow_call:

env:
FILES_DIR: roles/oneagent/files

jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up environment
uses: ./.github/actions/setup-build-environment
- name: Build the collection
uses: ./.github/actions/build-collection
- name: Run tests
uses: ./.github/actions/run-tests
28 changes: 28 additions & 0 deletions .github/workflows/build-test-upload.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2024 Dynatrace LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Build, test and upload
on:
push:
branches: [ 'main' ]
workflow_dispatch:

jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Build and test
uses: ./.github/workflows/build-and-test.yaml
- name: Upload the collection
uses: ./.github/actions/upload-collection

0 comments on commit 42b8298

Please sign in to comment.