1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

GitHub ActionsでiOSアプリのバージョンアップを自動化する方法

Posted at

概要

iOSアプリのバージョン管理を効率化するために、GitHub Actionsを活用して手動でバージョンを更新するワークフローを構築する方法を紹介します。このワークフローは、patchminormajorのいずれかのバージョンアップを選択し、プロジェクトファイルを自動的に更新します。

前提条件

  • GitHubリポジトリが存在すること
  • .pbxprojファイルを持つiOSプロジェクトであること

ワークフローの設定手順

以下の手順に従って、GitHub Actionsのワークフローを設定します。

1. ワークフローファイルの作成

リポジトリの.github/workflowsディレクトリにversionup.ymlという名前のファイルを作成します。以下のコードをそのファイルに追加します。

.github/workflows/versionup.yml
# versionup.yml
name: Manual Version up

on:
  workflow_dispatch:
    inputs:
      update_type:
        description: 'バージョンアップの種類を選択'
        type: choice
        required: true
        options:
          - patch
          - minor
          - major
        default: 'patch'

permissions:
  contents: write

jobs:
  versionup:
    runs-on: macos-latest
    steps:
    - uses: actions/checkout@v4
      with:
        token: ${{ secrets.GITHUB_TOKEN }}
        fetch-depth: 0
    
    - name: Get Current Version
      id: current_version
      run: |
        CURRENT_VERSION=$(grep -m 1 'MARKETING_VERSION = ' $(find . -name "*.pbxproj") | grep -o '[0-9]*\.[0-9]*\.[0-9]*')
        
        MAJOR=$(echo $CURRENT_VERSION | cut -d. -f1)
        MINOR=$(echo $CURRENT_VERSION | cut -d. -f2)
        PATCH=$(echo $CURRENT_VERSION | cut -d. -f3)
        
        case "${{ github.event.inputs.update_type }}" in
          major)
            NEW_VERSION="$((MAJOR + 1)).0.0"
            ;;
          minor)
            NEW_VERSION="${MAJOR}.$((MINOR + 1)).0"
            ;;
          patch)
            NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))"
            ;;
        esac
        echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT

    - name: Update App Version
      run: |
        find . -name "*.pbxproj" -exec sed -i '' "s/MARKETING_VERSION = .*;/MARKETING_VERSION = ${{ steps.current_version.outputs.new_version }};/g" {} \;
        CURRENT_VERSION=$(grep -m 1 'CURRENT_PROJECT_VERSION =' $(find . -name "*.pbxproj") | head -n 1 | grep -o '[0-9]*')
        NEW_PROJECT_VERSION=$((CURRENT_VERSION + 1))
        find . -name "*.pbxproj" -exec sed -i '' 's/CURRENT_PROJECT_VERSION = [0-9]*;/CURRENT_PROJECT_VERSION = '"$NEW_PROJECT_VERSION"';/g' {} \;

    - name: Commit and Push Changes
      run: |
        git config --global user.name "github-actions[bot]"
        git config --global user.email "github-actions[bot]@users.noreply.github.com"
        git fetch -p
        NEW_VERSION="${{ steps.current_version.outputs.new_version }}"
        BRANCH_NAME="release/${NEW_VERSION}"
        git checkout -b $BRANCH_NAME
        git add .
        git commit -m "バージョン番号を${NEW_VERSION}に更新"
        git push origin HEAD

2. ワークフローの実行

GitHubリポジトリの「Actions」タブから、このワークフローを手動で実行できます。実行時に、patchminormajorのいずれかを選択してバージョンを更新します。

注意点

  • GITHUB_TOKENはGitHubが自動的に提供するトークンで、リポジトリへの書き込み権限を持っています。
  • macos-latestを使用していますが、必要に応じて他のランナーに変更可能です。

このワークフローを使用することで、手動でバージョンを管理する手間を省き、効率的にiOSアプリのバージョンを更新できます。これにより、開発プロセスの一部を自動化し、より重要なタスクに集中することが可能になります。

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?