Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get started with GitHub Actions #158

Open
soapgu opened this issue Aug 1, 2022 · 0 comments
Open

Get started with GitHub Actions #158

soapgu opened this issue Aug 1, 2022 · 0 comments
Labels
Demo Demo IDE Good for newcomers Research

Comments

@soapgu
Copy link
Owner

soapgu commented Aug 1, 2022

  • 前言

github一直以来都是用来issue写博客和存一些个人以及练习代码的基本功能。对一些其他功能没怎么玩。正好最近在学一些关于CI/CD的知识。正好玩玩看github的Actions的功能,一边试水一边记录,希望这篇日志不是一篇“翻车”日志
图片

  • 使用Actions生成windows桌面程序

首先找一个桌面程序的repository,进入到到Actions
图片
github很“智能”简易让我选".NET Desktop"

  • 然后出现了一个dotnet-desktop.yml的编辑界面

感觉和docker的配置文件有点像,看上去挺简洁的,但是显然还有一定的学习成本。
至少可以和怎么把大象放到冰箱里面类似。

  • 为了避免首发翻车,我们定一个小目标,Action能编译一个相关exe程序吧

说复杂也不复杂,所有的子步骤都是组件化,有一个专门的Marketplace,想要用就可以直接拿来用。

name: .NET Core Desktop

on:
  workflow_dispatch:

jobs:

  build:

    strategy:
      matrix:
        configuration: [Release]

    runs-on: windows-latest  # For a list of available runner types, refer to
                             # https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on

    env:
      Solution_Name: FocusStudy.sln                         # Replace with your solution name, i.e. MyWpfApp.sln.
      
    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 hosted by GitHub!"
    - name: Checkout
      uses: actions/checkout@v3
      with:
        fetch-depth: 0

    # Add  MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
    - name: Setup MSBuild
      uses: microsoft/[email protected]

    # Restore the application to populate the obj folder with RuntimeIdentifiers
    - name: Restore the application
      run: msbuild $env:Solution_Name /t:Restore /p:Configuration=$env:Configuration
      env:
        Configuration: ${{ matrix.configuration }}

    - name: Build solution
      run: msbuild $env:Solution_Name /t:Build /p:Configuration=$env:Configuration
      
    - name: Zip the Build
      run: zip -r release.zip /bin/$env:Configuration/
      
    - uses: actions/upload-artifact@v3
      with:
        name: build-artifact
        path: ./release.zip

过程就不表了

  1. 通过workflow_dispatch配置为手工触发工作量
  2. 检出最新代码
  3. 还原nuget包
  4. Build and Zip
  5. upload

完成后,Actions里面多了一个工作流,并且可以手工触发
图片

翻了两次车

  1. msbulid 命令行的/p:Configuration="Release",要加双引号
  2. zip命令在windows机器上不识别,找下资料要用Compress-Archive
  3. Compress-Archive也需要使用脱裤子放屁了,Upload a Build Artifact,这个action会自动zip的
  4. 微软做的界面真是好看,比jenkins好看多了……

图片

也没有太多的难度,把主要知识点梳理了下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Demo Demo IDE Good for newcomers Research
Projects
None yet
Development

No branches or pull requests

1 participant