From b8ba1c3239fa5e0acf895f2d1bcec3ea70e0259d Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 14 Aug 2024 19:40:57 +0930 Subject: [PATCH] temp --- .../reusable_ansible_collection.yaml | 248 ++++++++++++++++-- 1 file changed, 224 insertions(+), 24 deletions(-) diff --git a/.github/workflows/reusable_ansible_collection.yaml b/.github/workflows/reusable_ansible_collection.yaml index 4954a53..8935c1f 100644 --- a/.github/workflows/reusable_ansible_collection.yaml +++ b/.github/workflows/reusable_ansible_collection.yaml @@ -6,13 +6,18 @@ name: 'Ansible Collection' on: workflow_call: inputs: + ANSIBLE_COLLECTION_MARK_RELEASE_LIVE: + default: true + required: false + description: Remove 'Draft' status on the the Github Release. + type: boolean ANSIBLE_GALAXY_NAMESPACE: - default: none + default: '${{ github.event.repository.owner }}' required: false description: Namespace on Ansible Galaxy. type: string ANSIBLE_GALAXY_PACKAGE_NAME: - default: none + default: '${{ github.event.repository.name }}' required: false description: Collection name to use when publishing to Ansible Galaxy. type: string @@ -30,7 +35,7 @@ on: secrets: ANSIBLE_GALAXY_UPLOAD_TOKEN: description: Token used to upload Collection to Ansible Galaxy. - required: true + required: false jobs: @@ -57,8 +62,8 @@ jobs: ansible \ setuptools_rust \ Rust \ - ansible-lint==6.15.0 \ - yamllint==1.31.0 \ + ansible-lint==24.7.0 \ + yamllint==1.35.1 \ lxml \ ansible-lint-junit==0.17.7 \ ansible-lint-to-junit-xml==0.1.0; @@ -76,27 +81,46 @@ jobs: run: | ansible-lint -q \ --nocolor \ - --parseable ${{ env.ANSIBLE_LINT_PATH }} \> "artifacts/$PYTHON_VERSION-ansible-lint.log" 1>&1 || ANSIBLE_LINT=$? + --parseable ${{ env.ANSIBLE_LINT_PATH }} > "artifacts/ansible-lint.log" 1>&1 || ANSIBLE_LINT=$? + + if [ "${ANSIBLE_LINT}" ]; then + + echo "exit_code=${ANSIBLE_LINT}" >> $GITHUB_OUTPUT + + else + + echo "exit_code=0" >> $GITHUB_OUTPUT + + fi - echo "exit_code=${ANSIBLE_LINT}" > $GITHUB_OUTPUT + echo "[Trace] GITHUB_OUTPUT[$(cat $GITHUB_OUTPUT)]"; - name: Convert Lint log to JUnit Test report id: junit-test-report shell: bash run: | - cat "artifacts/$PYTHON_VERSION-ansible-lint.log" \ - | ansible-lint-to-junit-xml > "artifacts/$PYTHON_VERSION-ansible-lint.junit.xml" 1>&1 || ANSIBLE_LINT_JUNIT=$? + cat "artifacts/ansible-lint.log" | \ + ansible-lint-to-junit-xml > "artifacts/ansible-lint.junit.xml" 1>&1 || ANSIBLE_LINT_JUNIT=$? - echo "exit_code=${ANSIBLE_LINT_JUNIT}" > $GITHUB_OUTPUT + + if [ "${ANSIBLE_LINT_JUNIT}" ]; then + + echo "exit_code=${ANSIBLE_LINT_JUNIT}" >> $GITHUB_OUTPUT + + else + + echo "exit_code=0" >> $GITHUB_OUTPUT + + fi - name: Check if JUnit Test Report was Successful shell: bash run: | - if [ ${{ steps.junit-test-report.outputs.exit_code }} > 0 ]; then + if [ ${{ steps.junit-test-report.outputs.exit_code }} -gt 0 ]; then - echo "Error ANSIBLE_LINT_JUNIT failed with ${{ steps.junit-test-report.outputs.exit_code }}"; + echo "[Error] ANSIBLE_LINT_JUNIT failed with ${{ steps.junit-test-report.outputs.exit_code }}"; fi @@ -106,9 +130,9 @@ jobs: run: | if [ ${{ steps.lint.outputs.exit_code }} -ge 3 ]; then - echo "ansible lint failed with ${{ steps.lint.outputs.exit_code }}"; + echo "[Error] ansible lint failed with ${{ steps.lint.outputs.exit_code }}"; - exit ${{ steps.lint.outputs.exit_code }}; + exit ${{ steps.lint.outputs.exit_code }}; fi # don't fail the job?? 1=failed test, 2=failed command i.e. switch/flag @@ -117,29 +141,35 @@ jobs: if: ${{ success() || failure() }} uses: actions/upload-artifact@v4 with: - name: ansible-collection + name: ansible-collection-lint path: artifacts/ - name: Should the Job be force failed? shell: bash run: | - if [ "0${{ inputs.LINTING_MUST_PASS }}" == "0yes" ]; then + if [ "0${{ inputs.LINTING_MUST_PASS }}" == "0true" ]; then - echo "Trace LINTING_MUST_PASS[${{ inputs.LINTING_MUST_PASS }}]"; - - echo "ansible lint failed with ${{ steps.lint.outputs.exit_code }}"; + if [ ${{ steps.lint.outputs.exit_code }} -gt 0 ]; then + + echo "[Trace] LINTING_MUST_PASS[${{ inputs.LINTING_MUST_PASS }}]"; + + echo "[Error] ansible lint failed with ${{ steps.lint.outputs.exit_code }}"; - exit ${{ steps.lint.outputs.exit_code }}; + exit ${{ steps.lint.outputs.exit_code }}; + fi + fi lint-galaxy-yaml: name: 'Lint (galaxy.yaml)' - if: github.event.commits[0].author.name != 'nfc-bot' + # if: github.event.commits[0].author.name != 'nfc-bot' runs-on: ubuntu-latest + env: + ANSIBLE_LINT_PATH: 'galaxy.y*' steps: @@ -147,16 +177,166 @@ jobs: uses: actions/checkout@v4 + - name: Install Dependencies + shell: bash + run: | + pip install \ + pipenv==2022.1.8 \ + wheel \ + ansible \ + setuptools_rust \ + Rust \ + ansible-lint==24.7.0 \ + yamllint==1.35.1 \ + lxml \ + ansible-lint-junit==0.17.7 \ + ansible-lint-to-junit-xml==0.1.0; + + + - name: Create Artifact directory + shell: bash + run: | + mkdir -p artifacts + + + - name: Lint + id: lint + shell: bash + run: | + ansible-lint -q \ + --nocolor \ + --parseable ${{ env.ANSIBLE_LINT_PATH }} > "artifacts/ansible-lint.log" 1>&1 || ANSIBLE_LINT=$? + + if [ "${ANSIBLE_LINT}" ]; then + + echo "exit_code=${ANSIBLE_LINT}" >> $GITHUB_OUTPUT + + else + + echo "exit_code=0" >> $GITHUB_OUTPUT + + fi + + echo "[Trace] GITHUB_OUTPUT[$(cat $GITHUB_OUTPUT)]"; + + + - name: Convert Lint log to JUnit Test report + id: junit-test-report + shell: bash + run: | + cat "artifacts/ansible-lint.log" | \ + ansible-lint-to-junit-xml > "artifacts/ansible-lint-galaxy.junit.xml" 1>&1 || ANSIBLE_LINT_JUNIT=$? + + + if [ "${ANSIBLE_LINT_JUNIT}" ]; then + + echo "exit_code=${ANSIBLE_LINT_JUNIT}" >> $GITHUB_OUTPUT + + else + + echo "exit_code=0" >> $GITHUB_OUTPUT + + fi + + + - name: Check if JUnit Test Report was Successful + shell: bash + run: | + if [ ${{ steps.junit-test-report.outputs.exit_code }} -gt 0 ]; then + + echo "[Error] ANSIBLE_LINT_JUNIT failed with ${{ steps.junit-test-report.outputs.exit_code }}"; + + fi + + + - name: Check if Linting Error Occurred + shell: bash + run: | + if [ ${{ steps.lint.outputs.exit_code }} -ge 3 ]; then + + echo "[Error] ansible lint failed with ${{ steps.lint.outputs.exit_code }}"; + + exit ${{ steps.lint.outputs.exit_code }}; + + fi # don't fail the job?? 1=failed test, 2=failed command i.e. switch/flag + + + - name: Upload build Artifact + if: ${{ success() || failure() }} + uses: actions/upload-artifact@v4 + with: + name: ansible-collection-lint-galaxy.yaml + path: artifacts/ + + + + - name: Force fail? + shell: bash + run: | + + if [ ${{ steps.lint.outputs.exit_code }} -gt 0 ]; then + + echo "[Trace] LINTING_MUST_PASS[${{ inputs.LINTING_MUST_PASS }}]"; + + echo "[Error] ansible lint failed with ${{ steps.lint.outputs.exit_code }}"; + + exit ${{ steps.lint.outputs.exit_code }}; + + fi + + + + lint-reports: + name: 'Linting Reports' + if: success() || failure() + needs: + - lint + - lint-galaxy-yaml + runs-on: ubuntu-latest + env: + ANSIBLE_LINT_PATH: 'galaxy.y*' + steps: + + + - name: Ansible Lint Report (galaxy.yaml) + if: success() || failure() + uses: dorny/test-reporter@v1 + with: + artifact: ansible-collection-lint-galaxy.yaml + name: Ansible Lint Report (galaxy.yaml) + path: 'ansible-lint-galaxy.junit.xml' + reporter: java-junit + + + - name: Ansible Lint Report + if: success() || failure() + uses: dorny/test-reporter@v1 + with: + artifact: ansible-collection-lint + name: Ansible Lint Report + path: 'ansible-lint.junit.xml' + reporter: java-junit + + build: name: Build needs: - lint - lint-galaxy-yaml - runs-on: python:3.11-bookworm + runs-on: ubuntu-latest steps: + - name: Debug + shell: bash + run: | + + echo "[Debug] ANSIBLE_GALAXY_NAMESPACE=${{ inputs.ANSIBLE_GALAXY_NAMESPACE }}"; + + echo "[Debug] ANSIBLE_GALAXY_PACKAGE_NAME=${{ inputs.ANSIBLE_GALAXY_PACKAGE_NAME }}"; + + - name: Checkout Code - ${{ github.ref_name }} uses: actions/checkout@v4 @@ -186,7 +366,7 @@ jobs: if: false needs: - build - runs-on: python:3.11-bookworm + runs-on: ubuntu-latest steps: # @@ -205,7 +385,7 @@ jobs: - lint - lint-galaxy-yaml - build - runs-on: python:3.11-bookworm + runs-on: ubuntu-latest steps: @@ -236,3 +416,23 @@ jobs: run: | echo "Amend release with download link for the collection"; + + + collection-release: + if: ${{( + github.ref_type == 'tag' + && + inputs.ANSIBLE_COLLECTION_MARK_RELEASE_LIVE + )}} + needs: + - publish + name: Mark Release Live + runs-on: ubuntu-latest + steps: + + + - name: Publish Release + uses: grzegorzkrukowski/action-publish-github-release@v1 + with: + tag_name: ${{ github.ref_name }} + token: ${{ secrets.GITHUB_TOKEN }}