🔧(diagram): Refactor class diagram by removing duplicated content #237
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| # Lint the code base and launch unit test at each push or pull request | |
| # based on https://github.com/mvdan/github-actions-golang | |
| name: Lint, Test, Build and Deploy | |
| "on": | |
| push: | |
| # execute when pushing only branches and tags | |
| branches: | |
| - "**" | |
| # avoid infinite loop for auto created PRs | |
| - "!update/pre-commit-*" | |
| tags: | |
| - "**" | |
| workflow_dispatch: | |
| # cancel previous build if several pushes | |
| concurrency: | |
| group: | | |
| ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
| cancel-in-progress: true | |
| env: | |
| # Apply linter fixes configuration | |
| # When active, APPLY_FIXES must also be defined as | |
| # environment variable (in github/workflows/mega-linter.yml | |
| # or other CI tool) | |
| APPLY_FIXES: all | |
| # Decide which event triggers application of fixes in a | |
| # commit or a PR (pull_request, push, all) | |
| APPLY_FIXES_EVENT: all | |
| # If APPLY_FIXES is used, defines if the fixes are | |
| # directly committed (commit) or posted in a PR (pull_request) | |
| APPLY_FIXES_MODE: pull_request | |
| # variables to compute complex conditions | |
| COND_UPDATED_SOURCES: false | |
| COND_APPLY_FIXES_NEEDED: false | |
| COND_PUSH_OR_PR: >- | |
| ${{ | |
| github.event_name == 'pull_request' || | |
| github.event_name == 'push' | |
| }} | |
| jobs: | |
| # ------------------------------------------------------- | |
| # Build docker images | |
| # ------------------------------------------------------- | |
| build-docker-images: | |
| runs-on: ubuntu-latest | |
| env: | |
| FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true # Forces Node 24 runtime | |
| permissions: | |
| # needed by guibranco/github-status-action-v2@v1 | |
| statuses: write | |
| strategy: | |
| fail-fast: true | |
| matrix: | |
| go-version: [1.25.7] | |
| os: [ubuntu-latest] | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v4 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| # overall process | |
| - uses: guibranco/github-status-action-v2@v1 | |
| if: ${{ env.COND_PUSH_OR_PR }} | |
| with: | |
| authToken: ${{secrets.GITHUB_TOKEN}} | |
| context: build-docker | |
| state: pending | |
| - name: Set env vars | |
| id: vars | |
| # shellcheck disable=SC2129 | |
| run: | | |
| ( | |
| echo "job_tag=${{github.run_id}}-${{matrix.os}}" | |
| echo "image_tag=bash-compiler-${{matrix.os}}" | |
| echo "image_name=scrasnups/bash-compiler" | |
| echo "branch_name=${GITHUB_REF##*/}" | |
| ) >> "${GITHUB_ENV}" | |
| - uses: guibranco/github-status-action-v2@v1 | |
| if: ${{ env.COND_PUSH_OR_PR }} | |
| with: | |
| authToken: ${{secrets.GITHUB_TOKEN}} | |
| context: build-docker-${{ env.image_tag }} | |
| state: pending | |
| - name: Docker meta | |
| id: meta | |
| uses: docker/metadata-action@v6 | |
| with: | |
| # list of Docker images to use as base name for tags | |
| images: | | |
| ${{env.image_name}} | |
| # generate Docker tags based on the following events/attributes | |
| tags: | | |
| type=schedule | |
| type=ref,event=branch | |
| type=ref,event=pr | |
| type=semver,pattern={{version}} | |
| type=semver,pattern={{major}}.{{minor}} | |
| type=semver,pattern={{major}} | |
| type=sha | |
| - uses: docker/build-push-action@v7 | |
| continue-on-error: false | |
| with: | |
| load: true | |
| context: . | |
| file: Dockerfile | |
| pull: true | |
| push: true | |
| github-token: ${{ github.token }} | |
| tags: | | |
| ${{ env.image_name }}:${{ env.image_tag }} | |
| cache-from: type=gha,scope=${{ env.image_tag }} | |
| cache-to: type=gha,mode=max,scope=${{ env.image_tag }} | |
| - uses: guibranco/github-status-action-v2@v1 | |
| if: ${{ env.COND_PUSH_OR_PR }} | |
| with: | |
| authToken: ${{secrets.GITHUB_TOKEN}} | |
| context: build-docker-${{ env.image_tag }} | |
| state: ${{ job.status }} | |
| - uses: guibranco/github-status-action-v2@v1 | |
| if: ${{ env.COND_PUSH_OR_PR }} | |
| with: | |
| authToken: ${{secrets.GITHUB_TOKEN}} | |
| context: build-docker | |
| state: ${{ job.status }} | |
| # ------------------------------------------------------- | |
| # Pre-commit | |
| # ------------------------------------------------------- | |
| pre-commit: | |
| runs-on: ubuntu-latest | |
| env: | |
| FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true # Forces Node 24 runtime | |
| needs: [build-docker-images] | |
| permissions: | |
| # needed by guibranco/github-status-action-v2@v1 | |
| statuses: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v4 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - uses: crazy-max/ghaction-import-gpg@v7 | |
| if: ${{ success() }} | |
| with: | |
| gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} | |
| passphrase: ${{ secrets.GPG_PASSPHRASE }} | |
| git_user_signingkey: true | |
| git_commit_gpgsign: true | |
| - uses: actions/create-github-app-token@v3.1.1 | |
| if: ${{ success() }} | |
| id: generate-token | |
| with: | |
| app-id: ${{ secrets.APP_ID }} | |
| private-key: ${{ secrets.APP_PRIVATE_KEY }} | |
| - uses: guibranco/github-status-action-v2@v1 | |
| if: ${{ env.COND_PUSH_OR_PR }} | |
| with: | |
| authToken: ${{ secrets.GITHUB_TOKEN }} | |
| context: pre-commit-megalinter | |
| state: pending | |
| - name: Set env vars | |
| id: vars | |
| # shellcheck disable=SC2129 | |
| run: | | |
| ( | |
| echo "branch_name=${GITHUB_REF##*/}" | |
| ) >> "${GITHUB_ENV}" | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: 3.12 | |
| - uses: fchastanet/github-action-setup-shfmt@v4.0.0 | |
| - uses: actions/setup-go@v6 | |
| with: | |
| go-version: "1.25.7" | |
| check-latest: false | |
| - name: Install requirements | |
| run: | | |
| set -exo pipefail | |
| ./.github/scripts/install-dev.sh | |
| - name: Transform pre-commit config for GitHub | |
| if: ${{ success() }} | |
| run: .github/preCommitGeneration.sh | |
| - name: Run pre-commit | |
| uses: j178/prek-action@v2 | |
| id: preCommit | |
| with: | |
| extra-args: >- | |
| -c .pre-commit-config-github.yaml -a --hook-stage manual | |
| - name: MegaLinter | |
| id: ml | |
| if: ${{ !cancelled() }} | |
| # You can override MegaLinter flavor used to have faster performances | |
| # More info at https://megalinter.io/latest/flavors/ | |
| uses: oxsecurity/megalinter/flavors/go@v9 | |
| # All available variables are described in documentation | |
| # https://megalinter.io/latest/config-file/ | |
| env: | |
| # Validates all source when push on master, | |
| # else just the git diff with master. | |
| # Override with true if you always want to lint all sources | |
| VALIDATE_ALL_CODEBASE: true | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| MEGALINTER_CONFIG: .mega-linter-githubAction.yml | |
| CI_MODE: 1 | |
| GOTOOLCHAIN: go1.25.7+auto | |
| - name: Upload MegaLinter artifacts | |
| if: success() || failure() | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: MegaLinter reports | |
| retention-days: 2 | |
| overwrite: true | |
| path: | | |
| megalinter-reports | |
| mega-linter.log | |
| - name: MegaLinter/Precommit has updated sources | |
| if: > | |
| steps.preCommit.outcome == 'failure' || ( | |
| steps.ml.outputs.has_updated_sources == 1 && ( | |
| env.APPLY_FIXES_EVENT == 'all' || | |
| env.APPLY_FIXES_EVENT == github.event_name | |
| ) | |
| ) | |
| run: | | |
| echo "COND_UPDATED_SOURCES=true" >> "${GITHUB_ENV}" | |
| - name: is apply fixes needed ? | |
| if: > | |
| env.APPLY_FIXES_MODE == 'pull_request' && ( | |
| github.event_name == 'push' || | |
| github.event.pull_request.head.repo.full_name == | |
| github.repository | |
| ) | |
| run: | | |
| echo "COND_APPLY_FIXES_NEEDED=true" >> "${GITHUB_ENV}" | |
| - name: Create Pull Request | |
| id: cpr | |
| # prettier-ignore | |
| if: > | |
| env.COND_UPDATED_SOURCES == 'true' && | |
| env.COND_APPLY_FIXES_NEEDED == 'true' && | |
| !contains(github.event.head_commit.message, 'skip fix') | |
| uses: peter-evans/create-pull-request@v8 | |
| with: | |
| token: ${{ steps.generate-token.outputs.token }} | |
| committer: fchastanet <237869+fchastanet@users.noreply.github.com> | |
| branch: update/pre-commit-fixes-${{ env.branch_name }} | |
| delete-branch: true | |
| title: lint fixes | |
| commit-message: Auto-update lint fixes | |
| body: | | |
| some auto fixes have been generated during pre-commit run | |
| labels: pre-commit-fixes | |
| - name: Print Pull request created | |
| if: |- | |
| ${{ | |
| steps.cpr.outputs.pull-request-number && | |
| steps.cpr.conclusion == 'success' | |
| }} | |
| run: | | |
| echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" | |
| echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}" | |
| - uses: guibranco/github-status-action-v2@v1 | |
| if: ${{ env.COND_PUSH_OR_PR }} | |
| with: | |
| authToken: ${{ secrets.GITHUB_TOKEN }} | |
| context: pre-commit-megalinter | |
| state: ${{ job.status }} | |
| # ------------------------------------------------------- | |
| # Unit tests | |
| # ------------------------------------------------------- | |
| unit-tests: | |
| runs-on: ${{ matrix.os }} | |
| env: | |
| FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true # Forces Node 24 runtime | |
| needs: [build-docker-images] | |
| permissions: | |
| # needed by guibranco/github-status-action-v2@v1 | |
| statuses: write | |
| # needed by marocchino/sticky-pull-request-comment | |
| pull-requests: write | |
| strategy: | |
| fail-fast: true | |
| matrix: | |
| go-version: [1.25.7] | |
| os: [ubuntu-latest] | |
| steps: | |
| - name: Install Go | |
| uses: actions/setup-go@v6 | |
| with: | |
| go-version: ${{ matrix.go-version }} | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Downloads the dependencies | |
| run: go mod download | |
| - name: Lints all code with golangci-lint | |
| run: | | |
| set -exo pipefail | |
| go fmt ./... | |
| mkdir -p logs || true | |
| - uses: guibranco/github-status-action-v2@v1 | |
| if: ${{ env.COND_PUSH_OR_PR }} | |
| with: | |
| authToken: ${{ secrets.GITHUB_TOKEN }} | |
| context: build-${{matrix.os}} | |
| state: pending | |
| - name: build the binary | |
| run: | | |
| set -exo pipefail | |
| ./.github/scripts/build-local.sh | |
| - uses: guibranco/github-status-action-v2@v1 | |
| if: ${{ env.COND_PUSH_OR_PR }} | |
| with: | |
| authToken: ${{ secrets.GITHUB_TOKEN }} | |
| context: build-${{matrix.os}} | |
| state: ${{ job.status }} | |
| - uses: guibranco/github-status-action-v2@v1 | |
| if: ${{ env.COND_PUSH_OR_PR }} | |
| with: | |
| authToken: ${{ secrets.GITHUB_TOKEN }} | |
| context: unit-tests-${{matrix.go-version}}-${{matrix.os}} | |
| state: pending | |
| - name: Install gocover-cobertura | |
| run: | | |
| set -exo pipefail | |
| go install github.com/boumenot/gocover-cobertura@latest | |
| # Install gotestfmt on the VM running the action. | |
| - name: Set up gotestfmt | |
| uses: GoTestTools/gotestfmt-action@v2 | |
| with: | |
| token: ${{ github.token }} | |
| # Optional: pass the gotestfmt version you want to run. | |
| version: v2.0.0 | |
| # Optional: pass an organization name and repo to use a fork | |
| org: GoTestTools | |
| repo: gotestfmt | |
| - name: Run tests | |
| run: | | |
| go test -coverprofile=logs/coverage.log -covermode=atomic -coverpkg=./... ./... 2>&1 | | |
| tee logs/tests.log | gotestfmt | |
| # Upload the original go test log as an artifact for later review. | |
| - name: Upload test log | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: test-log | |
| path: logs/coverage.log | |
| if-no-files-found: error | |
| - name: check test coverage | |
| uses: vladopajic/go-test-coverage@v2 | |
| with: | |
| config: ./.testcoverage.yml | |
| - uses: guibranco/github-status-action-v2@v1 | |
| if: ${{ env.COND_PUSH_OR_PR }} | |
| with: | |
| authToken: ${{ secrets.GITHUB_TOKEN }} | |
| context: unit-tests-${{matrix.go-version}}-${{matrix.os}} | |
| state: ${{ job.status }} | |
| # ------------------------------------------------------- | |
| # Build and deploy documentation | |
| # ------------------------------------------------------- | |
| build-deploy: | |
| needs: | |
| - unit-tests | |
| - pre-commit | |
| # Only run if the test and pre-commit jobs succeeded, and if the push is on master branch or if it's a workflow dispatch event | |
| if: |- | |
| ${{ | |
| needs.unit-tests.result == 'success' && | |
| needs.pre-commit.result == 'success' && | |
| github.ref == 'refs/heads/master' | |
| }} | |
| uses: fchastanet/my-documents/.github/workflows/build-site-action.yml@master | |
| with: | |
| site-name: "bash-compiler" | |
| checkout-repo: "fchastanet/bash-compiler" | |
| site-dir: "_site-content" | |
| secrets: inherit | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write |