GitLab CI和GitHub Actions Beta 有什么区别?两者都从 Git 存储库谈论 DevOps/自动化
我正在运行 GitHub 操作工作流,并且在尝试运行 maven 安装时出现失败错误。在我可以安装 maven 软件包之前,我需要签名。这是我的工作流程 yml 文件:
name: Github Action
on:
push:
branches:
- master
- release/*
schedule:
- cron: '0 0 * * 0'
jobs:
build:
name: Main
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
java-version: [1.8]
operating-system: [ubuntu-latest]
steps:
- name: Prepare
uses: actions/checkout@v1
- name: Set Up Java Development Kit
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java-version }}
- name: Maven build clean, build, test and install
run: |
mvn clean
mvn install
mvn package --file pom.xml …Run Code Online (Sandbox Code Playgroud) continuous-integration github maven maven-gpg-plugin github-actions
错误,用户 'root'@'localhost' 访问被拒绝(使用密码:YES) 我试图在 Github Actions 中使用 mysql 服务,但没有运气。我收到以下错误
用户 'root'@'localhost' 访问被拒绝(使用密码:YES)
我的工作如下:
test:
name: Test
needs: install
services:
mysql:
image: mysql:8.0
ports:
- '8888:3306'
env:
MYSQL_ROOT_PASSWORD: rootpass
MYSQL_DATABASE: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/setup-node@master
with:
node-version: '10.x'
- run: mysql --port 8888 -u root -prootpass -e 'CREATE DATABASE IF NOT EXISTS test;'
Run Code Online (Sandbox Code Playgroud)
我似乎无法让它工作。任何帮助表示赞赏。可以在此处找到我的测试设置存储库的拉取请求:https : //github.com/morsby/medmcq/pull/399
在我的action.yml 中,我定义了一个输入:
name: 'test action'
author: Param Thakkar
description: 'test'
inputs:
test_var:
description: 'A test variable'
required: true
runs:
using: 'docker'
image: 'Dockerfile'
Run Code Online (Sandbox Code Playgroud)
在我的工作流程中,我通过了 test_var:
name: CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Test the GH action
uses: paramt/github-actions-playground@master
with:
test_var: "this is just a test"
Run Code Online (Sandbox Code Playgroud)
所以应该有一个在工作流运行时创建的环境变量,对吗?但是当我运行这个简短的 python 脚本时:
import os
print(os.getenv('TEST_VAR'))
print("It works!")
exit(0)
Run Code Online (Sandbox Code Playgroud)
它打印:
None
It works!
Run Code Online (Sandbox Code Playgroud)
我认为我必须通过我的 Dockerfile 传递 ENV 变量......现在我的 Dockerfile 看起来像这样:
FROM python:latest
# Add files to the image
ADD …Run Code Online (Sandbox Code Playgroud) 在我的操作工作流程结束时,我有以下步骤。它在代码推送到 master 时运行,其想法是一旦此操作完成,将所有由 github 操作更改的文件提交回 master。
- name: Commit and push changes
run: |
git config --global user.name 'myGithubUserName'
git config --global user.email 'myEmail@gmail.com'
git add -A
git commit -m "Increased build number [skip ci]"
git push -u origin HEAD
Run Code Online (Sandbox Code Playgroud)
但是,即使我正在配置用户和电子邮件,我也不断收到以下错误。
致命:无法读取“ https://github.com ”的用户名:设备未配置
[错误]进程已完成,退出代码为 128。
请注意,这会继续运行macOS-latest并使用预打包的 git。
我想在env:GitHub Action的部分设置一个环境变量,并使用GitHub Actions的上下文和表达式语法。我试过这个:
jobs:
build:
runs-on: ubuntu-latest
env:
MYVAR: ${{ format('{0}:{1}', ${{ env.PATH }}, ${{ env.HOME }} ) }}
steps:
- name: Check environment
run: echo $MYVAR
Run Code Online (Sandbox Code Playgroud)
这会导致错误消息:
### ERRORED 10:45:52Z
- Your workflow file was invalid: The pipeline is not valid. .github/workflows/main.yml (Line: 10, Col: 14): Unexpected symbol: '${{'. Located at position 19 within expression: format('{0}:{1}', ${{ env.PATH
Run Code Online (Sandbox Code Playgroud)
此语法:
env:
MYVAR: ${{ format('{0}:{1}', {{ env.PATH }}, {{ env.HOME }} ) }}
Run Code Online (Sandbox Code Playgroud)
导致错误:
### …Run Code Online (Sandbox Code Playgroud) 我已按照此处的说明进行操作,但是当我运行时./svc.sh run,收到以下错误:
Could not find domain for port (Aqua)
Run Code Online (Sandbox Code Playgroud)
我正在通过 SSH 进入一个盒子来运行这个命令,当我不在无头会话中时它似乎工作正常,但我需要它是无头的并作为后台服务。还有人遇到这个吗?
我想在我的 Github Actions 工作流中缓存 Android NDK。原因是我需要特定版本的 NDK 和 CMake,它们没有预装在 MacOS 运行器上。
我尝试使用以下工作流作业来实现此目的:
jobs:
build:
runs-on: macos-latest
steps:
- name: Cache NDK
id: cache-primes
uses: actions/cache@v1
with:
path: ${{ env.ANDROID_NDK_HOME }}
key: ${{ runner.os }}-ndk-${{ hashFiles(env.ANDROID_NDK_HOME) }}
- name: Install NDK
run: echo "y" | $ANDROID_HOME/tools/bin/sdkmanager "ndk;21.0.6113669" "cmake;3.10.2.4988404"
Run Code Online (Sandbox Code Playgroud)
问题在于env上下文不包含ANDROID_NDK_HOME变量。所以这意味着build.steps.with.path评估为空。
如果我使用以下步骤进行调试,则存在常规环境变量并打印正确的路径:
jobs:
build:
steps:
- name: Debug print ANDROID_NDK_HOME
run: echo $ANDROID_NDK_HOME
Run Code Online (Sandbox Code Playgroud)
但是常规环境变量只能在shell脚本中使用,而build.steps.with据我所知不能使用。
这是我的 github 操作 yml 文件:
name: CI
on: [pull_request]
jobs:
build_ios:
name: Set up
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [self-hosted]
node-version: [10.x]
steps:
- name: Checkout github repo (+ download lfs dependencies)
uses: actions/checkout@v2
with:
lfs: true
Run Code Online (Sandbox Code Playgroud)
在它运行之后,我希望所有的 git lfs 文件都被下载、签出并准备好使用,但文件的内容是这样的:
version https://git-lfs.github.com/spec/v1
oid sha256:f23e4c2b1244bc93085dbccf17c447e54sca44650294648df128d58303e4eff
size 58951008
Run Code Online (Sandbox Code Playgroud)
下面我附上实际的 github 操作日志,以防万一:
Run actions/checkout@v2
with:
lfs: true
repository: SudoPlz/test-project-mobile
token: ***
ssh-strict: true
persist-credentials: true
clean: true
fetch-depth: 1
submodules: false
Syncing repository: SudoPlz/test-project-mobile
Getting Git version info
Working directory …Run Code Online (Sandbox Code Playgroud) 使用 Github 操作发布 npm 包,它可以正常工作并运行 jest 测试用例而不会出错。所以我决定添加 yarn 缓存来优化构建时间并且缓存过程有效,但是 jest 失败并出现以下错误。
$ jest --config=jest.config.js
/bin/sh: 1: jest: not found
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
##[error]Process completed with exit code 127.
Run Code Online (Sandbox Code Playgroud)
这是我的 yml
name: NPM Publish
on:
push:
branches:
- master
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12.x
- name: Get yarn cache directory
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)" …Run Code Online (Sandbox Code Playgroud) github-actions ×10
github ×6
git ×2
docker ×1
dockerfile ×1
git-lfs ×1
gitlab ×1
maven ×1
yarnpkg ×1