Skip to content

Commit

Permalink
feat: Add reusable workflow
Browse files Browse the repository at this point in the history
ref: #1
  • Loading branch information
jon-nfc committed Aug 19, 2024
1 parent 0f19c82 commit 4667967
Showing 1 changed file with 252 additions and 0 deletions.
252 changes: 252 additions & 0 deletions .github/workflows/reusable_mkdocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
---

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: "${{ github.repository_owner }}"
# required: false
# description: Namespace on Ansible Galaxy.
# type: string
# ANSIBLE_GALAXY_PACKAGE_NAME:
# default: "${{ github.event.repository.name }}"
# required: false
# description: Collection name to use when publishing to Ansible Galaxy.
# type: string
# ANSIBLE_GALAXY_SERVER_URL:
# default: https://galaxy.ansible.com
# required: false
# description: Collection name to use when publishing to Ansible Galaxy.
# type: string
# ANSIBLE_LINTING_MUST_PASS:
# default: true
# required: false
# description: Fail the linting action if the tests failed
# type: boolean

# secrets:
# ANSIBLE_GALAXY_UPLOAD_TOKEN:
# description: Token used to upload Collection to Ansible Galaxy.
# required: false


# permissions:
# pull-requests: write
# contents: write
# statuses: write
# checks: write
# actions: write


jobs:


lint:
name: 'Lint'
env:
MDLINT_PATHS: '"docs/*.md docs/**/*.md docs/**/**/*.md docs/**/**/**/*.md docs/**/**/**/**/**/*.md #CHANGELOG.md !gitlab-ci !website-template"'
runs-on: ubuntu-latest
steps:


- name: Checkout Code - ${{ github.ref_name }}
uses: actions/checkout@v4


- name: Install Dependencies
shell: bash
run: |
apt update;
apt install -y --no-install-recommends npm;
- name: Checkout Code - ${{ github.ref_name }}
uses: actions/checkout@v4


- name: Install Linter
shell: bash
run: |
npm install markdownlint-cli2 --global
npm install markdownlint-cli2-formatter-junit --global
- name: Create Artifact directory
shell: bash
run: |
mkdir -p artifacts
- name: Add linting rules
shell: bash
run: |
if [ ! -f ".markdownlint.json" ]; then
cp "website-template/.markdownlint.json" ".markdownlint.json";
fi;
if [ ! -f ".markdownlint-cli2.jsonc" ]; then
cp -f "gitlab-ci/lint/.markdownlint-cli2.jsonc" ".markdownlint-cli2.jsonc";
fi
ls -la;
- name: Lint
id: lint
shell: bash
run: |
markdownlint-cli2 $MDLINT_PATHS 1>&1 || EXITCODE=$?
if [ "${EXITCODE}" ]; then
echo "exit_code=${EXITCODE}" >> $GITHUB_OUTPUT
else
echo "exit_code=0" >> $GITHUB_OUTPUT
fi
echo "[Trace] GITHUB_OUTPUT[$(cat $GITHUB_OUTPUT)]";
mv *.junit.xml "artifacts/markdown_lint.junit.xml
- name: Check if Linting Error Occured
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: mkdocs-lint
path: artifacts/


- name: Should the Job be force failed?
shell: bash
run: |
if [ "0${{ inputs.ANSIBLE_LINTING_MUST_PASS }}" == "0true" ]; then
if [ ${{ steps.lint.outputs.exit_code }} -gt 0 ]; then
echo "[Trace] ANSIBLE_LINTING_MUST_PASS[${{ inputs.ANSIBLE_LINTING_MUST_PASS }}]";
echo "[Error] ansible lint failed with ${{ steps.lint.outputs.exit_code }}";
exit ${{ steps.lint.outputs.exit_code }};
fi
fi
lint-reports:
name: 'Linting Reports'
if: success() || failure()
needs:
- lint
- lint-galaxy-yaml
runs-on: ubuntu-latest
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
if: false
needs:
- lint
- lint-galaxy-yaml
runs-on: ubuntu-latest
steps:


- name: Debug
shell: bash
run: |
echo "To be created";
publish:
name: Publish to Galaxy
if: false
needs:
- lint
- lint-galaxy-yaml
- build
runs-on: ubuntu-latest
steps:


- name: to be created
shell: bash
run: |
echo "to be created";
release:
if: false
needs:
- publish
name: Mark Release Live
runs-on: ubuntu-latest
steps:


- name: to be created
shell: bash
run: |
echo "to be created";
# - name: Publish Release
# uses: grzegorzkrukowski/action-publish-github-release@v1
# with:
# tag_name: ${{ github.ref_name }}
# token: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 4667967

Please sign in to comment.