3
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?

.NET Frameworkアプリケーションのバージョン更新の手間を減らす

Last updated at Posted at 2025-12-21

対象とする読者

  • .NET Frameworkでアプリケーションを開発している人
  • ソースコード管理ツールとしてGitHubを使っている個人・組織

TL;DR

  • A successful Git branching modelのリリースブランチ作成作業を、GitHub Actionsのワークフローで担う
  • ブラウザ上でバージョン番号を入力しワークフローを手動実行すると、BOTがReleaseブランチの作成からPull Requestの作成までをおこなってくれる
  • バージョン更新時に複数個所を修正する手間が省け、更新漏れやタイポを防げる

ワークフロー

.github/workflows/update.yaml
name: Update Version Automation

on:
  workflow_dispatch:
    inputs:
      new_version:
        description: '新しいバージョンを入力してください (例: 1.0.0.0)'
        required: true

permissions:
  contents: write
  pull-requests: write

jobs:
  update-version:
    runs-on: ubuntu-slim
    timeout-minutes: 10
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v6
        with:
          fetch-depth: 0
      
      - name: Create Release Branch
        run: |
          git checkout -b Release-v${{ github.event.inputs.new_version }}
          git push origin Release-v${{ github.event.inputs.new_version }}

      - name: Update Version in Files
        run: |
          NEW_VERSION="${{ github.event.inputs.new_version }}"
          TARGET_FILES=(
            "MySolution/ConsoleApp1/Properties/AssemblyInfo.cs"
            "MySolution/ClassLibrary1/Properties/AssemblyInfo.cs"
          )
          for TARGET_FILE in "${TARGET_FILES[@]}"; do
            sed -i "s/\[assembly: AssemblyVersion(\".*\")\]/[assembly: AssemblyVersion(\"$NEW_VERSION\")]/g" "$TARGET_FILE"
            sed -i "s/\[assembly: AssemblyFileVersion(\".*\")\]/[assembly: AssemblyFileVersion(\"$NEW_VERSION\")]/g" "$TARGET_FILE"
          done

      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v8
        with:
          branch: Release-v${{ github.event.inputs.new_version }}
          title: 'Update version to v${{ github.event.inputs.new_version }}'
          body: 'This PR updates the version to v${{ github.event.inputs.new_version }}.'
          base: main

TARGET_FILESのパスはご自身のパスに変更してください。

使い方

  1. 組織アカウント(もしくはリポジトリ)の [Settings] > [Actions] > [General] > [Workflow permissions] にて、「Allow GitHub Actions to...」のチェックボックスをオンにします
    image.png
  2. ワークフローをデフォルトブランチおよびdevelopブランチにマージします
  3. ブラウザ上の [Actions] > [Update Version Automation] > [Run workflow] にて、Branch: develop に設定し、新しいバージョンを入力して「Run workflow」をクリックします
    image.png
  4. 自動でPull Requestが作成されるので、変更点をレビューします
    image.png
  5. リリース作業が完了したら、Pull Requestをmainブランチにマージします

ワークフローのトリガーであるworkflow_dispatchは、デフォルトブランチにワークフローが存在しないと使えません。
使い方で示したようにmainブランチとdevelopブランチの両方にワークフローをマージするか、developブランチのみにマージしてデフォルトブランチを一時的にdevelopに切り替えるか、いずれかの対処をおこなう必要があります。

参考

3
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
3
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?