Skip to content

Automate Unity Package Releases Using GitHub Actions. GitHubアクションを使ってUnityパッケージのリリースを自動化

Notifications You must be signed in to change notification settings

IShix-g/Unity-GitHubActions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

4b7b9e1 · Mar 14, 2025
Mar 14, 2025
Jan 29, 2025
Mar 14, 2025
Mar 4, 2025
Mar 8, 2025
Feb 7, 2025
Mar 14, 2025
Jan 27, 2025
Mar 4, 2025

Repository files navigation

Test Create Release
Test Update package.json
Test Merge and Push
Test Release Notes Generator
Test Build Package
Test Unity Test
Test Unity C# Linter

README - 日本語版

Unity-GitHubActions

GitHub Actions for Unity.

Table of Contents

Details

Overview

This repository provides automation for Unity package releases using GitHub Actions.

This action automates the following tasks:

You can choose to execute only specific tasks you need.

Release Notes

When commit messages start with specific keywords like feat or fix, they will be automatically included in the release notes.

Available Commit Message Types

Type Description
feat: Add new features
fix: Fix bugs
docs: Update or fix documentation
style: Code style fixes (e.g., remove whitespaces)
refactor: Refactor without changing functionality
perf: Changes to improve performance

Required Settings

Set Read and write permissions for Settings > Actions > General > Workflow permissions.

Settings for Different Scenarios

When Branch Protection or Tag Protection is Enabled

By default, permission errors will occur. You need to configure GitHub Apps to bypass these protection rules.

  1. Create a GitHub App
  2. Install the app and configure it for your repository.
  3. Add BOT_APP_ID and BOT_PRIVATE_KEY to the repository's secrets.
  4. Update the app permissions so it can bypass protection rules.

For more details, refer to GitHubApp.md.

When Running Tests or Generating Packages

Unity needs to be executed in batch mode, which requires Unity account information.
Refer to Activation for the necessary details and configure them in your repository.
Tests and package generation utilize GameCI.

Required Secrets

Depending on your Unity license, either UNITY_LICENSE for Personal or UNITY_SERIAL for Pro is mandatory. Add these to the repository's secrets.

Name Description
UNITY_EMAIL Email address for Unity login
UNITY_PASSWORD Password for Unity login
UNITY_LICENSE Required for Personal license
UNITY_SERIAL Required for Pro license

Is Building Unity Packages Necessary?

Since Unity 2018, it has been possible to manage packages via the Package Manager (UPM), and now almost all supported Unity versions are compatible with UPM. Because of this, the traditional process of generating Unity packages has become largely unnecessary. As a result, the main workflow we provide does not include the release of Unity packages.

Manual Release

build-release_merge.yaml

Loading
graph LR
    validate-branch --> update-packagejson
    update-packagejson --> merge-and-push
    merge-and-push --> release-notes
    release-notes --> create-release
    create-release --> clean-branch

For manual releases:

  1. Navigate to the Actions tab.
  2. Select Manual Release (Merge to Default) > Run workflow.

Sample Workflow Execution

Option Description Default Example
tag Git tag to create N/A 1.0.0
clean-branch Whether to delete non-default branches false
fast-forward Whether to allow fast-forward merging false
include-default-branch Whether to include the default branch in the workflow false
dry-run Simulate without committing or pushing changes false
draft-release Set to true for a draft release, false for final false

Steps for Manual Release

  1. Create a new branch (e.g., release).
  2. Prepare the release in this branch.
  3. Trigger a manual release using Run workflow.

Setup Guide

  1. Copy the code from .github/workflows/build-release_merge.yaml to a new YAML file in your project's .github/workflows directory.
  2. Update the file-path in update-packagejson to match your project structure.
  3. If not using branch protection rules, remove references to secrets.BOT_APP_ID and secrets.BOT_PRIVATE_KEY.

Note: In case of permission errors during execution, configure proper permissions.

Release Through Pull Requests

build-release_pull-request.yaml

Loading
graph LR
    extract-tag --> update-packagejson
    update-packagejson --> release-notes
    release-notes --> create-release

Create a pull request from any branch to the default branch. Ensure the release title matches the tag name (e.g., 1.0.0). The release will be created automatically after merging the pull request.

Sample Execution

Releases are created automatically post-merge.

Release Creation Conditions

A release will be created if:

  • The pull request title includes a version number (e.g., 1.0.0).
  • The base branch is the default branch.

Steps for PR-Based Release

  1. Create a branch (e.g., release).
  2. Prepare the release in this branch.
  3. Create a pull request from this branch to the default branch with the title set to the version (e.g., v1.0.0).
  4. Merge the pull request.
  5. The release will be generated automatically.

Setup Guide

  1. Copy the code from .github/workflows/build-release_pull-request.yaml to a YAML file in your .github/workflows directory.
  2. Update the file-path in update-packagejson to match your project structure.
  3. If not using branch protection rules, remove references to secrets.BOT_APP_ID and secrets.BOT_PRIVATE_KEY.

Recommendations

Even if you primarily use the pull-request-based release method, it is recommended to configure manual release as a fallback.

Adding Unity Test Framework (formerly Test Runner)

Execute tests within Unity Editor. Configuration is required to use this feature. Please refer to the Setup section.

About Tests

Tests are executed using GameCI's Test Runner.
There’s no need to specify individual tests; it will automatically run Edit Tests and/or Play Tests created in UnityEditor.

Workflow Examples

Please refer to build-release_merge_test.yaml as an example implementation.

Adding to Existing Workflow

  • Add checks: write to permissions
  • Add a unity-test job
  • Specify the Unity Editor version in unity-version (e.g., 2021.3.45f1)

Supported Unity Editor versions can be checked here.

Specifying Test Mode

By default, both Edit Mode and Play Mode tests are executed.
If you want to run only specific modes, specify the test-modes parameter. Valid parameters can be found in Game CI - testMode.
To specify multiple modes, separate them with commas.

Code Example (Default Setting)

test-modes: 'playmode,editmode'

Sample Execution Result

You can view the list of executed tests.
Sample Execution Result

Unity - Code Coverage will be included in the artifacts.

Adding Package Generation

Refer to build-release_merge_package.yaml for implementation details. Configuration is required, as explained in the Setup section.
This process allows you to:

  • Generate packages (UPM package)
  • Attach the generated package to the assets section of the release page

About Package Generation

The package generation uses GameCI's Builder.

[Note] Environments That Cannot Generate Packages

Packages cannot be generated if the package path is outside the Assets folder in Unity Editor.

Path Examples

  • [Works] Assets/MyPackage/
  • [Fails] Packages/MyPackage/

Adding to Existing Workflow

  • Add a build-package job
  • Specify the package name without the extension in package-name (e.g., TestPackage)
  • Specify the Unity Editor version in unity-version (e.g., 2021.3.45f1)
  • Add a release-package-upload job

Supported Unity Editor versions can be checked here.

Required Unity Editor Settings

A script for generating packages is required. Please use the provided PackageExporter.

Sample Execution Result

The built package will appear in the release.
Sample Execution Result

PackageExporter

This script generates packages. It is lightweight and only functional in the Editor, with no additions to build outputs.

Installation

Install it using one of the following methods:

[Recommended] Package Manager

Open Unity Editor, and go to "Window > Package Manager > Add package from git URL...". Enter the following URL to install:

URL: https://github.com/IShix-g/Unity-GitHubActions.git?path=Assets/PackageExporter

Download the Package

Download the package from the Assets section of the release page as PackageExporter_xxx.unitypackage, and install it.

[Required] Running Export Tests

  • Open "Window > Test Export Package" in Unity Editor
  • Enter the necessary information and run the export
  • If no errors appear in the console and the path of the exported package is displayed, the process is successful

Install the exported package in a test project to verify its functionality.

C# Style Check

What is a Style Check?

In many teams, there are specific coding conventions such as:

  • Private fields should be named using _myField style (_ + camelCase)
  • if statements must always use {} braces
  • Indentation should use spaces instead of tabs

A style check enforces these rules automatically when a pull request is opened or a manual trigger is executed, reducing the burden on reviewers.

Style Check in Pull Requests

lint-unity-cs-pull-request.yaml

Example Execution

If there are style issues, the action will fail, and the pull request will display comments highlighting the problems.

Target of Style Checks

The style check runs on newly committed or modified .cs files in the pull request.

Workflow of Style Check

  1. A pull request is created.
  2. The style check runs automatically when the pull request is created.
  3. (If issues are found) Fix the issues and commit, triggering another style check.

Setup Guide

  1. Copy the code from lint-unity-cs-pull-request.yaml and create a YAML file in the .github/workflows folder of your project.
  2. Specify the branch for style checks under branches (e.g., 'main').
  3. Specify the target paths under paths (e.g., Assets/**). Multiple paths can be specified.
  4. (Optional) Configure style check targets with include-paths using regular expressions, separated by , (e.g., Assets/.*).
  5. (Optional) Exclude paths from style checks with exclude-paths.
  6. Create a style rule configuration file. Refer to this example to create an .editorconfig.

Manual Execution for Style Check

lint-unity-cs-dispatch.yaml

Example Execution

See the execution example at:
https://github.com/IShix-g/Unity-GitHubActions/actions/runs/13626333298

Target of Style Checks

The style check runs on all specified .cs files.

Workflow of Style Check

Click the Run workflow button to execute the style check.

Setup Guide

  1. Copy the code from lint-unity-cs-dispatch.yaml and create a YAML file in the .github/workflows folder of your project.
  2. (Optional) Configure style check targets with include-paths using regular expressions, separated by , (e.g., Assets/.*).
  3. (Optional) Exclude paths from style checks with exclude-paths.
  4. Create a style rule configuration file. Refer to this example to create an .editorconfig.

Job Descriptions

Main Job Descriptions.

Validate Tag

.github/workflows/reusable-validate-tag.yaml

This action checks if the tag format is valid and returns outputs.normalized-tag, a normalized version of the tag with only numeric values.

Inputs

id description default
require-validation true to disallow old or invalid tags. false to proceed even if validation fails. true
validate-semantic-versioning Specifies whether to validate the tag format using Semantic Versioning. true
tag The tag to validate (e.g., 1.0.0).

Outputs

id description
normalized-tag Normalized tag (e.g., tag without the v prefix).
tag Same as the input tag.
validated Indicates whether the tag passed validation.

Update package.json

.github/workflows/reusable-update-packagejson.yaml

This action updates the version in package.json and commits the changes.

Inputs

id description default
file-path Path to the package.json file to update. You can provide multiline paths. Only package.json files are supported.
tag The Git tag to assign (e.g., 1.0.0).
dry-run true to simulate the update and commit without actual changes being pushed.
require-validation true requires tag validation to pass, false allows proceeding even if it fails. true
ref The branch or tag to check out before updating.
commit-message-format Template for the commit message when updating package.json. Example: Update package.json to {v}. Update package.json to {v}

Secrets

For branch or tag protection:

id description
BOT_APP_ID Specify the application ID
BOT_PRIVATE_KEY Set the private key for the app

Outputs

id description
normalized-tag Normalized tag (tag without the v prefix).
sha Git commit SHA after the package.json update.
changed Indicates if the Git branch was modified or created.

Merge and Push

.github/workflows/reusable-merge-and-push.yaml

This action merges branches and pushes the changes.

Inputs

id description default
target-branch The target branch from the repository to merge.
push-branch The branch to push the changes into.
commit-id Commit ID for creating a release and tag.
dry-run Enables dry-run mode (simulate without committing). false
fast-forward Allows a fast-forward merge. false

Secrets

For branch or tag protection:

id description
BOT_APP_ID Specify the application ID
BOT_PRIVATE_KEY Set the private key for the app

Outputs

id description
sha Git commit SHA after the merge.
merged Indicates if the branches were successfully merged.

Release Notes Generator

.github/workflows/reusable-release-notes.yaml

This action generates release notes based on commit messages. Messages beginning with fix: or feat: will be included in the release notes.

Inputs

id description default
from-tag The starting tag (default: first commit if unset).
to-tag The ending tag (default: latest commit if unset).
commit-message-format Format for commit messages (see https://git-scm.com/docs/pretty-formats for details). - %s (%h)
commit-id Commit ID for release and tag.
derive-from-tag true to auto-determine from-tag using previous tags; false to configure manually. true

Outputs

id description
notes The generated release notes.

Create Release

.github/workflows/reusable-create-release.yaml

This action creates a release and optionally adds a tag.

Inputs

id description default
commit-id Commit ID for creating the release and tag.
dry-run true to perform a dry run (does not create the release).
require-validation true enforces validation; false skips validation and proceeds. true
wait-before-delete The wait time (in seconds) before deleting temporary branches. 25
tag The Git tag to create (e.g., 1.0.0).
release-format Template for the release title. E.g., Ver.{0} will title the release as Ver.1.0.0. {0} omits prefixes. Ver.{0}
release-note Custom release notes to include.
draft-release true for a draft release; false for a final release. false

Secrets

For branch or tag protection:

id description
BOT_APP_ID Specify the application ID
BOT_PRIVATE_KEY Set the private key for the app

Running Unity Tests (Unity Test Framework)

.github/workflows/reusable-unity-test.yaml

About This Workflow

  • Executes either Edit Tests, Play Tests, or both using Unity Editor
  • Test results can be viewed under the Sample Execution Result
  • Requires setup to be completed

※ This workflow uses GameCI's Test Runner to execute tests.

Inputs

ID Description Default Value
unity-version Specifies the Unity version. If set to auto, the project's Unity version is used auto
project-path Specifies the path to the Unity project
test-modes Specifies which tests to run playmode,editmode
coverage-options Sets options for code coverage generateAdditionalMetrics;generateHtmlReport;generateBadgeReport

Check supported Unity versions here.

Secrets

The following secrets are required to execute Unity Editor in batch mode:

ID Description
UNITY_EMAIL Email address to log in to Unity
UNITY_PASSWORD Password to log in to Unity
UNITY_LICENSE Required if using a Personal license
UNITY_SERIAL Required if using a Pro license

For more details, please refer to the setup section.


Generating a Package (Build Package)

.github/workflows/reusable-build-package.yaml

  • Executes the package build
  • Packages must be located under the Assets directory
  • Requires the installation of PackageExporter
  • Requires setup to be completed

※ This workflow uses GameCI's Builder to generate packages.

Inputs

ID Description Default Value
tag The Git tag to apply (e.g., 1.0.0)
package-name Specifies the package name without the extension (e.g., TestPackage)
commit-id Commit ID for creating releases or tags
unity-version Specifies the Unity version. If set to auto, the project's Unity version is used auto
project-path Specifies the path to the Unity project
build-method Name of the script method to build the package, including the namespace PackageExporter.Editor.CLIBuilder.Build
retention-days Specifies how long the artifact is retained 0

Check supported Unity versions here.
If uploading generated packages to the release page, setting retention-days to 1 day is sufficient.

Outputs

ID Description
package-name The specified package name
export-path Output path of the generated package
artifact-url Download URL of the generated package
package-hash SHA-256 hash of the generated package

export-path is for verification purposes. Due to GitHub Actions' limitations, it will be deleted after the workflow is completed.

Secrets

The following secrets are required to execute Unity Editor in batch mode:

ID Description
UNITY_EMAIL Email address to log in to Unity
UNITY_PASSWORD Password to log in to Unity
UNITY_LICENSE Required if using a Personal license
UNITY_SERIAL Required if using a Pro license

For more details, please refer to the setup section.


Uploading a Package to Release

.github/workflows/reusable-release-package-upload.yaml

This action uploads a package to the release page.

Inputs

ID Description Default Value
release-tag Tag of the release to upload the package to (e.g., 1.0.0)
artifact-package-name Name of the uploaded artifact package (e.g., TestPackage_1.0.0.unitypackage)
package-hash SHA-256 hash of the target package
dry-run Set to true if only testing; no upload will occur false
Generating the SHA-256 Hash

If generating the SHA-256 hash yourself, follow the example below:
Note that the artifact-digest produced during artifact upload is also a SHA-256 hash but cannot be reused here.

hash=$(sha256sum "$package_path" | awk '{ print $1 }')

Style Checking for C# Files (Lint C# Files for Unity)

reusable-lint-cs-files.yaml

This action performs style checks on the specified C# files.

Open Source Software (OSS) Used

  • dotnet format: Used for performing style checks.
  • StyleCop.Analyzers: Used for enforcing style guidelines during checks.
  • reviewdog: Used for posting messages to pull requests and other reporting purposes.

Input Parameters (Inputs)

ID Description Default Value
ref Specifies the branch or commit ID to use. Default branch is used if unspecified.
editorconfig-branch Specifies the branch where the .editorconfig file is located. Uses ref if unspecified.
files Specifies the target files in the Assets directory, separated by commas.
review-reporter Specifies the reviewdog reporter. github-pr-review
review-level Specifies the reviewdog level. warning
review-exit-code Specifies the reviewdog exit code. error

About GitHub Actions Usage Fees

When using GitHub Actions in a private repository, usage fees apply. For public repositories, it remains free.
While fees are incurred, there is a free usage allowance available. You can check the details via Billing and plans > Plans and usage > Usage this month.

Referenced Repository

This repository served as a reference or inspiration for the workflows and configurations described above.

https://github.com/Cysharp/Actions

About

Automate Unity Package Releases Using GitHub Actions. GitHubアクションを使ってUnityパッケージのリリースを自動化

Topics

Resources

Stars

Watchers

Forks

Languages