小编mic*_*ohl的帖子

Github Actions:为什么 shell 脚本中的中间命令失败会导致整个步骤失败?

我在 Github Actions 工作中有一个步骤:

      - name: Check for changes
        run: |
          diff=$( git diff --name-only 'origin/main' )
          changed_files=$( echo $diff | grep -c src/my_folder ) # this fails

          # more script lines
          # that are unrelated
Run Code Online (Sandbox Code Playgroud)

Error: Process completed with exit code 1. 仅当 grep 找不到任何内容时才会失败。如果 中有匹配项$diff,则此步骤按预期进行。但当然它也需要在没有匹配的情况下工作。

我可以在本地或在脚本内运行它,没有问题,退出代码总是0(在 Mac 上)。

我不明白问题是什么。经过几个小时的反复试验和研究,我了解到这grep在 Github 操作中显然很棘手,但我没有找到任何提示或适当的文档,我应该如何解决这个确切的情况。

如果我将失败的线路更改为

echo $( echo $diff | grep -c src/my_folder ) # this works and prints out the result
Run Code Online (Sandbox Code Playgroud)

这可以毫无问题地执行。

但是,即使没有发现任何结果,如何将 …

bash continuous-integration grep github-actions

9
推荐指数
1
解决办法
4166
查看次数

如何为我用 Kotlin 编写的自定义 IssueRegistry 解决“过时的自定义 lint 检查”并使其工作(Android)

我正在尝试实现自定义 lint 检查(使用 Kotlin)。我已经为我的自定义检查设置了一个模块并添加了类来测试我的第一个 lew lint 检查,主要是在这里这里遵循这两个教程。

所以我现在有一个模块,我有一个自定义的 IssueRegistry,我已经为它创建了一个问题和一个 Detector 类。到目前为止,它似乎是完整的。我添加了一个测试来检查我的 lint 检查是否有效并且看起来没问题。

我通过在 settings.gradle 中引用它来将我的模块添加到项目中,如下所示: include ':app', ':somemodule', ':mylintmodule'

现在,如果我使用 linter 运行 linter,./gradlew lint我会得到一个 lint 结果文件,告诉我:

    Lint found an issue registry (com.myproject.mylintmodule) which requires a newer API level. That means that the custom lint checks are intended for a newer lint version; please upgrade
    Lint can be extended with "custom checks": additional checks implemented by developers and libraries to for example enforce specific …
Run Code Online (Sandbox Code Playgroud)

android lint kotlin

6
推荐指数
0
解决办法
1791
查看次数

Kotlin:高阶函数,如何向集合中添加函数并调用它们

我有一个类,它包含一组应该在某个事件上调用的函数("监听器")(Android上的Gps更新,但这在这里不重要).看起来像这样(为了清晰起见,大大简化了):

class myClass {
private var listeners = mutableSetOf<(Location) -> Unit>()

fun addListener(listener: (Location) -> Unit) {
    listeners.add { listener }
}

private fun updateListeners(location: Location) {
    if (!listeners.isEmpty()) {
        listeners.forEach {
            it.invoke(location)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

现在我正在尝试从另一个类中添加一个函数,我想在调用updateListeners()时调用它.

class myOtherClass {

private fun registerLocationListener() {
    myClass.addListener (this::onLocationUpdateReceived)
}

private fun onLocationUpdateReceived(location: Location) {
    // do something with the location data
}
Run Code Online (Sandbox Code Playgroud)

编译器在这里没有给我任何警告,所以我首先假设这是正确的.但onLocationUpdateReceived不会被调用.如果我用.toString()记录我的集合中的项目,我得到

Function1<android.location.Location, kotlin.Unit>
Run Code Online (Sandbox Code Playgroud)

这似乎是我想要的 - 但我对此事的经验有限,所以我可能错了.所以我知道updateListeners()被调用,我知道"东西"被放入我的集合中,但onLocationUpdateReceived永远不会被调用.

任何人都可以帮助我如何设置它以便它有效吗?

lambda function set higher-order-functions kotlin

1
推荐指数
1
解决办法
80
查看次数