GitLab CI から GitHub Actions への移行: ステップごとの手順
最終更新
GitLab CIからGitHub Actionsへの移行は、比較的直接的な置き換えになります。stagesはneedsに、rulesはonとifの組み合わせに、cacheとartifactsはactions/cacheとupload-artifactに、servicesはservicesに対応します。注意が必要な点は、includeとextends(再利用可能なワークフローとコンポジットアクションを使用します)、CI/CD変数(secretsはエクスポートされません)、そしてGitLab固有の機能である組み込みのコンテナレジストリやReview Appsです。
関連ページ:GitLab CIとGitHub Actionsの比較、GitLab CIの代替手段。
概念の対応関係
| GitLab CI | GitHub Actions |
|---|---|
.gitlab-ci.yml | .github/workflows/*.yml |
stages: | needs:によるジョブの順序制御 |
job: | jobs.<id> |
image: | ジョブにcontainer:を指定するか、setup-*アクションを使用します |
services: | services: |
script: | steps: - run: |
before_script: / after_script: | 前のステップ、またはif: always()を指定したステップ |
variables: | env: |
| プロジェクト / グループのCI/CD変数 | リポジトリ、Organization、または環境のsecretsとvariables |
rules: / only / except | on:によるトリガーとif:式 |
needs:(DAG) | needs: |
parallel: matrix | strategy.matrix |
cache: と key:files | actions/cache と hashFiles() |
artifacts: | actions/upload-artifact |
artifacts: reports: junit | テストレポーターアクション、またはアップロード |
dependencies:(アーティファクトの受け渡し) | actions/download-artifact |
extends: / include: / テンプレート | コンポジットアクション、再利用可能なワークフロー(workflow_call) |
environment: | environment: |
when: manual | 環境の必須レビュアー、またはworkflow_dispatch |
scheduleパイプライン | on.schedule。cronスケジュールをご覧ください |
| GitLab Runner (tags) | ランナーラベル |
| コンテナレジストリ | GitHub Packages(ghcr.io)または他のレジストリ |
$CI_COMMIT_SHA, $CI_COMMIT_BRANCH | ${{ github.sha }}, ${{ github.ref_name }} |
実際のパイプラインの比較
GitLab:
# .gitlab-ci.yml
stages: [build, test, deploy]
default:
image: python:3.13
cache:
key:
files: [poetry.lock]
paths: [.cache/pip]
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
build:
stage: build
script:
- pip install poetry
- poetry build
artifacts:
paths: [dist/]
expire_in: 1 week
test:
stage: test
parallel:
matrix:
- PYVER: ["3.12", "3.13"]
image: python:$PYVER
services:
- postgres:16
variables:
POSTGRES_PASSWORD: postgres
DATABASE_URL: postgres://postgres:postgres@postgres:5432/postgres
script:
- pip install -r requirements.txt
- pytest --junitxml=report.xml
artifacts:
when: always
reports:
junit: report.xml
deploy:
stage: deploy
script: ./scripts/deploy.sh
environment: production
rules:
- if: $CI_COMMIT_BRANCH == "main"
needs: [test]
GitHub Actions:
# .github/workflows/ci.yml
name: CI
on:
push:
branches: [main]
pull_request:
jobs:
build:
runs-on: ubuntu-latest # or [self-hosted, Linux, compiler-ci]
steps:
- uses: actions/checkout@v6
- run: pipx install poetry
- uses: actions/setup-python@v7
with:
python-version: "3.13"
cache: poetry
- run: poetry build
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
retention-days: 7
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python: ["3.12", "3.13"]
services:
postgres:
image: postgres:16
env:
POSTGRES_PASSWORD: postgres
ports: ["5432:5432"]
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 5s --health-retries 10
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python }}
cache: pip
- run: pip install -r requirements.txt
- run: pytest --junitxml=report.xml
- uses: actions/upload-artifact@v4
if: always()
with:
name: junit-${{ matrix.python }}
path: report.xml
deploy:
needs: [build, test]
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v6
- run: ./scripts/deploy.sh
注意すべき点:
- GitLabでは各ジョブが
image:内で実行されます。Actionsではジョブはランナー仮想マシン上で実行されるため、setup-*を使って必要な言語をインストールします。特定のイメージが必要な場合はcontainer:を使用します。 - サービス:GitLabではサービスのホストはイメージ名(
postgres)になります。Actionsでランナー上で実行するジョブの場合は、マップされたポートを指定したlocalhostになります。container:を使う場合は、サービスのキー名になります。ヘルスチェックの追加を推奨します。 cache: key: files: [poetry.lock]は、setup-python内のcache: poetryになります。poetry.lockのハッシュ値が使用されます。詳しくはPoetryのキャッシュ、pipのキャッシュ、および一般的なキャッシュのガイドをご覧ください。rules: if: $CI_COMMIT_BRANCH == "main"は、onトリガーとifの組み合わせになります。artifacts: reports: junitに直接対応する機能はありません。ファイルをアップロードするか、JUnitレポーターアクションを使用してください。
変数、secrets、環境
GitLab variables marked masked or protected become GitHub secrets. Protected variables, available only on protected branches, map to environment secrets with branch protection rules on the environment. You must copy values manually; there is no export of secret values. File-type variables become secrets you write to a file in a step. Predefined CI_ variables map to GitHub contexts (github., runner.*).
クラウドの認証情報については、保存されたキーの代わりにOIDCを使用します:AWSとGitHub Actions OIDC。さらなるセキュリティ強化については、GitHub Actionsのセキュリティ確保を参照してください。
Include、extends、テンプレート
GitLabのパイプラインでは、include:とextends:を通じてYAMLを共有することがよくあります。規模に応じて、Actionsの仕組みを選択してください:
- 共有するステップのまとまり:共有リポジトリにあるコンポジットアクション。
- 完全な共有ジョブやパイプライン:
on: workflow_callとinputs/secretsを使う再利用可能なワークフロー。 - 多くの上書きを伴うテンプレート:入力を持つ再利用可能なワークフロー、または生成されたYAMLによるアプローチ。
再利用可能なワークフローではextendsのすべてを実現できません(たとえば任意のキーのディープマージなど)。そのため、単純な変換ではなく、構成の見直しが必要になる点にご注意ください。
GitLabに含まれていて、GitHubにはない機能
- コンテナレジストリ:GitHub Packages(ghcr.io)または外部のレジストリをご利用ください。
- Review Appsと環境のダッシュボード:GitHubのEnvironmentsとデプロイメントで一部をカバーできます。プレビュー環境は独自に設定する必要があります。
- 組み込みのセキュリティスキャンテンプレート:GitHubにはコードスキャンとDependabotがあります。Dependabotのセットアップをご覧ください。
- マージトレイン:GitHubの同等機能はマージキューです。
- 子パイプラインと動的パイプライン:ワークフローの呼び出しとマトリックス戦略をご利用ください。
自動変換:GitHub Actions Importer
GitHubのImporterはghの拡張機能です。GitHubのドキュメント(2026年10月時点で確認)によると、GitLab(クラウドおよびセルフホスト)、Jenkins、CircleCI、Azure DevOps、Bamboo、Bitbucket Pipelines、Travis CIに対応しており、DockerとGitHub CLIが必要です。
gh extension install github/gh-actions-importer
gh actions-importer configure
gh actions-importer audit gitlab --output-dir audit --namespace my-group
ドキュメントに記載されているコマンドはaudit、forecast、dry-run、migrateです。auditで変換される内容の概要を確認し、forecastで過去のGitLabパイプライン履歴からActionsの分数を見積もり、dry-runでワークフローをローカルに書き出してください。GitLabの構成に必要なフラグは、GitHubのImporterのドキュメントで確認してください。出力は下書きとして扱ってください。特にinclude/extendsの構造は確認が必要です。
切り替え計画
- Importerで監査と見積もりを行います。
- 主要なテストパイプラインを移植し、ブランチで実行します。
- しばらく並行運用します:GitLab CIを動かし続け、結果を比較してください。この段階でコードをGitLabに置いたままにする場合、Actionsを使うにはリポジトリをGitHubに置く必要がある点にご注意ください。リポジトリの移行は独立した作業として計画してください。
- シークレット、環境、デプロイジョブを移行します。ステージング環境でテストしてください。
- ブランチ保護を更新し、GitHubのチェックを必須にします。
- GitLab CIを停止し、古い設定をアーカイブします。
移行後の高速化
GitLabの共有ランナーとGitHubのデフォルトの2 vCPUランナーではサイズが異なるため、判断する前に比較してください。GitHubの大型ランナーは料金が高くなります。GitHub Actionsの料金をご覧ください。compiler.devでは、runs-on: [self-hosted, Linux, compiler-ci]を通じて、同じワークフローを8 vCPU / 16 GBのマシンで1分あたり$0.008で実行できます。元のランナーへの自動フォールバックも対応しています。料金と高速ランナーをご覧ください。
よくある質問
GitLabからGitHubへリポジトリを移行する必要がありますか?
GitHub ActionsはGitHubでホストされているリポジトリで動作するため、はい、必要です。コードの移行をCIの移行と並行して計画してください。
GitLabのincludeとextendsはどのように置き換えればよいですか?
共通のステップにはコンポジットアクション、共通のジョブには再利用可能なワークフローを使います。
GitLab CIの変数は自動的に移行されますか?
いいえ。シークレットの値はエクスポートできないため、GitHubのシークレットとして再入力してください。
GitLabのステージ間でのアーティファクトの受け渡しは、何に置き換えればよいですか?
一方のジョブでupload-artifact、次のジョブでdownload-artifactを使い、needsを組み合わせます。
移行中に両方のCIシステムを実行できますか?
はい、ミラーまたは複製したリポジトリで実行できます。必須チェックを切り替える前に、結果を比較してください。
関連記事
- CircleCI から GitHub Actions への移行: ステップごとの手順概念の対応表、設定の並列比較、シークレット、キャッシュ、Importer、切り替え計画を使って、CircleCI から GitHub Actions へ移行します。
- JenkinsからGitHub Actionsへの移行: 手順ごとのガイドJenkinsfile の対応表、並べて見る変換、認証情報、キャッシュ、エージェント、Importer、切り替え計画を使って、Jenkins から GitHub Actions へ移行します。
- compiler.devのランナーで比較するGitLab CIとGitHub Actionscompiler.devのランナーでのGitLab CIとGitHub Actionsの比較:シート単位の料金、コンピュートの分数、オールインワンのDevOpsにおけるトレードオフ、.gitlab-ci.ymlの移行。
- 2026年のGitLab CIの代替ツール2026年のGitLab CIの代替ツールのベスト:GitHub Actions、CircleCI、Buildkite、Semaphore、Jenkins、compiler.devを、料金と移行の注意点とともに紹介します。