前言
体验了一下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

385

被折叠的 条评论
为什么被折叠?



