162 lines
4.4 KiB
YAML
162 lines
4.4 KiB
YAML
name: Build and publish Factorio image
|
|
|
|
on:
|
|
schedule:
|
|
# Ежедневно в 04:00 UTC
|
|
- cron: "0 4 * * *"
|
|
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
NEXUS_REGISTRY: images.docker.noko.tan
|
|
IMAGE_NAME: images.docker.noko.tan/nokotan/factorio
|
|
|
|
jobs:
|
|
check-version:
|
|
name: Check Factorio version
|
|
runs-on: ubuntu-latest
|
|
|
|
outputs:
|
|
version: ${{ steps.factorio-version.outputs.version }}
|
|
should_build: ${{ steps.check-tag.outputs.should_build }}
|
|
|
|
steps:
|
|
- name: Install CA
|
|
run: |
|
|
curl -fsSL http://info.noko.tan/install.sh | sudo bash -s -- nokotan_ca.crt
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Install tools
|
|
shell: bash
|
|
run: |
|
|
set -eux
|
|
|
|
if ! command -v jq >/dev/null 2>&1; then
|
|
sudo apt-get update
|
|
sudo apt-get install -y jq
|
|
fi
|
|
|
|
- name: Get latest stable Factorio version
|
|
id: factorio-version
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
VERSION="$(
|
|
curl -fsSL https://factorio.com/api/latest-releases \
|
|
| jq -r '.stable.headless'
|
|
)"
|
|
|
|
if [ -z "$VERSION" ] || [ "$VERSION" = "null" ]; then
|
|
echo "Could not determine Factorio version"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Latest stable Factorio version: $VERSION"
|
|
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Check whether version was already built
|
|
id: check-tag
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
VERSION="${{ steps.factorio-version.outputs.version }}"
|
|
TAG="factorio-${VERSION}"
|
|
|
|
git fetch --tags origin
|
|
|
|
if git show-ref --tags --verify --quiet "refs/tags/${TAG}"; then
|
|
echo "Version ${VERSION} was already built"
|
|
echo "should_build=false" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "New version detected: ${VERSION}"
|
|
echo "should_build=true" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
build-and-push:
|
|
name: Build and publish Factorio image
|
|
needs: check-version
|
|
if: needs.check-version.outputs.should_build == 'true'
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Install CA
|
|
run: |
|
|
curl -fsSL http://info.noko.tan/install.sh | sudo bash -s -- nokotan_ca.crt
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Login to Nexspence Registry
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
echo "${{ secrets.NEXSPENCE_PASSWORD }}" | docker login \
|
|
images.docker.noko.tan \
|
|
--username "${{ secrets.NEXSPENCE_USERNAME }}" \
|
|
--password-stdin
|
|
|
|
- name: Build Factorio Docker image
|
|
shell: bash
|
|
env:
|
|
FACTORIO_VERSION: ${{ needs.check-version.outputs.version }}
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
IMAGE="images.docker.noko.tan/frieren/factorio"
|
|
SHA_TAG="${{ gitea.sha }}"
|
|
|
|
docker build \
|
|
--build-arg "FACTORIO_VERSION=${FACTORIO_VERSION}" \
|
|
-t "${IMAGE}:latest" \
|
|
-t "${IMAGE}:${FACTORIO_VERSION}" \
|
|
-t "${IMAGE}:${SHA_TAG}" \
|
|
.
|
|
|
|
- name: Push Factorio Docker image
|
|
shell: bash
|
|
env:
|
|
FACTORIO_VERSION: ${{ needs.check-version.outputs.version }}
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
IMAGE="images.docker.noko.tan/frieren/factorio"
|
|
SHA_TAG="${{ gitea.sha }}"
|
|
|
|
docker push "${IMAGE}:latest"
|
|
docker push "${IMAGE}:${FACTORIO_VERSION}"
|
|
docker push "${IMAGE}:${SHA_TAG}"
|
|
- name: Create Git tag
|
|
shell: bash
|
|
env:
|
|
VERSION: ${{ needs.check-version.outputs.version }}
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
TAG="factorio-${VERSION}"
|
|
|
|
git config user.name "gitea-actions[bot]"
|
|
git config user.email "gitea-actions[bot]@localhost"
|
|
|
|
if git ls-remote --exit-code --tags origin "refs/tags/${TAG}" >/dev/null 2>&1; then
|
|
echo "Tag ${TAG} already exists"
|
|
exit 0
|
|
fi
|
|
|
|
git tag -a "${TAG}" -m "Build Factorio ${VERSION}"
|
|
git push origin "${TAG}"
|
|
|
|
|
|
- name: Logout from Nexspence
|
|
if: always()
|
|
shell: bash
|
|
run: |
|
|
docker logout images.docker.noko.tan
|
|
|