From 7efc21fe784522e0dcb142aab76e8d56858a9dd5 Mon Sep 17 00:00:00 2001 From: Jared Holgate Date: Wed, 10 Jul 2024 13:23:27 +0100 Subject: [PATCH] Add wiki workflows (#120) # Pull Request ## Issue Issue #, if available: ## Description Description of changes: ## License By submitting this pull request, I confirm that my contribution is made under the terms of the projects associated license. --- .github/workflows/super-linter.yml | 49 ++++++++++++++++++++++ .github/workflows/wiki-sync.yml | 65 ++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 .github/workflows/super-linter.yml create mode 100644 .github/workflows/wiki-sync.yml diff --git a/.github/workflows/super-linter.yml b/.github/workflows/super-linter.yml new file mode 100644 index 0000000..dceae28 --- /dev/null +++ b/.github/workflows/super-linter.yml @@ -0,0 +1,49 @@ +--- +name: Linting +on: + pull_request: + types: ['opened', 'synchronize'] + merge_group: + workflow_dispatch: + +concurrency: + group: linting-${{ github.event.pull_request.head.repo.full_name }}/${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + superlinter: + name: super linter + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Setup Terraform + uses: hashicorp/setup-terraform@v3 + with: + terraform_version: latest + terraform_wrapper: false + - name: Run github/super-linter/slim + uses: github/super-linter/slim@v5 + env: + # Lint all code + VALIDATE_ALL_CODEBASE: true + FILTER_REGEX_EXCLUDE: '.*tests/vendor/.*' + # Need to define main branch as default + # is set to master in super-linter + DEFAULT_BRANCH: main + # Enable setting the status of each individual linter + # run in the Checks section of a pull request + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # The following linter types will be enabled: + VALIDATE_BASH: true + VALIDATE_BASH_EXEC: true + VALIDATE_GITHUB_ACTIONS: true + VALIDATE_JSON: true + VALIDATE_MARKDOWN: true + # VALIDATE_TERRAFORM_TERRASCAN: true # disabled for now as does not support TF 1.3 optional(type, default) + VALIDATE_TERRAFORM_TFLINT: true + VALIDATE_YAML: true + # VALIDATE_GO: true # Disabled because it down not work :( + # Additional settings: + # If a shell script is not executable, the bash-exec + # linter will report an error when set to true + ERROR_ON_MISSING_EXEC_BIT: true diff --git a/.github/workflows/wiki-sync.yml b/.github/workflows/wiki-sync.yml new file mode 100644 index 0000000..2b8b5ea --- /dev/null +++ b/.github/workflows/wiki-sync.yml @@ -0,0 +1,65 @@ +--- +name: Docs/Wiki Sync + +permissions: + contents: write + +# yamllint disable-line rule:truthy +on: + release: + types: [published] + workflow_dispatch: + +env: + wiki_source_repo: "${{ github.repository }}" + wiki_source_repo_dir: "${{ github.repository }}/docs/wiki" + wiki_target_repo: "${{ github.repository }}.wiki" + github_user_name: "github-actions" + github_email: "github-actions@github.com" + github_commit_message: "GitHub Action syncing wiki from docs/wiki" + +jobs: + sync-wiki: + name: Sync Wiki + if: github.repository == 'Azure/ALZ-PowerShell-Module' || github.event_name == 'workflow_dispatch' + runs-on: ubuntu-latest + steps: + - name: Checkout Source Repo + uses: actions/checkout@v3 + with: + repository: ${{ env.wiki_source_repo }} + path: ${{ env.wiki_source_repo }} + + - name: Checkout Wiki Repo + uses: actions/checkout@v3 + with: + repository: ${{ env.wiki_target_repo }} + path: ${{ env.wiki_target_repo }} + + - name: Configure Local Git + run: | + git config --global user.name "$github_user_name" + git config --global user.email "$github_email" + working-directory: ${{ env.GITHUB_WORKSPACE }} + + - name: Sync docs/wiki Into Wiki Repo + run: | + rsync -avzr --delete --exclude='.git/' "$wiki_source_repo_dir/" "$wiki_target_repo" + working-directory: ${{ env.GITHUB_WORKSPACE }} + + - name: Check for changes + id: git_status + run: | + mapfile -t "CHECK_GIT_STATUS" < <(git status -s) + printf "%s\n" "${CHECK_GIT_STATUS[@]}" + echo "changes=${#CHECK_GIT_STATUS[@]}" >> "$GITHUB_OUTPUT" + working-directory: ${{ env.wiki_target_repo }} + + - name: Add files, commit and push into Wiki + if: steps.git_status.outputs.changes > 0 + run: | + echo "Pushing changes to origin..." + git add . + git commit -m "$github_commit_message [$GITHUB_ACTOR/${GITHUB_SHA::8}]" + git push --set-upstream "https://$GITHUB_TOKEN@github.com/$wiki_target_repo.git" master + working-directory: ${{ env.wiki_target_repo }}