0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

GitHub Actionsで.NetCoreをshellを使ってコンパイルしてpushまでする

Last updated at Posted at 2021-03-20

概要

GitHub Actions上で.Net Coreのコンパイルをshellで行い、その後add、commit、pushをする

経緯

自社ツールを.Net CoreでWindowsで開発しており、Mac版とLinux版のコンパイルを行いたいが、WindowsでMac版とLinux版のコンパイルは正常なバイナリが出力されないため、Macでコンパイルをする必要がある
いちいちMacでコンパイルを行うのは面倒であるため、GitHub ActionsでMacとLinux版を作ってしまおうというお話

コンパイルした後に、特定のフォルダに実行ファイルを移動させたいのでそれらの処理をまとめてshellで行う
GitHubActionsにはpullして、shellを叩いて、commit、pushをしてほしい

環境

.Net Core 3.1.x
プロジェクト名:Wiener

コンパイル用のshell

shellファイルは.csprojと同一ディレクトリに配置
出力後にバイナリファイルを「Wiener/tools/wiener/mac/」へ移動させる
linux版は割愛

compile_mac.sh
# !/bin/bash

SRC_DLL_PATH="$(pwd)/bin/Release/netcoreapp3.1/osx-x64/publish/Wiener"
DST_DLL_PATH="$(pwd)/../../Wiener/tools/wiener/mac/"

dotnet publish -c Release -r osx-x64 /p:PublishSingleFile=true /p:PublishTrimmed=true

cp ${SRC_DLL_PATH} ${DST_DLL_PATH}

ActionsのYaml

dotnet.yml
name: build-mac-and-linux

on:
  push:
    branches: [ develop ]

jobs:
  build:

    runs-on: macos-latest

    steps:
    - uses: actions/checkout@v2
    - name: Setup .NET Core Install
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 3.1.x
    - name: Build
      run: cd Project/Wiener && sh compile_mac.sh && sh compile_linux.sh && cd ../../
    - name: Upload
      run: git commit -a -m "update binary mac and linux" && git push

ざっくり解説

name: build-mac-and-linux

名前、なんでもいい

on:
  push:
    branches: [ develop ]

developブランチに何かがpushされた時にアクションを実行する

    runs-on: macos-latest

最新のMacOSで実行する

    - uses: actions/checkout@v2

Actions環境にpullとかcheckoutとか色々初期化してくれる
とりあえず書いておけばOK

    - name: Setup .NET Core Install
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 3.1.x

Actions環境に.Net Core 3.1.xを構築してくれる

    - name: Build
      run: cd Project/Wiener && sh compile_mac.sh && sh compile_linux.sh && cd ../../

ディレクトリ移動して、mac版のshellを叩いて、linux版のshellを叩いて、ディレクトリ戻る!

    - name: Upload
      run: git commit -a -m "update binary mac and linux" && git push

更新されたファイルをcommitしてpush

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?