对于我们的应用程序构建号,我们使用分支构建中存储库迄今为止的提交总数。
这是之前使用的实现的
git log --oneline | wc -l
Run Code Online (Sandbox Code Playgroud)
之前我们使用jenkins,现在我们正在更改为github actions。
当尝试使用类似的工作流程步骤来计算提交计数时,每次只给出 1。
我的工作流程。
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ r12.1_githubactions ]
pull_request:
branches: [ r12.1_githubactions ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is …Run Code Online (Sandbox Code Playgroud) 我的 CI 管道中有两个步骤。一是缓存dotnet的安装路径,二是dotnet安装。并使用 windows-2019 图像。但系统永远无法识别 .net 7 可用,它始终安装了 .net 6.0。缓存还显示缓存了 200MB,但可能某些 PATH 变量需要调整。有人可以帮我弄这个吗?
runs-on: windows-2019
env:
DOTNET_INSTALL_DIR: '.\.dotnet'
DOTNET_ROOT: '.\.dotnet'
Run Code Online (Sandbox Code Playgroud)
我的缓存步骤是:
- name: Cache dotnet
id: cache-dotnet-core # id used in cache-hit condition
uses: actions/cache@v3
with:
path: '.\.dotnet' #~/.dotnet
key: ${{ runner.os }}-dotnet-${{ hashFiles('**/project.assets.json') }}
restore-keys: ${{ runner.os }}-dotnet-${{ hashFiles('**/project.assets.json') }}
Run Code Online (Sandbox Code Playgroud)
我的 dotnet 安装步骤是
- name: Install Dotnet
#if: steps.cache-dotnet-core.outputs.cache-hit != 'true' # condition to check if old installation is available in cache
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
Run Code Online (Sandbox Code Playgroud)
请记住,保存缓存后,第二次运行作业将显示 .net …
给出以下示例 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以便他们只需运行自己的命令?(这会节省一些时间,但我认为这是不可能的,因为这两个作业都在单独的容器中运行)
如果这是不可能的,有没有办法提取“重复”行并将它们移动到我可以在工作中调用的“步骤函数”,这样我就不必一遍又一遍地编写这些步骤?
我目前正在尝试从其他两个工作流程调用可重用工作流程,这两个工作流程都位于与可重用工作流程相同的目录和相同的私有存储库中。这些文件看起来像这样:
// .github/workflows/deploy.yml
name: Deploy
on:
workflow_call:
inputs:
bucketFolder:
type: string
jobs:
deploy:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18]
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 7
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "pnpm"
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Install modules
run: pnpm install
- name: Build application
run: pnpm run build
- name: Deploy to S3
run: aws s3 …Run Code Online (Sandbox Code Playgroud) Github Action 类似功能的等效配置是什么,如下命令:
env-cmd -f .env cypress run --component
Run Code Online (Sandbox Code Playgroud)
我尝试将一个环境变量导入到 Github Action 中,但不起作用:
env:
CYPRESS_PUBLIC_PATH: /public/
Run Code Online (Sandbox Code Playgroud)
因此,我更喜欢加载 env 文件并直接由应用程序/cypress 使用,而不是一一定义 env 变量。
我找不到任何可以在 Github Action 中加载一个 env 文件的文档。或者也许有一种方法可以在 Github Action 中运行上面完全相同的代码?
更新:我按照@Maddie.Squerciati的指示在Cypress配置上定义env文件,它在我的本地工作,但是github操作仍然无法识别/使用env文件。
这是我的 github 操作配置:
name: Cypress
uses: cypress-io/github-action@v5
with:
config-file: cypress.config.js
command: npm run cy:run-unit
component: true
record: false
parallel: false
browser: chrome
Run Code Online (Sandbox Code Playgroud) environment-variables cypress env-file github-actions env-cmd
与我的本地相比,Github 操作运行缓慢,并且 TC 在 github 操作中失败,任何人都可以建议我是否可以在某些特定服务器上运行或在 github 操作 yaml 文件中设置超时,下面是我的 github 操作 yaml 文件
name: Cypress Tests
on: push
jobs:
cypress-run:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Cypress run
uses: cypress-io/github-action@v6
with:
record: true
browser: chrome
spec: cypress/e2e/Customer.cy.js
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Run Code Online (Sandbox Code Playgroud)