A example project of exporting a package using Unity and GitHub Actions.
Create UnityPackageExporter.cs
under the Editor
folder in the project repository, and write the following.
(The package name and other constants should match your project)
using System.IO;
using UnityEditor;
namespace ExportPackageExample.Editor {
public static class UnityPackageExporter {
// The name of the unitypackage to output.
const string k_PackageName = "ExportPackageExample";
// The path to the package under the `Assets/` folder.
const string k_PackagePath = "ExportPackageExample";
// Path to export to.
const string k_ExportPath = "Build";
public static void Export () {
ExportPackage($"{k_ExportPath}/{k_PackageName}.unitypackage");
}
public static string ExportPackage (string exportPath) {
// Ensure export path.
var dir = new FileInfo(exportPath).Directory;
if (dir != null && !dir.Exists) {
dir.Create();
}
// Export
AssetDatabase.ExportPackage(
$"Assets/{k_PackagePath}",
exportPath,
ExportPackageOptions.Recurse
);
return Path.GetFullPath(exportPath);
}
}
}
This is a fairly concise code, so if you want to customize the package in more detail, please refer to the official documentation. https://docs.unity3d.com/ScriptReference/AssetDatabase.ExportPackage.html
Acquire the ULF file to activate your Unity license. Use the following tool to acquire the ULF file.
https://github.com/mackysoft/Unity-ManualActivation
- Select the
Settings > Secrets
menu in the project repository. - Click the
New repository secret
button. - Enter "UNITY_LICENSE" in Name and copy and paste the contents of the ULF file in Value.
- Click the
Add secret
button.
You can now treat the contents of the ULF file as an environment variable while keeping its contents private.
Create a package.yaml
under the repository .github/workflows/
and write the following.
name: Export Package
on:
pull_request: {}
push: { branches: [main] }
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
jobs:
build:
name: Build UnityPackage
runs-on: ubuntu-latest
steps:
# Checkout
- name: Checkout repository
uses: actions/checkout@v2
with:
lfs: true
# Cache
- name: Cache
uses: actions/cache@v2
with:
path: Library
key: Library
restore-keys: Library-
# Build
- name: Build .unitypackage
uses: game-ci/unity-builder@v2
with:
unityVersion: 2020.3.1f1
buildMethod: ExportPackageExample.Editor.UnityPackageExporter.Export # Path to the export method containing the namespace.
# Upload
- name: Upload .unitypackage
uses: actions/upload-artifact@v2
with:
name: Unity Package
path: Build
The workflow for exporting unitypackage will run by making a Push and Pull Request to the repository.
If you see a tick mark as shown below, you have succeeded. The exported unitypackage can be acquired from Artifacts in the upper right corner.
Hiroya Aramaki is a indie game developer in Japan.
- Blog: https://mackysoft.net/blog
- Twitter: https://twitter.com/makihiro_dev
This repository is under the MIT License.