我有一个处理新版本的 Github Actions 工作流程。最后的一些步骤为不同平台构建应用程序。我不是创建多个步骤,每个步骤针对不同的平台进行构建,也不是创建一个运行多个命令的步骤,而是寻找一种为数组中的每个项目循环一个步骤的方法。
我知道有一个工作矩阵,所以这是我的伪实现来显示我正在寻找的内容
jobs:
do_it:
runs-on: ubuntu-latest
steps:
- name: For each entry in the array...
strategy:
matrix:
target: [ this, that, something ]
run: echo ${{ matrix.target }}
Run Code Online (Sandbox Code Playgroud)
是否可以创建类似于矩阵的东西,以便它可以多次循环该步骤?
作为旁注,我知道有一个类似的问题使用一组值来重复 GitHub Actions 工作流程中的步骤,但我不想将作业拆分为多个作业,因为这样我必须处理所有构建工件。
我使用创建了一个新的 Vue 应用程序npm create vue。在运行时,该应用程序会获取配置并从中读取字符串。该字符串表示要在应用程序内呈现的组件的名称。这些动态组件位于“可插入”目录中
.\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 src\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 App.vue\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 pluggables\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 ThisFoo.vue\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 ThatBar.vue\nRun Code Online (Sandbox Code Playgroud)\n所以基本上 App.vue 文件的作用是
\n<script setup lang="ts">\nimport { onMounted, shallowRef, defineAsyncComponent } from "vue";\n\nconst pluggableComponent = shallowRef();\n\nonMounted(() => {\n // fetch configuration\n const componentName = "ThisFoo"; // extract from configuration\n\n pluggableComponent.value = defineAsyncComponent(() => import(`./pluggables/${componentName}.vue`));\n});\n</script>\n\n<template>\n <div>Pluggable below:</div>\n <component :is="pluggableComponent" />\n</template>\nRun Code Online (Sandbox Code Playgroud)\n我可以在构建时访问配置文件,并知道运行时需要哪些组件,以及根据此配置将哪些组件视为“死代码”。有没有办法告诉 Vite 从构建中排除未使用的组件?
\n例如,排除整个可插拔目录,但包括可插拔目录中所需的组件
\n\n\nvite build --exclude ./src/pluggables/** --include ./src/pluggables/ThisFoo.vue
\n
或者通过创建自定义 Vite 构建函数,我可以在 CI/CD 期间调用并传入组件名称数组。 …
我通过创建了一个新的 Vue 项目npm init vue@latest并选择了 Cypress。
目前还没有测试,我有一个占位符/cypress/e2e/example.cy.ts测试
describe("My First Test", () => {
it("visits the app root url", () => {
cy.visit("/");
});
});
Run Code Online (Sandbox Code Playgroud)
我正在使用 Cypress v11.0.1,并且有一个脚本可以在我的 Github Actions 中运行 cypress 测试
"test:e2e:ci": "start-server-and-test preview :4173 'cypress run --e2e'",
Run Code Online (Sandbox Code Playgroud)
这是我的 Cypress 动作
- name: Check if e2e tests are passing
uses: cypress-io/github-action@v4
with:
build: npm run build
start: npm run test:e2e:ci
Run Code Online (Sandbox Code Playgroud)
有时(这种情况很少发生) Github 工作流程会失败
正如您所看到的,测试本身通过了。我可以通过再次运行来修复管道......
有人知道为什么会发生这种情况以及如何避免此错误?
如果您需要更多信息(例如配置文件),请告诉我
我有一个使用 Zod 的 Vite 库。我想解析配置,我的文件夹结构与配置对象结构类似。index.ts文件始终导出其自己目录中的所有文件以及其子目录中的所有内容,例如,export * from \'./subDir\';根文件导出“整个库”。
以下设置显示了单个配置分支
\n\n.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 src\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 api\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 dataSources\n| | | \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 dataSource\n| | | | \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 following\n| | | | | \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 computed\n| | | | | | \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 followingComputedDataSourceConfigurationSchema.ts ( extends dataSourceConfigurationSchema )\n| \xe2\x94\x82 \xe2\x94\x82 | | | \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 index.ts\n| | | | | \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 entity\n| | | | | | \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 followingEntityDataSourceConfigurationSchema.ts ( extends leadingDataSourceConfigurationSchema )\n| \xe2\x94\x82 \xe2\x94\x82 | | | …Run Code Online (Sandbox Code Playgroud) 我正在使用 Vuetify 3 并希望有一个文本字段充当日期选择器。您可以在 Vuetify 2 文档中查看示例https://v2.vuetifyjs.com/en/components/date-pickers/#dialog-and-menu
Vuetify 3 文档还没有这样的示例https://vuetifyjs.com/en/components/date-pickers/
我开始制作一个Playground示例原型
<template>
<v-app>
<v-container>
<v-menu v-model="isMenuOpen" :close-on-content-click="false">
<template v-slot:activator="{ props }">
<v-text-field
label="Selected date"
:model-value="selectedDate"
readonly
v-bind="props"
></v-text-field>
</template>
<v-date-picker v-model="selectedDate"></v-date-picker>
</v-menu>
</v-container>
</v-app>
</template>
<script setup>
import { ref } from 'vue'
const isMenuOpen = ref(false)
const selectedDate = ref()
</script>
Run Code Online (Sandbox Code Playgroud)
如何从日期选择器中删除所有多余的东西?我不需要
因此,每当我选择日期时,我都希望模型更新
给定客户端发出 HTTP 请求
<!DOCTYPE html>
<html>
<body>
<script>
fetch('http://localhost:3000/messages', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ data: 'foo' })
})
.then(async response => {
console.log(await response.json());
});
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
API服务器不处理请求,请求处理程序应充当代理并将请求发送到另一台服务器
import (
"net/http"
"net/http/httputil"
"net/url"
)
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/messages", handleRequest)
http.ListenAndServe(":3000", mux)
}
func handleRequest(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "*")
w.Header().Set("Access-Control-Allow-Methods", "*")
targetUrl, _ := url.Parse("http://localhost:3001/messages")
proxy := httputil.NewSingleHostReverseProxy(targetUrl)
proxy.ServeHTTP(w, r)
}
Run Code Online (Sandbox Code Playgroud)
目标服务器应该处理请求并发回响应
import (
"encoding/json"
"net/http"
)
func …Run Code Online (Sandbox Code Playgroud) 基于crypto.subtle.exportKey("spki", cryptoKey)我想将返回的值转换ArrayBuffer为字符串,以便我可以将其转换为 base64 字符串。根据我尝试过的文档
const bufferAsString = String.fromCharCode.apply(null, new Uint8Array(buffer));
Run Code Online (Sandbox Code Playgroud)
但 TypeScript 告诉我
TS2345:“Uint8Array”类型的参数不可分配给“number[]”类型的参数。
如何修复类型错误?
给定来自不同数据源的节点结构,其中一个节点依赖于0 到 n 个其他节点,但单个节点只能依赖于一个源的节点
const nodes = [
{ dataSourceId: "a", id: "a-1", dependsOnDataSourceId: undefined, dependsOnNodes: [] },
{ dataSourceId: "a", id: "a-2", dependsOnDataSourceId: undefined, dependsOnNodes: [] },
{ dataSourceId: "a", id: "a-3", dependsOnDataSourceId: undefined, dependsOnNodes: [] },
{ dataSourceId: "b", id: "b-1", dependsOnDataSourceId: "a", dependsOnNodes: ["a-1"] },
{ dataSourceId: "b", id: "b-2", dependsOnDataSourceId: "a", dependsOnNodes: ["a-1"] },
{ dataSourceId: "b", id: "b-3", dependsOnDataSourceId: "a", dependsOnNodes: ["a-1", "a-2"] },
{ dataSourceId: "c", id: "c-1", dependsOnDataSourceId: "b", dependsOnNodes: ["b-1"] …Run Code Online (Sandbox Code Playgroud) 我为 Node 和浏览器创建了一个库,并想要调用一个以流响应的外部端点。由于该流可能永远不会结束,因此客户端应该能够中止该进程。
public async observe(): Promise<() => void> {
const abortController = new AbortController();
const response = await fetch('url', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: { /* ... */ },
signal: abortController.signal,
});
if (!response.ok) {
// handle error
}
setImmediate(async () => {
// parse response.body ( stream )
});
return () => {
abortController.abort();
};
}
Run Code Online (Sandbox Code Playgroud)
我使用它是setImmediate因为我必须首先返回 abort 函数,否则该函数将永远不会到达 return 语句,因为它会不断解析流。
不幸的setImmediate是,浏览器不支持(https://developer.mozilla.org/en-US/docs/Web/API/Window/setImmediate?retiredLocale=de#browser_compatibility)
有人知道用什么代替吗?
这可能与Zod: Parse external JSON file重复
我有一个函数需要一个 JSON 字符串并将其解析为由 Zod 模式推断的给定类型
const createConfigurationFromJson = (content: string): Configuration => {
const rawConfiguration = JSON.parse(content);
return configurationSchema.parse(rawConfiguration);
};
Run Code Online (Sandbox Code Playgroud)
如果 JSON 内容是无效 JSON 或 Zod 抛出解析错误,则此函数可能会抛出异常。在不使用其他第三方库的情况下,是否可以让Zod解析JSON字符串?所以我可以确定只能是Zod错误?
我有一些带有指示其类型的静态变量的类。我想基于这些静态变量创建一个联合类型
class Foo {
static typeId = 'i-am-foo';
}
class Bar {
static typeId = 'i-am-bar';
}
type MyUnionType = Foo.typeId | Bar.typeId;
Run Code Online (Sandbox Code Playgroud)
不幸的是这是不可能的,我收到错误
“Foo”仅指一种类型,但在这里用作命名空间。
是否可以使用静态变量进行类型定义?
给出以下示例 Github 操作工作流程
name: My workflow
on: pull_request
jobs:
foo:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 1.19
- name: Foo
run: echo "foo"
bar:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 1.19
- name: Bar
run: echo "bar"
Run Code Online (Sandbox Code Playgroud)
我希望这些工作Foo和Bar并行运行。但正如您所看到的,它们有一些共同的步骤。
是否可以创建一个运行结帐和设置步骤并提供自身的作业Foo,Bar以便他们只需运行自己的命令?(这会节省一些时间,但我认为这是不可能的,因为这两个作业都在单独的容器中运行)
如果这是不可能的,有没有办法提取“重复”行并将它们移动到我可以在工作中调用的“步骤函数”,这样我就不必一遍又一遍地编写这些步骤?
javascript ×6
typescript ×4
vue.js ×3
zod ×2
algorithm ×1
cypress ×1
go ×1
html ×1
node.js ×1
rollup ×1
vite ×1
vuetify.js ×1
vuetifyjs3 ×1