From 0d0bf206807387b79a62835c0f77e9274ea7fd60 Mon Sep 17 00:00:00 2001 From: RedlineTriad <39059512+RedlineTriad@users.noreply.github.com> Date: Wed, 9 Nov 2022 17:10:35 +0100 Subject: [PATCH 01/14] test: run action instead of image --- .github/workflows/test.yml | 26 +++++++++++--------------- action.yml | 9 ++++++++- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 68b915a..2c332a8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,19 +30,15 @@ jobs: cache-from: type=gha cache-to: type=gha,mode=max - - name: Test Molecule default pipeline - env: - ANSIBLE_FORCE_COLOR: '1' + - name: Create molecule scenario run: | - docker run \ - -v /var/run/libvirt/virtqemud-sock:/var/run/libvirt/virtqemud-sock \ - -v $(pwd)/test_files/:/var/test_files \ - ${{ env.IMAGE }}:test \ - sh -c "\ - molecule --version \ - && molecule init role --driver-name vagrant redlinetriad.validate \ - && cd validate \ - && cp /var/test_files/molecule.yml molecule/default/molecule.yml \ - && sed -i 's/redlinetriad.//g' molecule/default/converge.yml \ - && molecule test \ - " + molecule init role --driver-name vagrant redlinetriad.validate \ + cd validate \ + cp ../test_files/molecule.yml molecule/default/molecule.yml \ + sed -i 's/redlinetriad.//g' molecule/default/converge.yml \ + + - name: Test Molecule default pipeline + uses: ./ # Uses an action in the root directory + with: + molecule_working_dir: validate + image: "${{ env.IMAGE }}:test" diff --git a/action.yml b/action.yml index 136e8ab..c41bd3d 100644 --- a/action.yml +++ b/action.yml @@ -8,6 +8,13 @@ branding: color: green inputs: + image: + description: | + Container image to use for running molecule testing. + This is generally not needed and mostly useful for tests. + required: true + default: docker://ghcr.io/redlinetriad/molecule-vagrant-qemu-action:v1 + molecule_options: description: | Options: @@ -65,7 +72,7 @@ inputs: runs: using: docker - image: docker://ghcr.io/redlinetriad/molecule-vagrant-qemu-action:v1 + image: ${{ inputs.image }} env: ANSIBLE_ASYNC_DIR: "/tmp/.ansible_async" ANSIBLE_FORCE_COLOR: "1" From c876d7813c9f51fa00814c7a0638eade5c866252 Mon Sep 17 00:00:00 2001 From: RedlineTriad <39059512+RedlineTriad@users.noreply.github.com> Date: Wed, 9 Nov 2022 17:24:22 +0100 Subject: [PATCH 02/14] test: install molecule on runner --- .github/workflows/test.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2c332a8..c5b57fd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,6 +30,10 @@ jobs: cache-from: type=gha cache-to: type=gha,mode=max + - name: Install Molecule on Runner + run: | + python3 -m pip install molecule molecule-vagrant + - name: Create molecule scenario run: | molecule init role --driver-name vagrant redlinetriad.validate \ From 26ca5bcf2b65b810d7c268268eb161d22bf39374 Mon Sep 17 00:00:00 2001 From: RedlineTriad <39059512+RedlineTriad@users.noreply.github.com> Date: Wed, 9 Nov 2022 17:27:39 +0100 Subject: [PATCH 03/14] test: remove unnecessary escape characters --- .github/workflows/test.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c5b57fd..73c3c48 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -36,10 +36,10 @@ jobs: - name: Create molecule scenario run: | - molecule init role --driver-name vagrant redlinetriad.validate \ - cd validate \ - cp ../test_files/molecule.yml molecule/default/molecule.yml \ - sed -i 's/redlinetriad.//g' molecule/default/converge.yml \ + molecule init role --driver-name vagrant redlinetriad.validate + cd validate + cp ../test_files/molecule.yml molecule/default/molecule.yml + sed -i 's/redlinetriad.//g' molecule/default/converge.yml - name: Test Molecule default pipeline uses: ./ # Uses an action in the root directory From fbe765fb6047cafff32f4fe4702936ff429ea8ae Mon Sep 17 00:00:00 2001 From: RedlineTriad <39059512+RedlineTriad@users.noreply.github.com> Date: Wed, 9 Nov 2022 17:31:19 +0100 Subject: [PATCH 04/14] test: use own directory for tests --- .github/workflows/test.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 73c3c48..ef66fdb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -36,10 +36,11 @@ jobs: - name: Create molecule scenario run: | - molecule init role --driver-name vagrant redlinetriad.validate - cd validate - cp ../test_files/molecule.yml molecule/default/molecule.yml - sed -i 's/redlinetriad.//g' molecule/default/converge.yml + mkdir test + cd test + molecule init role --driver-name vagrant test.validate + cp ../../test_files/molecule.yml validate/molecule/default/molecule.yml + sed -i 's/test.//g' validate/molecule/default/converge.yml - name: Test Molecule default pipeline uses: ./ # Uses an action in the root directory From 8ac4fd50323f5ca77bd79086773d8becd73ceed0 Mon Sep 17 00:00:00 2001 From: RedlineTriad <39059512+RedlineTriad@users.noreply.github.com> Date: Wed, 9 Nov 2022 17:34:36 +0100 Subject: [PATCH 05/14] test: fix directory path for test file --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ef66fdb..2a66333 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -39,7 +39,7 @@ jobs: mkdir test cd test molecule init role --driver-name vagrant test.validate - cp ../../test_files/molecule.yml validate/molecule/default/molecule.yml + cp ../test_files/molecule.yml validate/molecule/default/molecule.yml sed -i 's/test.//g' validate/molecule/default/converge.yml - name: Test Molecule default pipeline From 1c8cae937d3b165a954e11a5e458015421258215 Mon Sep 17 00:00:00 2001 From: RedlineTriad <39059512+RedlineTriad@users.noreply.github.com> Date: Wed, 9 Nov 2022 17:39:22 +0100 Subject: [PATCH 06/14] test: fix directory used to run test --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2a66333..a8819cb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -45,5 +45,5 @@ jobs: - name: Test Molecule default pipeline uses: ./ # Uses an action in the root directory with: - molecule_working_dir: validate + molecule_working_dir: test/validate image: "${{ env.IMAGE }}:test" From 3d71c8bb5dc444a065de766700354fc3f8ec7384 Mon Sep 17 00:00:00 2001 From: RedlineTriad <39059512+RedlineTriad@users.noreply.github.com> Date: Wed, 9 Nov 2022 17:46:40 +0100 Subject: [PATCH 07/14] fix: working dir default --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index c41bd3d..97f2bf2 100644 --- a/action.yml +++ b/action.yml @@ -68,11 +68,11 @@ inputs: Path to another directory in the repository, where molecule command will be issued from. Useful in those cases where Ansible roles are not in git repository root. required: false - default: ${{ github.workspace }} + default: "." runs: using: docker - image: ${{ inputs.image }} + image: "${{ inputs.image }}" env: ANSIBLE_ASYNC_DIR: "/tmp/.ansible_async" ANSIBLE_FORCE_COLOR: "1" From 313794cc26daaaf83e823f339b8b54601ba31a90 Mon Sep 17 00:00:00 2001 From: RedlineTriad <39059512+RedlineTriad@users.noreply.github.com> Date: Sun, 13 Nov 2022 15:04:17 +0100 Subject: [PATCH 08/14] fix: use composite instead of docker action --- action.yml | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/action.yml b/action.yml index 97f2bf2..3441e71 100644 --- a/action.yml +++ b/action.yml @@ -71,8 +71,18 @@ inputs: default: "." runs: - using: docker - image: "${{ inputs.image }}" - env: - ANSIBLE_ASYNC_DIR: "/tmp/.ansible_async" - ANSIBLE_FORCE_COLOR: "1" + using: composite + steps: + - run: | + docker run + -v $(pwd)/:/${{ github.workspace }} + ${{ inputs.image }} + sh -c " + molecule --version + && cd ${{ github.workspace }} + && molecule test + " + shell: bash + env: + ANSIBLE_ASYNC_DIR: "/tmp/.ansible_async" + ANSIBLE_FORCE_COLOR: "1" From 0a809ffc39a1d2c87475bff8c3dde0a7cd8abc13 Mon Sep 17 00:00:00 2001 From: RedlineTriad <39059512+RedlineTriad@users.noreply.github.com> Date: Sun, 13 Nov 2022 15:07:27 +0100 Subject: [PATCH 09/14] fix: escape newlines --- action.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/action.yml b/action.yml index 3441e71..0d41fa1 100644 --- a/action.yml +++ b/action.yml @@ -74,13 +74,13 @@ runs: using: composite steps: - run: | - docker run - -v $(pwd)/:/${{ github.workspace }} - ${{ inputs.image }} - sh -c " - molecule --version - && cd ${{ github.workspace }} - && molecule test + docker run \ + -v $(pwd)/:/${{ github.workspace }} \ + ${{ inputs.image }} \ + sh -c "\ + molecule --version \ + && cd ${{ github.workspace }} \ + && molecule test \ " shell: bash env: From edee84d89f2955147af44e4a035b0c130b1028ba Mon Sep 17 00:00:00 2001 From: RedlineTriad <39059512+RedlineTriad@users.noreply.github.com> Date: Sun, 13 Nov 2022 15:12:51 +0100 Subject: [PATCH 10/14] fix: remove double slash in path --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 0d41fa1..487b94b 100644 --- a/action.yml +++ b/action.yml @@ -75,7 +75,7 @@ runs: steps: - run: | docker run \ - -v $(pwd)/:/${{ github.workspace }} \ + -v $(pwd)/:${{ github.workspace }} \ ${{ inputs.image }} \ sh -c "\ molecule --version \ From d6f0503636145122a358ca6cb994ad2d19d50a4b Mon Sep 17 00:00:00 2001 From: RedlineTriad <39059512+RedlineTriad@users.noreply.github.com> Date: Sun, 13 Nov 2022 15:17:33 +0100 Subject: [PATCH 11/14] fix: pass inputs to container --- action.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/action.yml b/action.yml index 487b94b..63be463 100644 --- a/action.yml +++ b/action.yml @@ -86,3 +86,7 @@ runs: env: ANSIBLE_ASYNC_DIR: "/tmp/.ansible_async" ANSIBLE_FORCE_COLOR: "1" + INPUT_MOLECULE_OPTIONS: ${{ inputs.molecule_options }} + INPUT_MOLECULE_COMMAND: ${{ inputs.molecule_command }} + INPUT_MOLECULE_ARGS: ${{ inputs.molecule_args }} + INPUT_MOLECULE_WORKING_DIR: ${{ inputs.molecule_working_dir }} From 088a7c5dc2a8221ce33eeb52337355e1b6ae842b Mon Sep 17 00:00:00 2001 From: RedlineTriad <39059512+RedlineTriad@users.noreply.github.com> Date: Sun, 13 Nov 2022 15:32:49 +0100 Subject: [PATCH 12/14] fix: don't use custom molecule script --- action.yml | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/action.yml b/action.yml index 63be463..1296f11 100644 --- a/action.yml +++ b/action.yml @@ -68,20 +68,12 @@ inputs: Path to another directory in the repository, where molecule command will be issued from. Useful in those cases where Ansible roles are not in git repository root. required: false - default: "." + default: ${{ github.workspace }} runs: using: composite steps: - - run: | - docker run \ - -v $(pwd)/:${{ github.workspace }} \ - ${{ inputs.image }} \ - sh -c "\ - molecule --version \ - && cd ${{ github.workspace }} \ - && molecule test \ - " + - run: docker run -v $(pwd)/:${{ github.workspace }} ${{ inputs.image }} shell: bash env: ANSIBLE_ASYNC_DIR: "/tmp/.ansible_async" From f569e0e6c901b0be3f7a9f301ffde8c6e2738a15 Mon Sep 17 00:00:00 2001 From: RedlineTriad <39059512+RedlineTriad@users.noreply.github.com> Date: Sun, 13 Nov 2022 15:46:34 +0100 Subject: [PATCH 13/14] fix: propagate variables to container --- action.yml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/action.yml b/action.yml index 1296f11..9feaf92 100644 --- a/action.yml +++ b/action.yml @@ -73,12 +73,14 @@ inputs: runs: using: composite steps: - - run: docker run -v $(pwd)/:${{ github.workspace }} ${{ inputs.image }} + - run: > + docker run + -v $(pwd)/:${{ github.workspace }} + -e "ANSIBLE_ASYNC_DIR=/tmp/.ansible_async" + -e "ANSIBLE_FORCE_COLOR=1" + -e "INPUT_MOLECULE_OPTIONS=${{ inputs.molecule_options }}" + -e "INPUT_MOLECULE_COMMAND=${{ inputs.molecule_command }}" + -e "INPUT_MOLECULE_ARGS=${{ inputs.molecule_args }}" + -e "INPUT_MOLECULE_WORKING_DIR=${{ inputs.molecule_working_dir }}" + ${{ inputs.image }} shell: bash - env: - ANSIBLE_ASYNC_DIR: "/tmp/.ansible_async" - ANSIBLE_FORCE_COLOR: "1" - INPUT_MOLECULE_OPTIONS: ${{ inputs.molecule_options }} - INPUT_MOLECULE_COMMAND: ${{ inputs.molecule_command }} - INPUT_MOLECULE_ARGS: ${{ inputs.molecule_args }} - INPUT_MOLECULE_WORKING_DIR: ${{ inputs.molecule_working_dir }} From 5038b6f8ebf628e5eff2010878a41fdb271874f4 Mon Sep 17 00:00:00 2001 From: RedlineTriad <39059512+RedlineTriad@users.noreply.github.com> Date: Sun, 13 Nov 2022 15:52:57 +0100 Subject: [PATCH 14/14] fix: set workdir to workspace --- action.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 9feaf92..6fba934 100644 --- a/action.yml +++ b/action.yml @@ -68,7 +68,7 @@ inputs: Path to another directory in the repository, where molecule command will be issued from. Useful in those cases where Ansible roles are not in git repository root. required: false - default: ${{ github.workspace }} + default: "." runs: using: composite @@ -76,6 +76,7 @@ runs: - run: > docker run -v $(pwd)/:${{ github.workspace }} + --workdir=${{ github.workspace }} -e "ANSIBLE_ASYNC_DIR=/tmp/.ansible_async" -e "ANSIBLE_FORCE_COLOR=1" -e "INPUT_MOLECULE_OPTIONS=${{ inputs.molecule_options }}"