diff --git a/.github/workflows/buildx.yml b/.github/workflows/buildx.yml index 32b3bd535d..43c083f29b 100644 --- a/.github/workflows/buildx.yml +++ b/.github/workflows/buildx.yml @@ -2,6 +2,7 @@ name: Publish Docker images on: workflow_dispatch: + workflow_call: schedule: - cron: "0 3 * * *" push: @@ -10,7 +11,8 @@ on: paths: - "**/*" - "!.github/**" # Important: Exclude PRs related to .github from auto-run - - "!.github/workflows/**" # Important: Exclude PRs related to .github from auto-run + - "!.github/workflows/**" # Important: Exclude PRs related to .github/workflows from auto-run + - "!.github/actions/**" # Important: Exclude PRs related to .github/actions from auto-run env: REGISTRY_IMAGE: teslamate/teslamate diff --git a/.github/workflows/check_paths.yml b/.github/workflows/check_paths.yml index d3fc91d027..b1f71b470f 100644 --- a/.github/workflows/check_paths.yml +++ b/.github/workflows/check_paths.yml @@ -22,6 +22,9 @@ on: - "!.github/workflows/**" # Important: Exclude PRs related to .github/workflows from auto-run - "!.github/actions/**" # Important: Exclude PRs related to .github/actions from auto-run +permissions: + contents: read + jobs: check_paths: runs-on: ubuntu-latest diff --git a/.github/workflows/devops.yml b/.github/workflows/devops.yml new file mode 100644 index 0000000000..65e1218eb4 --- /dev/null +++ b/.github/workflows/devops.yml @@ -0,0 +1,51 @@ +name: DevOps + +on: + workflow_dispatch: + push: + paths: + - "**/*" + - "!.github/**" # Important: Exclude PRs related to .github from auto-run + - "!.github/workflows/**" # Important: Exclude PRs related to .github/workflows from auto-run + - "!.github/actions/**" # Important: Exclude PRs related to .github/actions from auto-run + pull_request: + branches: ["master"] + paths: + - "**/*" + - "!.github/**" # Important: Exclude PRs related to .github from auto-run + - "!.github/workflows/**" # Important: Exclude PRs related to .github/workflows from auto-run + - "!.github/actions/**" # Important: Exclude PRs related to .github/actions from auto-run + +permissions: + contents: read + +jobs: + check_paths: + uses: ./.github/workflows/check_paths.yml + + spell_check: + needs: check_paths + if: needs.check_paths.outputs.githubfolder == 'false' || github.event_name == 'schedule' + uses: ./.github/workflows/spell_check.yml + + # ensure_linting: + # needs: + # - check_paths + # - spell_check + # if: needs.check_paths.outputs.githubfolder == 'false' || github.event_name == 'schedule' + # uses: ./.github/workflows/ensure_linting.yml + + elixir: + needs: + - check_paths + - spell_check + # - ensure_linting + if: needs.check_paths.outputs.githubfolder == 'false' || github.event_name == 'schedule' + uses: ./.github/workflows/elixir.yml + + ghcr_build: + needs: + - check_paths + - elixir + if: needs.check_paths.outputs.githubfolder == 'false' || github.event_name == 'schedule' + uses: ./.github/workflows/ghcr_build.yml diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.yml index 9dfc3cc781..5f9da7b955 100644 --- a/.github/workflows/elixir.yml +++ b/.github/workflows/elixir.yml @@ -1,15 +1,7 @@ name: Elixir CI on: - push: - paths: - - "**/*" - - "!.github/**" # Important: Exclude PRs related to .github from auto-run - pull_request: - branches: ["master"] - paths: - - "**/*" - - "!.github/**" # Important: Exclude PRs related to .github from auto-run + workflow_call: env: CACHE_NAME_DEPS: cache-elixir-deps @@ -17,6 +9,9 @@ env: CACHE_NAME_COMPILED_TEST: cache-compiled-test-build ELIXIR_ASSERT_TIMEOUT: 1000 +permissions: + contents: read + jobs: check_paths: uses: ./.github/workflows/check_paths.yml diff --git a/.github/workflows/ghcr_build.yml b/.github/workflows/ghcr_build.yml index 2cf4aae91e..def558d7c1 100644 --- a/.github/workflows/ghcr_build.yml +++ b/.github/workflows/ghcr_build.yml @@ -1,19 +1,14 @@ name: Build GHCR images on: - workflow_dispatch: - push: - paths: - - "**/*" - - "!.github/**" # Important: Exclude PRs related to .github from auto-run - - "!.github/workflows/**" # Important: Exclude PRs related to .github from auto-run - branches: ["ci"] + workflow_call: pull_request_target: branches: ["master", "ci"] paths: - "**/*" - "!.github/**" # Important: Exclude PRs related to .github from auto-run - - "!.github/workflows/**" # Important: Exclude PRs related to .github from auto-run + - "!.github/workflows/**" # Important: Exclude PRs related to .github/workflows from auto-run + - "!.github/actions/**" # Important: Exclude PRs related to .github/actions from auto-run env: REGISTRY_IMAGE: ghcr.io/${{ github.repository }} diff --git a/.github/workflows/ghcr_purge.yml b/.github/workflows/ghcr_purge.yml index c01de8b11b..709aaed080 100644 --- a/.github/workflows/ghcr_purge.yml +++ b/.github/workflows/ghcr_purge.yml @@ -1,13 +1,15 @@ name: Purge PR images on: + workflow_call: pull_request_target: types: - closed paths: - "**/*" - "!.github/**" # Important: Exclude PRs related to .github from auto-run - - "!.github/workflows/**" # Important: Exclude PRs related to .github from auto-run + - "!.github/workflows/**" # Important: Exclude PRs related to .github/workflows from auto-run + - "!.github/actions/**" # Important: Exclude PRs related to .github/actions from auto-run permissions: contents: read diff --git a/.github/workflows/spell_check.yml b/.github/workflows/spell_check.yml index 8aa1700cb3..a317e48be2 100644 --- a/.github/workflows/spell_check.yml +++ b/.github/workflows/spell_check.yml @@ -1,184 +1,21 @@ -name: Elixir CI +name: Spell check on: - push: - paths: - - "**/*" - - "!.github/**" # Important: Exclude PRs related to .github from auto-run - pull_request: - branches: ["master"] - paths: - - "**/*" - - "!.github/**" # Important: Exclude PRs related to .github from auto-run + workflow_call: -env: - CACHE_NAME_DEPS: cache-elixir-deps - CACHE_NAME_COMPILED_DEV: cache-compiled-dev-build - CACHE_NAME_COMPILED_TEST: cache-compiled-test-build - ELIXIR_ASSERT_TIMEOUT: 1000 +permissions: + contents: read jobs: check_paths: uses: ./.github/workflows/check_paths.yml - verify_dependencies_and_static_analysis: - name: Verify dependencies, POT files, unused dependencies, static analysis + spell_check: + name: Spell check needs: check_paths if: needs.check_paths.outputs.githubfolder == 'false' || github.event_name == 'schedule' runs-on: ubuntu-20.04 - permissions: - contents: read - - steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - - - name: Setup Elixir and Cache Dependencies - id: setup-elixir-and-cache-deps - uses: ./.github/actions/setup-elixir-and-cache-deps - with: - cache-name-deps: ${{ env.CACHE_NAME_DEPS }} - cache-name-compiled: ${{ env.CACHE_NAME_COMPILED_DEV }} -name: Elixir CI - -on: - push: - paths: - - "**/*" - - "!.github/**" # Important: Exclude PRs related to .github from auto-run - pull_request: - branches: ["master"] - paths: - - "**/*" - - "!.github/**" # Important: Exclude PRs related to .github from auto-run - -env: - CACHE_NAME_DEPS: cache-elixir-deps - CACHE_NAME_COMPILED_DEV: cache-compiled-dev-build - CACHE_NAME_COMPILED_TEST: cache-compiled-test-build - ELIXIR_ASSERT_TIMEOUT: 1000 - -jobs: - check_paths: - runs-on: ubuntu-latest - outputs: - githubfolder: ${{ steps.filter.outputs.githubfolder }} steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - - - uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 - id: filter - with: - filters: | - githubfolder: - - '.github/**' - - lint: - name: Lint - needs: check_paths - if: needs.check_paths.outputs.githubfolder == 'false' || github.event_name == 'schedule' - runs-on: ubuntu-20.04 - - permissions: - contents: read - - steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - - - name: Setup Elixir and Cache Dependencies - id: setup-elixir-and-cache-deps - uses: ./.github/actions/setup-elixir-and-cache-deps - with: - cache-name-deps: ${{ env.CACHE_NAME_DEPS }} - cache-name-compiled: ${{ env.CACHE_NAME_COMPILED_DEV }} - mix-env: dev - - - name: Compile without warnings - run: mix compile --warnings-as-errors - shell: sh - - - name: Verify that POT files are up to date - run: mix gettext.extract --check-up-to-date - - name: Spell check uses: crate-ci/typos@c16dc8f5b4a7ad6211464ecf136c69c851e8e83c # v1.22.9 - - - name: Check formatting - run: mix format --check-formatted - - - name: Check unused dependencies - run: mix deps.unlock --check-unused - - - name: Restore PLT cache - id: plt_cache - uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 - with: - key: | - ${{ runner.os }}-${{ steps.setup-elixir-and-cache-deps.outputs.elixir-version }}-${{ steps.setup-elixir-and-cache-deps.outputs.otp-version }}-plt - restore-keys: | - ${{ runner.os }}-${{ steps.setup-elixir-and-cache-deps.outputs.elixir-version }}-${{ steps.setup-elixir-and-cache-deps.outputs.otp-version }}-plt - path: | - priv/plts - - - name: Create Persistent Lookup Tables (PLTs) for Dialyzer - if: steps.plt_cache.outputs.cache-hit != 'true' - run: mix dialyzer --plt - - - name: Save PLT cache - id: plt_cache_save - uses: actions/cache/save@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 - if: steps.plt_cache.outputs.cache-hit != 'true' - with: - key: | - ${{ runner.os }}-${{ steps.setup-elixir-and-cache-deps.outputs.elixir-version }}-${{ steps.setup-elixir-and-cache-deps.outputs.otp-version }}-plt - path: | - priv/plts - - - name: Run dialyzer for static analysis - run: mix dialyzer --format github - - test: - name: Test - needs: - - check_paths - - lint - if: needs.check_paths.outputs.githubfolder == 'false' || github.event_name == 'schedule' - runs-on: ubuntu-20.04 - - permissions: - contents: read - - services: - db: - image: postgres:16 - ports: ["5432:5432"] - env: - POSTGRES_PASSWORD: postgres - options: >- - --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 - - steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - - - name: Setup Elixir and Cache Dependencies - id: setup-elixir-and-cache-deps - uses: ./.github/actions/setup-elixir-and-cache-deps - with: - cache-name-deps: ${{ env.CACHE_NAME_DEPS }} - cache-name-compiled: ${{ env.CACHE_NAME_COMPILED_TEST }} - mix-env: test - ELIXIR_ASSERT_TIMEOUT: ${{ env.ELIXIR_ASSERT_TIMEOUT }} - - - name: Compile without warnings - run: mix compile --warnings-as-errors - shell: sh - - - name: Run tests - run: mix test --warnings-as-errors - - - name: Check Coverage - if: github.ref == 'refs/heads/master' - run: mix coveralls.github - continue-on-error: true - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f9c93ccd4..c907dd2b20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ - ci(refactor): use composite action to avoid duplication in elixir workflow (#4219 - @JakobLichterfeld) - ci: prevent workflow runs for certain conditions and allow scheduled runs (#4219 - @JakobLichterfeld) - ci(refactor): use reusable workflow to check paths (#4219 - @JakobLichterfeld) +- ci(refactor): use reusable workflows for streamlined DevOps pipeline (#4219 - @JakobLichterfeld) #### Dashboards