.net core github action ci/cd配置模板

前言

体验了一下github的ci/cd 感觉挺好用的,下面是两种在用的模板可以参考

.net core nuget 自动发布

name: Narojay.Tools.Core
 
on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]
 
jobs:
  build:
 
    runs-on: ubuntu-latest
 
    steps:
    - uses: actions/checkout@v2
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 5.0.x
    - name: Install dependencies
      run: dotnet restore
    - name: Build
      run: dotnet build --configuration Release --no-restore
    - name: Publish
      uses: brandedoutcast/publish-nuget@v2.5.2
      with:
       PROJECT_FILE_PATH: ./Narojay.Tools.Core.csproj
       NUGET_KEY: ${{secrets.NUGET_KEY}}

.net core web项目自动打包docker镜像

name: narojay.blog
on: 
 push:
  branches: [master]
 pull_request:
  branches: [master]
env:
    IMAGE_NAME: narojay/narojay.blog.api
    IMAGE_TAG: demo
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
     - uses: actions/checkout@v2
     - name: Setup .NET Core
       uses: actions/setup-dotnet@v1
       with:
        dotnet-version: 5.0.x
     - name: dotnet restore #还原包
       run: dotnet restore Narojay.Blog
     - name: dotnet publish #发布项目
       run: dotnet publish Narojay.Blog --configuration -c Release --no-restore -o app  
     - name: Run Crrpath
       run: ls 
     - name: Copy Dockerfile  # 拷贝Dockerfile到发布目录 ##生成随机数 echo "$RANDOM"|md5sum|cut -c 5-15
       run: cp ./Dockerfile ./app
     - name: Login to Docker Hub
       uses: docker/login-action@v1
       with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
     - name: Build Docker Image # Build Docker镜像并推送到镜像仓库
       uses: docker/build-push-action@v2
       with:
            tags: ${{env.IMAGE_NAME}}:${{env.IMAGE_TAG}}.${{ github.run_id }}.${{ github.run_number }} #动态变量镜像TAG 使用github运行job和jobid设置tag
            context: ./app
            file: ./app/Dockerfile # 指定Dockerfile
            push: true

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值