diff --git a/.github/workflows/sync-scala-version.yaml b/.github/workflows/sync-scala-version.yaml deleted file mode 100644 index 20820346..00000000 --- a/.github/workflows/sync-scala-version.yaml +++ /dev/null @@ -1,39 +0,0 @@ ---- - -name: Sync scala format version between Dockerfile and config file - -on: - pull_request: - paths: - - 'Dockerfile' - -permissions: - contents: write - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - with: - repository: ${{ github.event.pull_request.head.repo.full_name }} - ref: ${{ github.event.pull_request.head.ref }} - - - name: Sync the version if the dockerfile is getting updated - shell: bash - run: | - scala_version_from_dockerfile=$(grep 'scalameta/scalafmt' Dockerfile | awk -F: '{print $2}' | awk '{print $1}') - scala_version_from_dockerfile=${scala_version_from_dockerfile#v} - - scala_version_from_config=$(grep 'version =' TEMPLATES/.scalafmt.conf | awk -F= '{print $2}' | tr -d '[:space:]') - - echo "scala_version_from_dockerfile: $scala_version_from_dockerfile" - echo "scala_version_from_config: $scala_version_from_config" - - if [ "$scala_version_from_dockerfile" != "$scala_version_from_config" ]; then echo "versions differ"; sed -i "s/\(version =\).*/\1 ${scala_version_from_dockerfile}/g" TEMPLATES/.scalafmt.conf; fi - - uses: EndBug/add-and-commit@v9 # You can change this to use a specific version. - with: - add: 'TEMPLATES/.scalafmt.conf' - fetch: false - message: 'Update scala config version to match version installed' diff --git a/Dockerfile b/Dockerfile index 309c58f2..1edd060f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -343,6 +343,7 @@ COPY --from=gitleaks /usr/bin/gitleaks /usr/bin/ # Install scalafmt # #################### COPY --from=scalafmt /bin/scalafmt /usr/bin/ +RUN scalafmt --version | awk ' { print $2 }' > /tmp/scalafmt-version.txt ###################### # Install actionlint # @@ -436,6 +437,12 @@ RUN /linterVersions.sh \ ################################### COPY TEMPLATES /action/lib/.automation +# Dynamically set scalafmt version in the scalafmt configuration file +# Ref: https://scalameta.org/scalafmt/docs/configuration.html#version +COPY --from=base_image /tmp/scalafmt-version.txt /tmp/scalafmt-version.txt +RUN echo "version = $(cat /tmp/scalafmt-version.txt)" >> /action/lib/.automation/.scalafmt.conf \ + && rm /tmp/scalafmt-version.txt + ################################# # Copy super-linter executables # ################################# @@ -511,6 +518,12 @@ RUN /linterVersions.sh \ ################################### COPY TEMPLATES /action/lib/.automation +# Dynamically set scalafmt version in the scalafmt configuration file +# Ref: https://scalameta.org/scalafmt/docs/configuration.html#version +COPY --from=base_image /tmp/scalafmt-version.txt /tmp/scalafmt-version.txt +RUN echo "version = $(cat /tmp/scalafmt-version.txt)" >> /action/lib/.automation/.scalafmt.conf \ + && rm /tmp/scalafmt-version.txt + ################################# # Copy super-linter executables # ################################# diff --git a/TEMPLATES/.scalafmt.conf b/TEMPLATES/.scalafmt.conf index 632fc97e..fe68622b 100644 --- a/TEMPLATES/.scalafmt.conf +++ b/TEMPLATES/.scalafmt.conf @@ -1,7 +1,11 @@ // Scala Format Configuration // https://scalameta.org/scalafmt/docs/configuration.html -version = 3.8.2 -align.preset = more // For pretty alignment. +align.preset = more maxColumn = 80 // https://scalameta.org/scalafmt/docs/configuration.html#scala-dialects runner.dialect = scala3 + +// The version parameter is required to be specified explicitly +// Ref: https://scalameta.org/scalafmt/docs/configuration.html#version +// It will be added at the end of this file when building the Super-linter +// container image