Build /tg/ui #26
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build tgui | |
on: | |
workflow_dispatch: | |
inputs: | |
upstream-repository: | |
description: The upstream repository. | |
required: false | |
type: string | |
repository: | |
description: The repository to check out. | |
required: false | |
type: string | |
branch: | |
description: The branch in the repository to check out. | |
required: true | |
type: string | |
env: | |
REPOSITORY: ${{ vars.DEFAULT_REPOSITORY || inputs.repository }} | |
UPSTREAM_REPOSITORY: ${{ vars.UPSTREAM_REPOSITORY || inputs.upstream-repository }} | |
jobs: | |
build-tgui: | |
name: Build tgui | |
runs-on: ubuntu-22.04 | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
repository: ${{ env.REPOSITORY }} | |
ref: ${{ inputs.branch }} | |
ssh-key: ${{ secrets.REPOSITORY_SSH_KEY }} | |
- name: Setup Git User | |
run: | | |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git config --global user.name "tgui builder" | |
- name: Install Dependencies | |
run: | | |
source ~/.nvm/nvm.sh | |
nvm install 18 | |
corepack enable | |
tgui_yarn_cache_dir=$(cd tgui ; yarn config get cacheFolder) | |
if [ -n $tgui_yarn_cache_dir ] && [ $tgui_yarn_cache_dir != 'undefined' ] ; then | |
echo 'TGUI_YARN_CACHE_DIR='"$(tgui_yarn_cache_dir)" >> "$GITHUB_ENV" | |
fi | |
- name: Cache Dependencies | |
uses: actions/cache@v3 | |
with: | |
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }} | |
path: | | |
**/node_modules | |
${{ env.TGUI_YARN_CACHE_DIR }} | |
- name: Try to Fetch Upstream | |
if: ${{ env.UPSTREAM_REPOSITORY }} | |
run: | | |
behind_by=$(curl -L -s --fail-with-body \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
"https://api.github.com/repos/$UPSTREAM_REPOSITORY/compare/${UPSTREAM_REPOSITORY%%/*}:master...${REPOSITORY%%/*}:master" \ | |
| jq '.behind_by') | |
if [ $behind_by -le 0 ] ; then | |
echo '- Skipping upstream merge. No changes to merge.' | tee -a "$GITHUB_STEP_SUMMARY" | |
exit 0 | |
else | |
echo '- Merging upstream branch. HEAD branch is behind by '"$behind_by"' commits.' | tee -a "$GITHUB_STEP_SUMMARY" | |
fi | |
git fetch --unshallow origin @ | |
git fetch "git@github.com:$UPSTREAM_REPOSITORY.git" master && { git merge FETCH_HEAD || true ; } | |
exit_code=0 | |
merge_conflicts=$(git diff --name-only --diff-filter=U --exit-code) || exit_code=$? | |
if [ $exit_code -eq 0 ] ; then | |
exit 0 | |
elif echo $merge_conflicts | grep -v ^tgui/packages/tgui/public/ ; then | |
echo '- Automatic merge failed. Non-tgui bundle files have conflicts.' | tee -a "$GITHUB_STEP_SUMMARY" | |
exit 1 | |
fi | |
- name: Build | |
run: | | |
source ~/.nvm/nvm.sh | |
nvm use 18 | |
cd tgui | |
bin/tgui | |
- name: Commit and Push | |
run: | | |
if ! git diff --exit-code > /dev/null; then | |
git add ./tgui/packages/tgui/public/ | |
git commit -m "Build and update tgui" | |
git push | |
else | |
echo '- Skipping commit. No changes to commit.' | tee -a "$GITHUB_STEP_SUMMARY" | |
fi |