我有一个 GitHub 操作,正在运行 Web 应用程序的单元测试。我通过此操作运行 CodeClimate 测试报告。
CodeClimate 需要设置两个环境变量才能正确发送报告。这些都是;
GitHub actions 使 git commit sha 可通过 github 上下文使用,github.sha这样我就可以在该操作上设置一个环境变量,如下所示;
env:
GIT_SHA: ${{ github.sha }}
Run Code Online (Sandbox Code Playgroud)
但是 github actions 并不使分支名称可用。
它确实提供了一个名为 this is the full ref 的默认环境变量GITHUB_REF,但我知道我可以使用此简写语法获取短引用,即分支名称$GITHUB_REF##*/
我遇到的问题是我无法使用此值设置名为 GITHUB_BRANCH 的环境变量$GITHUB_REF##*/
有谁知道我如何获取分支名称并将其设置为环境变量,GIT_BRANCH以便 CodeClimate 测试脚本能够使用它。
最终我希望我的环境配置如下所示:
env:
GIT_SHA: <git commit sha>
GIT_BRANCH: <current git branch>
Run Code Online (Sandbox Code Playgroud) 项目设置如下:
两者都是用maven构建的。项目 B 将其包发布到其自己存储库的 github 包注册表中。项目 A 在 pom.xml 中依赖于项目 B 的工件,如下所示:
<dependency>
<groupId>com.company</groupId>
<artifactId>library-project-b</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
项目 A 还包括对项目 B 的包注册表的以下存储库引用:
<repository>
<id>github-library-project-b</id>
<name>Project B Github packages repositories</name>
<url>https://maven.pkg.github.com/organization/library-project-b</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
Run Code Online (Sandbox Code Playgroud)
为了对项目 B 的包注册表进行身份验证,项目 A 还包含一个 settings.xml,其中包含通过环境变量设置的凭据,这些环境变量是通过 Github 操作的机密提供的:
<server>
<id>github-library-project-b</id>
<username>${env.USER_PACKAGE_READ}</username>
<password>${env.TOKEN_PACKAGE_READ}</password>
</server>
Run Code Online (Sandbox Code Playgroud)
在 github actions 中的持续集成工作流程中,我执行以下步骤,将项目 B 的注册表访问存储库中的秘密映射到 settings.xml 中使用的环境变量,并通过 mvn 命令启动构建:
- name: Build Package
env:
USER_PACKAGE_READ: ${{ secrets.USER_PACKAGE_READ }}
TOKEN_PACKAGE_READ: ${{ secrets.TOKEN_PACKAGE_READ …Run Code Online (Sandbox Code Playgroud) 您好,我是 github actions 的新手,我正在尝试使用 Github action 创建 CICD pipline。我正在使用数字海洋水滴作为我的服务器,并且我正在尝试创建一个跑步者,如 github->settings->actions 中所述
当我写下以下命令时
./config.sh --url https://github.com/basobaasnepal/BasobaasWeb --token DFGFSDF234sf3fg45hd
我得到了这个: 不能使用 sudo 运行
我尝试将 root 用户更改为非 root 用户,但没有成功。我也尝试export {AGENT_ALLOW_RUNASROOT="1"}过
我正在尝试使用 github 操作将静态站点部署到 AWS S3 和 Cloudfront。我的 Github Action 代码是:
name: deploy-container
on:
push:
branches:
- master
paths:
- 'packages/container/**'
defaults:
run:
working-directory: packages/container
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: npm install
- run: npm run build
- uses: chrislennon/action-aws-cli@v1.1
- run: aws s3 sync dist s3://${{secrets.AWS_S3_BUCKET_NAME}}/container/latest
env:
AWS_ACCESS_KEY_ID: ${{secrets.AWS_ACCESS_KEY_ID}}
AWS_SECRET_ACCESS_KEY: ${{secrets.AWS_SECRET_ACCESS_KEY}}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试构建时出现了这些错误
amazon-s3 amazon-web-services amazon-cloudfront webpack github-actions
我正在使用 GitHub Actions 和安装在 Windows 2019 服务器上的自托管代理来设置 CI/CD 管道。
我面临的问题是操作 actions/checkout@v2 无法签出存储库并完全解压缩它。当我说“完全解压”时,我的意思是目标文件夹中有一些文件,它在停止之前设法解压。
从日志中:
Run actions/checkout@v2
Syncing repository: Syd/ExternWebb
Getting Git version info
Deleting the contents of 'C:\actions-runner\_work\ExternWebb\ExternWebb'
The repository will be downloaded using the GitHub REST API
To create a local Git repository instead, add Git 2.18 or higher to the PATH
Downloading the archive
Writing archive to disk
Extracting the archive
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command "$ErrorActionPreference = 'Stop' ; try { Add-Type -AssemblyName System.IO.Compression.FileSystem } …Run Code Online (Sandbox Code Playgroud) 我使用https://start.spring.io/创建了一个简单的 Spring Boot 应用程序。现在我想使用 Paketo.io / Cloud Native Build Pack 支持来spring-boot-maven-plugin构建容器映像,并使用 GitHub Actions 将其推送到 GitHub 容器注册表。
我的pom.xml看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>io.jonashackt</groupId>
<artifactId>helloworld</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>helloworld</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>15</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
mvn spring-boot:build-image我成功地使用GitHub Actions …
buildpack spring-boot spring-boot-maven-plugin github-actions github-package-registry
我只是在尝试 GitHub 操作,并且有以下工作流程。
feature/ticketno)上创建 PR 时,我想针对新创建的 PR 分支运行一些测试。我发现的一个解决方案是在操作步骤中添加 if 条件,以避免针对 PR 上的所需分支(即 master、staging)运行测试。
但不确定这是正确的方法,我正在寻找合适的解决方案
我正在尝试开发一个 Github Action,以在上传到 FTP 服务器之前更新我的(大部分)php 文件中的版本号和数据库凭据。
在我的主分支内,我有一个名为VERSION.mdcontent 的文本文件2.0.1。
该操作应该在每次推送提交时运行。
在部署到 FTP 服务器之前,需要进行这些替换(当然,不应更改真正的存储库文件,只更改上传到服务器的文件)。
__VERSION__应替换为我的文件的内容VERSION.md。db_connection.php,应将字符串__DB-PASSWORD__替换为相应的密钥DB_PASSWORD。这是我当前的工作流程:
on: push
name: FTP Deploy
jobs:
web-deploy:
name: Ubuntu VM
runs-on: ubuntu-latest
steps:
- name: Getting latest Code
uses: actions/checkout@v2.3.2
# at this position I tried the string replacing
- name: Sync Files
uses: SamKirkland/FTP-Deploy-Action@4.0.0
with:
server: ${{ secrets.ftp_server }}
username: ${{ secrets.ftp_username }}
password: ${{ secrets.ftp_password }}
server-dir: "public_html/" …Run Code Online (Sandbox Code Playgroud) 我使用自托管运行程序而不是 Github 运行程序来执行 Github 操作,因为自托管运行程序将有权访问专用网络。我还将在自托管运行器之上使用容器。
从链接 https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners
可以将 设定runs-on为ubuntu-latest。我认为这与https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-README.mddocker pull ubuntu中预装的软件是相同的图像
ubuntu-latest但 docker hub 上的 ubuntu 镜像与Github 托管运行器使用的镜像不同。在哪里可以找到 Github runner 使用的 docker 镜像?
配置自托管运行器并安装 docker 引擎后,我尝试了下面的工作流程。然而它失败了,没有图像ubuntu-latest
jobs:
build:
runs-on: self-hosted
container:
image: ubuntu-latest
steps:
- run: echo " The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo " This job is now running on a ${{ runner.os }} server !"
Run Code Online (Sandbox Code Playgroud) 我有一个 React 本机应用程序。我正在准备通过 github-actions 将 Android 持续部署到 Google Play 商店。
我正在使用这个库来签署应用程序:https ://github.com/r0adkll/sign-android-release
我有以下用于发布的 github-action 的 yaml 配置文件:
on: workflow_dispatch
name: Release to Google Play Store
jobs:
beta-distribution:
runs-on: ubuntu-latest
name: Beta Distribution
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/setup-node@master
- uses: c-hive/gha-yarn-cache@v1
- name: Install node modules
run: |
yarn install
- name: Cache Gradle Wrapper
uses: actions/cache@v2
with:
path: ~/.gradle/wrapper
key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}
- name: Cache Gradle Dependencies
uses: actions/cache@v2
with:
path: ~/.gradle/caches …Run Code Online (Sandbox Code Playgroud) github-actions ×10
git ×2
github ×2
github-actions-self-hosted-runners ×2
amazon-s3 ×1
android ×1
buildpack ×1
checkout ×1
devops ×1
docker ×1
git-workflow ×1
google-play ×1
java ×1
maven ×1
pipeline ×1
react-native ×1
spring-boot ×1
version ×1
webpack ×1
yaml ×1