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 Docker image needs: check-version if: needs.check-version.outputs.should_build == 'true' runs-on: prunner-ubuntu 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: Create BuildKit config run: | cat > /tmp/buildkitd.toml <<'EOF' [registry."docker.io"] mirrors = ["mirror.gcr.io"] EOF - name: Log in to Nexus Docker Registry uses: docker/login-action@v3 with: registry: ${{ env.NEXUS_REGISTRY }} username: ${{ secrets.NEXUS_USERNAME }} password: ${{ secrets.NEXUS_TOKEN }} - name: Setup Docker Buildx uses: docker/setup-buildx-action@v3 with: driver-opts: | image=moby/buildkit:buildx-stable-1 buildkitd-config-inline: | [registry."docker.io"] mirrors = ["mirror.gcr.io"] - name: Build and push Factorio image uses: docker/build-push-action@v6 with: context: . file: ./Dockerfile push: true build-args: | FACTORIO_VERSION=${{ needs.check-version.outputs.version }} tags: | ${{ env.IMAGE_NAME }}:${{ needs.check-version.outputs.version }} ${{ env.IMAGE_NAME }}:latest - 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" git tag -a "$TAG" \ -m "Build Factorio ${VERSION}" git push origin "$TAG"