【devops】Github Actions Secrets | 如何在Github中设置CI的Secret供CI的yaml使用

一、Github Actions

1、ci.yml

yaml 复制代码
name: CI

on: [ push ]


jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Set up Go
        uses: actions/setup-go@v4
        with:
          go-version: 1.23.0

      - name: Cache Go modules
        uses: actions/cache@v3
        with:
          path: |
            ~/.cache/go-build
            ~/go/pkg/mod
          key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
          restore-keys: |
            ${{ runner.os }}-go-

      - name: Build Go project
        run: |
          go env -w CGO_ENABLED=0
          go env -w GOPROXY=https://goproxy.cn,direct
          go env -w GOPRIVATE=github.com
          go mod tidy
          go build -trimpath -ldflags "-s -w" -o core_api api/core.go
          go build -trimpath -ldflags "-s -w" -o core_rpc rpc/core.go

      - name: Verify core_api exists
        run: |
          if [ ! -f core_api ]; then
            echo "core_api file not found!"
            exit 1
          fi
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2

      - name: Log in to Alibaba Cloud ACR
        env:
          ACR_REGISTRY: ${{ secrets.ACR_REGISTRY }}
          ACR_USERNAME: ${{ secrets.ACR_USERNAME }}
          ACR_PASSWORD: ${{ secrets.ACR_PASSWORD }}
        run: echo $ACR_PASSWORD | docker login $ACR_REGISTRY -u $ACR_USERNAME --password-stdin

      - name: Build and push Docker image - API
        env:
          ACR_REGISTRY: ${{ secrets.ACR_REGISTRY }}
        run: |
          docker build -t $ACR_REGISTRY/【你的acr地址】:latest -f Dockerfile-api .
          docker push $ACR_REGISTRY/【你的acr地址】:latest

      - name: Build and push Docker image - RPC
        env:
          ACR_REGISTRY: ${{ secrets.ACR_REGISTRY }}
        run: |
          docker build -t $ACR_REGISTRY/【你的acr地址】:latest -f Dockerfile-rpc .
          docker push $ACR_REGISTRY/【你的acr地址】:latest

2、添加 Secrets

这里有一个tabs,即:【Secrets】、【Variables】

我们需要根据 ci.yml中设置的进行对应的选择

我们需要根据 ci.yml 中的变量名进行赋值

相关推荐
张洛闻Eren12 分钟前
Ansible【第一课】:Ansible介绍
运维·数据库·云原生·kubernetes·github·ansible
成为你的宁宁34 分钟前
【Gitlab测试项目】
gitlab·devops
miofly43 分钟前
Meta 发布 Muse Wonder 系列模型,长上下文智能体任务表现接近主流竞品
开源·github
高频因子挖掘机1 小时前
股票分红送转后价格“断层”:前复权、后复权和不复权该怎么选?
后端·github·api
解道Jdon2 小时前
FigCraft把Figma用Rust从零重写了一遍
ide·windows·git·svn·eclipse·github·visual studio
u1301302 小时前
GitHub 热榜项目:日榜(2026-10-13)
人工智能·github
答案answer3 小时前
不用写一行Three.js代码,也能搭出复杂数字孪生场景
github·three.js
deepseek233 小时前
Dependabot匿名私有仓库开放后仍更新失败?组织级镜像的访问边界与排查实战
python·github·devops·软件供应链·dependabot
2023自学中3 小时前
github , ubuntu 虚拟机 push file config
linux·ubuntu·github
来自于狂人4 小时前
GitHub 开源热榜日报 · 2026年10月13日
开源·github