Sonarcloud-github-action incompatibility with act Github Actions local runner

GitHub - SonarSource/sonarcloud-github-action: Integrate SonarCloud code analysis to GitHub Actions is not usable with GitHub - nektos/act: Run your GitHub Actions locally 馃殌 at the moment, with the first problem being Issue: Docker env PATH lost 路 Issue #896 路 nektos/act 路 GitHub

That is able to be worked around with this little hack

Then I need to add some voodoo to populate sonar.organisation and sonar.project, so my yml is

name: Build
on:
  push:
    branches:
      - master
  pull_request:
    types: [opened, synchronize, reopened]
jobs:
  sonarcloud:
    name: SonarCloud
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0  # Shallow clones should be disabled for a better relevancy of analysis
      - run: echo "REPOSITORY_NAME=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_ENV
        shell: bash
      - name: SonarCloud Scan
        uses: jayvdb/sonarcloud-github-action@workaround-act-issue-896
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}  # Needed to get PR information, if any
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
        with:
          args: >
            -Dsonar.organization=${{ github.repository_owner }}
            -Dsonar.projectKey=${{ github.repository_owner }}_${{ env.REPOSITORY_NAME }}

Then when I run with $ act --detect-event -j sonarcloud in the repo root.

| INFO: Scanner configuration file: /opt/sonar-scanner/conf/sonar-scanner.properties
| INFO: Project root configuration file: NONE
| INFO: SonarScanner 4.6.2.2472
| INFO: Java 11.0.11 Alpine (64-bit)
| INFO: Linux 5.10.47-linuxkit amd64
| INFO: User cache: /opt/sonar-scanner/.sonar/cache
| INFO: Scanner configuration file: /opt/sonar-scanner/conf/sonar-scanner.properties
| INFO: Project root configuration file: NONE
| INFO: Analyzing on SonarCloud
| INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
| INFO: Load global settings
| INFO: Load global settings (done) | time=1685ms
| INFO: Server id: 1BD809FA-AWHW8ct9-T_TB3XqouNu
| INFO: User cache: /opt/sonar-scanner/.sonar/cache
| INFO: Load/download plugins
| INFO: Load plugins index
| INFO: Load plugins index (done) | time=490ms
| INFO: Load/download plugins (done) | time=309991ms
| INFO: Loaded core extensions: developer-scanner
| INFO: Found an active CI vendor: 'Github Actions'
| INFO: Load project settings for component key: '<project-name>'
| INFO: Process project properties
| INFO: Execute project builders
| INFO: Execute project builders (done) | time=5ms
| INFO: Project key: <project-name>
| INFO: Base dir: /Users/jayvdb/projects/github/<repo directory>
| INFO: Working dir: /Users/jayvdb/projects/github/<repo directory>/.scannerwork
| INFO: Load project branches
| INFO: Load project branches (done) | time=387ms
| INFO: Check ALM binding of project '<project-name>'
| INFO: Detected project binding: BOUND
| INFO: Check ALM binding of project '<project-name>' (done) | time=399ms
| INFO: Load project pull requests
| INFO: Load project pull requests (done) | time=401ms
| INFO: Load branch configuration
| INFO: Github event: push
| INFO: ------------------------------------------------------------------------
| INFO: EXECUTION FAILURE
| INFO: ------------------------------------------------------------------------
| INFO: Total time: 5:52.862s
| INFO: Final Memory: 6M/27M
| INFO: ------------------------------------------------------------------------
| ERROR: Error during SonarScanner execution
| java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.scan.filesystem.InputComponentStore
| 	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:52)
| 	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
| 	at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)
| 	at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)
| 	at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
| 	at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)
| 	at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)
| 	at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
| 	at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
| 	at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
| 	at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
| 	at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
| 	at org.picocontainer.DefaultPicoContainer.instantiateComponentAsIsStartable(DefaultPicoContainer.java:1034)
| 	at org.picocontainer.DefaultPicoContainer.addAdapterIfStartable(DefaultPicoContainer.java:1026)
| 	at org.picocontainer.DefaultPicoContainer.startAdapters(DefaultPicoContainer.java:1003)
| 	at org.picocontainer.DefaultPicoContainer.start(DefaultPicoContainer.java:767)
| 	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:122)
| 	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
| 	at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:128)
| 	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
| 	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
| 	at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:58)
| 	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:52)
| 	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
| 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
| 	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
| 	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
| 	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
| 	at com.sun.proxy.$Proxy0.execute(Unknown Source)
| 	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
| 	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
| 	at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
| 	at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
| 	at org.sonarsource.scanner.cli.Main.main(Main.java:61)
| Caused by: java.lang.IllegalStateException: Unable to load component interface org.sonar.scanner.scan.branch.BranchConfiguration
| 	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:52)
| 	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
| 	at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)
| 	at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)
| 	at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
| 	at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)
| 	at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)
| 	at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
| 	at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
| 	at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
| 	at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
| 	at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
| 	at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
| 	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
| 	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:50)
| 	... 34 more
| Caused by: java.lang.RuntimeException: Payload has no field 'ref' in: {}
| 	at org.sonar.scanner.ci.GithubActions.extractFieldSafely(GithubActions.java:174)
| 	at org.sonar.scanner.ci.GithubActions.loadPrAssociatedWithBranch(GithubActions.java:134)
| 	at org.sonar.scanner.ci.GithubActions.autoDetect(GithubActions.java:123)
| 	at java.base/java.util.Optional.flatMap(Optional.java:294)
| 	at org.sonar.scanner.ci.CiEnvironment.loadParameters(CiEnvironment.java:61)
| 	at com.sonarsource.branch.BranchAutoConfiguration.loadParameters(BranchAutoConfiguration.java:39)
| 	at com.sonarsource.branch.BranchConfigurationLoaderImpl.load(BranchConfigurationLoaderImpl.java:50)
| 	at org.sonar.scanner.scan.branch.BranchConfigurationProvider.provide(BranchConfigurationProvider.java:33)
| 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
| 	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
| 	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
| 	at org.picocontainer.injectors.MethodInjector.invokeMethod(MethodInjector.java:129)
| 	at org.picocontainer.injectors.MethodInjector.access$000(MethodInjector.java:39)
| 	at org.picocontainer.injectors.MethodInjector$2.run(MethodInjector.java:113)
| 	at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
| 	at org.picocontainer.injectors.MethodInjector.decorateComponentInstance(MethodInjector.java:120)
| 	at org.picocontainer.injectors.CompositeInjector.decorateComponentInstance(CompositeInjector.java:58)
| 	at org.picocontainer.injectors.Reinjector.reinject(Reinjector.java:142)
| 	at org.picocontainer.injectors.ProviderAdapter.getComponentInstance(ProviderAdapter.java:96)
| 	at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
| 	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
| 	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:50)
| 	... 48 more
| Caused by: java.lang.NullPointerException: Payload has no field 'ref' in: {}
| 	at java.base/java.util.Objects.requireNonNull(Objects.java:347)
| 	at org.sonar.scanner.ci.GithubActions.extractFieldSafely(GithubActions.java:172)
| 	... 70 more
| ERROR:
| ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
[Build/SonarCloud]   鉂  Failure - SonarCloud Scan
Error: exit with `FAILURE`: 1

org.sonar.scanner.ci.GithubActions.loadPrAssociatedWithBranch seems to no longer exist in GitHub - SonarSource/sonarqube: Continuous Inspection . Maybe this has been fixed in more recent versions of sonarqube?