Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply pr2957 to mega-linter-runner/.../mega-linter.yml #3033

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/mega-linter-for-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ jobs:
(
github.event_name == 'push' ||
github.event.pull_request.head.repo.full_name == github.repository
)
) &&
!contains(github.event.head_commit.message, 'skip fix')
Comment on lines +128 to +129
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}}" >> "${GITHUB_ENV}"

# Set APPLY_FIXES_IF_* vars for use in future steps
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/mega-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ jobs:
(
github.event_name == 'push' ||
github.event.pull_request.head.repo.full_name == github.repository
)
) &&
!contains(github.event.head_commit.message, 'skip fix')

Comment on lines +128 to +130
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}}" >> "${GITHUB_ENV}"

# Set APPLY_FIXES_IF_* vars for use in future steps
Expand Down
3 changes: 2 additions & 1 deletion TEMPLATES/mega-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ jobs:
(
github.event_name == 'push' ||
github.event.pull_request.head.repo.full_name == github.repository
)
) &&
!contains(github.event.head_commit.message, 'skip fix')
Comment on lines +123 to +124
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rasa please propose a change for this in #3032 and I will accept.

Copy link
Contributor Author

@rasa rasa Oct 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer the || solution, but it's more important that we apply this the same logic across all five (?) instances of mega-linter.yml.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... but it's more important that we apply this logic across all five (?) instances of mega-linter.yml.

Seems weird like that. We have one that is our own for dogfooding (the python@beta), another one for the second project (the node mega-linter-runner) again for dogfooding, then there is the one that is for the template for users, and all the duplicatas built into the documentation... I expect that these update from their sources when running ./build.sh, except if I'm wrong (and we should fix it).

}}" >> "${GITHUB_ENV}"

# Set APPLY_FIXES_IF_* vars for use in future steps
Expand Down
104 changes: 46 additions & 58 deletions mega-linter-runner/generators/mega-linter/templates/mega-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
---
name: MegaLinter

# Trigger mega-linter at every push. Action will also be visible from
# Pull Requests to main
# Trigger mega-linter at every push. Action will also be visible from Pull
# Requests to main
Comment on lines +6 to +7
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on:
# Comment this line to trigger action only on pull-requests
# (not recommended if you don't pay for GH Actions)
Expand Down Expand Up @@ -41,16 +41,17 @@ jobs:
runs-on: ubuntu-latest

# Give the default GITHUB_TOKEN write permission to commit and push, comment
# issues, and post new Pull Requests; remove the ones you do not need
# issues & post new PR; remove the ones you do not need
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

permissions:
contents: write
issues: write
pull-requests: write

steps:

# Git Checkout
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
Comment on lines +51 to +54
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@andrewvaughan andrewvaughan Oct 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@echoix one thing to consider with an upgrade to checkout@v4 is it may break workflows for people who use local linting. I'm thinking about tools like https://github.com/nektos/act - they're falling pretty far behind in keeping up with GitHub on server images. @catthehacker is the user that was maintaining those and they have left GitHub. It is possible that an upgrade to actions/checkout@v4, which, if I recall correctly upgrades the node version required, could break MegaLinter's ability to run locally via act.

It's something we need to earmark for a test (and I have with the change I proposed) prior to merging this into MegaLinter's next release.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the most important use case isn't with act, and thus, it way more important to not use a node version that is EOL since Sept 11, 2023 (node 16 used in actions/checkout@v3). Running locally with act, even if I have done it a couple of times in the past (when doing big changes in the docker building actions and multiplatform builds, iterating on GitHub was way too long), remains more of a hack than a supported (by us) use-case. Having an up to date runner image for act seems like the way to solve your interrogation.

I don't understand the meaning of your last sentence, especially "earmark for a test", and what do you expect before a next release (that should be due soon IMO, maybe wait a little after we settled and merged the big template changes and other link changes PRs).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have pretty up-to-date nodejs on images.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have pretty up-to-date nodejs on images.

I wasn't able to run checkout@v4 on the latest images as Node 20 wasn't available, IIRC.

with:
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}

Expand All @@ -62,14 +63,15 @@ jobs:
- name: MegaLinter

# You can override MegaLinter flavor used to have faster performances
# More info at https://megalinter.io/latest/flavors/
# More info at https://megalinter.io/flavors/
echoix marked this conversation as resolved.
Show resolved Hide resolved
uses: <%= GITHUB_ACTION_NAME %>@<%= GITHUB_ACTION_VERSION %>

id: ml

# All available variables are described in documentation
# https://megalinter.io/latest/config-file/
# https://megalinter.io/configuration/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original would be the correct link, #2986

env:

# Validates all source when push on main, else just the git diff with
# main. Override with true if you always want to lint all sources
#
Expand All @@ -80,15 +82,18 @@ jobs:
# VALIDATE_ALL_CODEBASE: >-
# ${{
# github.event_name == 'push' &&
# github.ref == 'refs/heads/main'
# contains(fromJSON('["refs/heads/main", "refs/heads/master"]'), github.ref)
# }}
VALIDATE_ALL_CODEBASE: <%- VALIDATE_ALL_CODE_BASE_GHA %>

GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# ADD YOUR CUSTOM ENV VARIABLES HERE TO OVERRIDE VALUES OF
# ADD YOUR CUSTOM ENV VARIABLES HERE OR DEFINE THEM IN A FILE
# .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY

# Uncomment to disable copy-paste and spell checks
# DISABLE: COPYPASTE,SPELL

# Upload MegaLinter artifacts
- name: Archive production artifacts
uses: actions/upload-artifact@v3
Expand All @@ -99,79 +104,62 @@ jobs:
megalinter-reports
mega-linter.log

# Set APPLY_FIXES_IF var for use in future steps
- name: Set APPLY_FIXES_IF var
run: |
printf 'APPLY_FIXES_IF=%s\n' "${{
steps.ml.outputs.has_updated_sources == 1 &&
(
env.APPLY_FIXES_EVENT == 'all' ||
env.APPLY_FIXES_EVENT == github.event_name
) &&
(
github.event_name == 'push' ||
github.event.pull_request.head.repo.full_name == github.repository
) &&
!contains(github.event.head_commit.message, 'skip fix')
}}" >> "${GITHUB_ENV}"

# Set APPLY_FIXES_IF_* vars for use in future steps
- name: Set APPLY_FIXES_IF_* vars
run: |
printf 'APPLY_FIXES_IF_PR=%s\n' "${{
env.APPLY_FIXES_IF == 'true' &&
env.APPLY_FIXES_MODE == 'pull_request'
}}" >> "${GITHUB_ENV}"
printf 'APPLY_FIXES_IF_COMMIT=%s\n' "${{
env.APPLY_FIXES_IF == 'true' &&
env.APPLY_FIXES_MODE == 'commit' &&
(!contains(fromJSON('["refs/heads/main", "refs/heads/master"]'), github.ref))
}}" >> "${GITHUB_ENV}"

# Create pull request if applicable
# (for now works only on PR from same repository, not from forks)
- name: Create Pull Request with applied fixes
uses: peter-evans/create-pull-request@v5
id: cpr
if: >-
steps.ml.outputs.has_updated_sources == 1 &&
(
env.APPLY_FIXES_EVENT == 'all' ||
env.APPLY_FIXES_EVENT == github.event_name
) &&
env.APPLY_FIXES_MODE == 'pull_request' &&
(
github.event_name == 'push' ||
github.event.pull_request.head.repo.full_name == github.repository
) &&
!contains(github.event.head_commit.message, 'skip fix')
if: env.APPLY_FIXES_IF_PR == 'true'
with:
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
commit-message: "[MegaLinter] Apply linters automatic fixes"
title: "[MegaLinter] Apply linters automatic fixes"
labels: bot

- name: Create PR output
if: >-
steps.ml.outputs.has_updated_sources == 1 &&
(
env.APPLY_FIXES_EVENT == 'all' ||
env.APPLY_FIXES_EVENT == github.event_name
) &&
env.APPLY_FIXES_MODE == 'pull_request' &&
(
github.event_name == 'push' ||
github.event.pull_request.head.repo.full_name == github.repository
) &&
!contains(github.event.head_commit.message, 'skip fix')
if: env.APPLY_FIXES_IF_PR == 'true'
run: |
echo "PR Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "PR URL - ${{ steps.cpr.outputs.pull-request-url }}"

# Push new commit if applicable
# (for now works only on PR from same repository, not from forks)
- name: Prepare commit
if: >-
steps.ml.outputs.has_updated_sources == 1 &&
(
env.APPLY_FIXES_EVENT == 'all' ||
env.APPLY_FIXES_EVENT == github.event_name
) &&
env.APPLY_FIXES_MODE == 'commit' &&
github.ref != 'refs/heads/main' &&
(
github.event_name == 'push' ||
github.event.pull_request.head.repo.full_name == github.repository
) &&
!contains(github.event.head_commit.message, 'skip fix')
if: env.APPLY_FIXES_IF_COMMIT == 'true'
run: sudo chown -Rc $UID .git/

- name: Commit and push applied linter fixes
uses: stefanzweifel/git-auto-commit-action@v4
if: >-
steps.ml.outputs.has_updated_sources == 1 &&
(
env.APPLY_FIXES_EVENT == 'all' ||
env.APPLY_FIXES_EVENT == github.event_name
) &&
env.APPLY_FIXES_MODE == 'commit' &&
github.ref != 'refs/heads/main' &&
(
github.event_name == 'push' ||
github.event.pull_request.head.repo.full_name == github.repository
) &&
!contains(github.event.head_commit.message, 'skip fix')
if: env.APPLY_FIXES_IF_COMMIT == 'true'
with:
branch: >-
${{
Expand Down
Loading