From a373c9d311a7e80bca4e74327e9966da7aaa890e Mon Sep 17 00:00:00 2001 From: "wojciech.stechura" Date: Thu, 6 Jun 2024 09:12:11 +0200 Subject: [PATCH] Move workflow logic to actions --- .github/actions/build-collection/action.yaml | 26 ++++++++++ .github/actions/run-tests/action.yaml | 26 ++++++++++ .../setup-build-environment/action.yaml | 26 ++++++++++ .github/actions/upload-collection/action.yaml | 26 ++++++++++ .github/workflows/build-and-test.yaml | 34 +++++++++++++ .github/workflows/build-and-test.yml | 51 ------------------- .github/workflows/build-test-upload.yaml | 29 +++++++++++ 7 files changed, 167 insertions(+), 51 deletions(-) create mode 100644 .github/actions/build-collection/action.yaml create mode 100644 .github/actions/run-tests/action.yaml create mode 100644 .github/actions/setup-build-environment/action.yaml create mode 100644 .github/actions/upload-collection/action.yaml create mode 100644 .github/workflows/build-and-test.yaml delete mode 100644 .github/workflows/build-and-test.yml create mode 100644 .github/workflows/build-test-upload.yaml diff --git a/.github/actions/build-collection/action.yaml b/.github/actions/build-collection/action.yaml new file mode 100644 index 0000000..8a108b0 --- /dev/null +++ b/.github/actions/build-collection/action.yaml @@ -0,0 +1,26 @@ +# Copyright 2023 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 $FILES_DIR && wget https://ca.dynatrace.com/dt-root.cert.pem -P $FILES_DIR + - name: Building the collection + shell: bask + run: ansible-galaxy collection build . diff --git a/.github/actions/run-tests/action.yaml b/.github/actions/run-tests/action.yaml new file mode 100644 index 0000000..c4879f9 --- /dev/null +++ b/.github/actions/run-tests/action.yaml @@ -0,0 +1,26 @@ +# Copyright 2023 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: Installing the collection + shell: bash + run: ansible-galaxy collection install dynatrace-oneagent* + - name: Running sanity test + shell: bash + run: pushd ~/.ansible/collections/ansible_collections/dynatrace/oneagent && ansible-test sanity && popd diff --git a/.github/actions/setup-build-environment/action.yaml b/.github/actions/setup-build-environment/action.yaml new file mode 100644 index 0000000..b9c652c --- /dev/null +++ b/.github/actions/setup-build-environment/action.yaml @@ -0,0 +1,26 @@ +# Copyright 2023 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: Installing dependencies + shell: bash + run: pip install ansible diff --git a/.github/actions/upload-collection/action.yaml b/.github/actions/upload-collection/action.yaml new file mode 100644 index 0000000..7f4c0ce --- /dev/null +++ b/.github/actions/upload-collection/action.yaml @@ -0,0 +1,26 @@ +# Copyright 2023 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* \ No newline at end of file diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml new file mode 100644 index 0000000..7f6589c --- /dev/null +++ b/.github/workflows/build-and-test.yaml @@ -0,0 +1,34 @@ +# Copyright 2023 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 + - uses: ./.github/actions/setup-build-environment + - uses: ./.github/actions/build-collection + - uses: ./.github/actions/run-tests diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml deleted file mode 100644 index f688212..0000000 --- a/.github/workflows/build-and-test.yml +++ /dev/null @@ -1,51 +0,0 @@ -# Copyright 2023 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 - - uses: actions/setup-python@v5 - with: - python-version: '3.10' - - name: Installing dependencies - run: pip install ansible - - name: Download certificate - run: mkdir $FILES_DIR && wget https://ca.dynatrace.com/dt-root.cert.pem -P $FILES_DIR - - name: Building the collection - run: ansible-galaxy collection build . - - name: Installing the collection - run: ansible-galaxy collection install dynatrace-oneagent* - - name: Running sanity test - run: pushd ~/.ansible/collections/ansible_collections/dynatrace/oneagent && ansible-test sanity && popd - - name: Publish artifact - if: ${{ contains(github.ref, 'refs/heads/main') }} - uses: actions/upload-artifact@v4 - with: - name: dynatrace-oneagent-${{ github.sha }} - retention-days: 7 - path: dynatrace-oneagent* \ No newline at end of file diff --git a/.github/workflows/build-test-upload.yaml b/.github/workflows/build-test-upload.yaml new file mode 100644 index 0000000..cda15ba --- /dev/null +++ b/.github/workflows/build-test-upload.yaml @@ -0,0 +1,29 @@ +# Copyright 2023 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: + pull_request: + types: [ 'closed' ] + workflow_dispatch: + +env: + FILES_DIR: roles/oneagent/files + +jobs: + build-and-test: + runs-on: ubuntu-latest + steps: + - uses: ./.github/workflows/build-and-test.yaml + - uses: ./.github/actions/upload-collection