mirror of
https://github.com/super-linter/super-linter.git
synced 2024-11-24 17:50:58 -05:00
build: automatically set scalafmt version (#6024)
Automatically append the 'version' configuration parameter to the scalafmt configuration file when building the image instead of using a GitHub Actions workflow to keep the scalafmt configuration file up to date. This makes the building process more reproducible and self-contained in the Dockerfile, and it also avoid stalling Dependabot PRs that update scalafmt because when there are automatically added commits to a PR, they block triggering workflows for that PR.
This commit is contained in:
parent
14e7f7ca2b
commit
38dd638c34
3 changed files with 19 additions and 41 deletions
39
.github/workflows/sync-scala-version.yaml
vendored
39
.github/workflows/sync-scala-version.yaml
vendored
|
@ -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'
|
13
Dockerfile
13
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 #
|
||||
#################################
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue