Build and Push Containers to GHCR #33
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 and Push Godot Containers to GHCR | |
on: | |
workflow_dispatch: # Enables manual trigger from the GitHub UI | |
permissions: | |
contents: write | |
packages: write | |
attestations: write | |
id-token: write | |
jobs: | |
build: | |
runs-on: self-hosted | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.10' | |
- name: Print Environment Variables | |
run: env | |
- name: Setup Environment | |
run: | | |
echo "HOME=/home/ubuntu" >> $GITHUB_ENV | |
echo "ARTIFACTS_ROOT_PATH=/home/ubuntu/.cache/github-runners/build-containers" >> $GITHUB_ENV | |
pip install gdown | |
- name: Print Environment Variables | |
run: env | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Clone Godot build-containers repository | |
run: git clone -b my-branch https://github.com/nongvantinh/build-containers | |
- name: Download Xcode | |
run: | | |
mkdir -p $ARTIFACTS_ROOT_PATH/files | |
cd $ARTIFACTS_ROOT_PATH/files | |
if ls Xcode_*.xip 1> /dev/null 2>&1; then | |
echo "Xcode file already exists, skipping download." | |
else | |
echo "Downloading Xcode..." | |
gdown ${{ secrets.XCODE_SDK_LINK }} | |
echo "Listing files in the current directory:" | |
ls -la | |
fi | |
- name: Build Godot Containers with Docker | |
run: | | |
chmod +x ${GITHUB_WORKSPACE}/build-containers/build.sh | |
cd ${GITHUB_WORKSPACE}/build-containers | |
./build.sh 4.3 f40 # Replace with the correct Godot branch and Fedora version as needed | |
- name: Log in to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Tag and Push to GitHub Container Registry | |
run: | | |
docker images --format '{{.Repository}}:{{.Tag}}' | while read image; do | |
IMAGE_NAME=ghcr.io/${{ github.repository_owner }}/$(basename $image) | |
docker tag $image $IMAGE_NAME | |
docker push $IMAGE_NAME | |
done | |
- name: Clean Up Dangling Images | |
run: | | |
docker images | |
docker rmi $(docker images -f "dangling=true" -q) || true # Ignore errors if no dangling images |