Skip to content

Commit 326065c

Browse files
authored
Merge branch 'Bisa:master' into master
2 parents 5e33d76 + 94e9499 commit 326065c

File tree

13 files changed

+153
-155
lines changed

13 files changed

+153
-155
lines changed

.github/workflows/ci.yml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ on:
1010
jobs:
1111
shellchecks:
1212
runs-on: ubuntu-latest
13+
environment: "CI Tests"
1314
steps:
15+
#- name: Login to Docker Hub
16+
# uses: docker/login-action@v2
17+
# with:
18+
# username: ${{ secrets.DOCKERHUB_USERNAME }}
19+
# password: ${{ secrets.DOCKERHUB_TOKEN }}
1420
- name: Checkout repo
1521
uses: actions/checkout@master
1622
- name: Shellchecks
@@ -19,14 +25,20 @@ jobs:
1925
docker run --rm -v "$GITHUB_WORKSPACE:/mnt" koalaman/shellcheck:stable factorio
2026
bats:
2127
runs-on: ubuntu-latest
28+
environment: "CI Tests"
2229
steps:
30+
#- name: Login to Docker Hub
31+
# uses: docker/login-action@v2
32+
# with:
33+
# username: ${{ secrets.DOCKERHUB_USERNAME }}
34+
# password: ${{ secrets.DOCKERHUB_TOKEN }}
2335
- name: Checkout repo
2436
uses: actions/checkout@master
25-
- name: Checkout submodules
26-
uses: textbook/git-checkout-submodule-action@master
37+
with:
38+
submodules: recursive
2739
- name: Prepare env
2840
run: |
29-
echo "factorio_version=1.1.30" >> $GITHUB_ENV
41+
echo "factorio_version=1.1.61" >> $GITHUB_ENV
3042
echo "factorio_user=factorio" >> $GITHUB_ENV
3143
echo "factorio_group=factorio" >> $GITHUB_ENV
3244
- name: Add factorio user
@@ -52,12 +64,3 @@ jobs:
5264
echo "FACTORIO_INIT_WITH_PRE_INSTALLED_GAME=1" >> $GITHUB_ENV
5365
- name: Bats with pre-installed game
5466
run: sudo -E -u "${factorio_user}" extras/test/libs/bats-core/bin/bats extras/test
55-
# docker-tests:
56-
# runs-on: ubuntu-latest
57-
# steps:
58-
# - name: Checkout repo
59-
# uses: actions/checkout@master
60-
# - name: Checkout submodules
61-
# uses: textbook/git-checkout-submodule-action@master
62-
# - name: foo
63-
# run: extras/.githooks/pre-commit

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
config
22
**/*.swp
3+
*.code-workspace

README.md

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,10 @@ A factorio init script in bash
44

55
## Requirements
66

7-
The following software packages need to be installed:
8-
9-
- Wget
10-
- cURL
11-
- bash-completion (optional but recomended)
12-
13-
- for yum based systems do the following:
14-
15-
```bash
16-
sudo yum install curl wget bash-completion
17-
```
18-
19-
- for dnf based systems do the following:
20-
21-
```bash
22-
sudo dnf install curl wget bash-completion
23-
```
24-
25-
- for apt-get based systems do the following:
26-
27-
```bash
28-
sudo apt-get install curl wget bash-completion
29-
```
7+
- [wget](https://www.gnu.org/software/wget/)
8+
- [curl](https://curl.se/)
9+
- [xz](https://tukaani.org/xz/) (wube uses tar.xz for tarballs, only needed if you install with this script)
10+
- [bash-completion](https://github.com/scop/bash-completion) (optional)
3011

3112
## Debugging
3213

@@ -162,18 +143,18 @@ git submodule update
162143
git config --local core.hooksPath extras/.githooks
163144
```
164145

165-
The ```extras/.githooks/pre-commit``` will run shellcheck, local tests as well as docker tests with and without resources.
146+
The ```extras/.githooks/pre-push``` will run shellcheck, local tests as well as docker tests with and without resources.
166147

167148
#### With Docker
168149

169150
- Build the docker image(s) (a slightly modified ubuntu/centos)
170151

171152
```bash
172153
docker build --build-arg ubuntu_version=20.04 \
173-
--build-arg factorio_version=1.1.30 \
154+
--build-arg factorio_version=1.1.61 \
174155
--tag ubuntu-finit:latest - < extras/docker/Dockerfile.ubuntu
175156
docker build --build-arg centos_version=centos8 \
176-
--build-arg factorio_version=1.1.30 \
157+
--build-arg factorio_version=1.1.61 \
177158
--tag centos-finit:latest - < extras/docker/Dockerfile.centos
178159
```
179160

@@ -193,7 +174,7 @@ Please note that some tests will be skipped unless you run them with the docker
193174
- run the tests
194175

195176
```bash
196-
./extras/test/libs/bats-core/bin/bats test
177+
./extras/test/libs/bats-core/bin/bats extras/test
197178
```
198179

199180
Using [parallel](https://www.gnu.org/software/parallel), adding ```--jobs 10``` to the above (adjust the number accordingly) will allow you to execute more tests in parallel and in turn possibly decrease the total time required to complete the run.

config.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ SAVELOG=0
5656
# Useful for Cloud providers where VMs may start faster than their Internet connectivity is plumbed.
5757
WAIT_PINGPONG=0
5858

59+
# Time after which the factorio server will be killed with force.
60+
# Adjust this to allow more time for map saving, e.g. on modded servers with multiple maps.
61+
# Increased values must be propagated to service files (systemd) as well.
62+
FORCED_SHUTDOWN=15
63+
5964
# Using install, it's possible to cache the tarballs fetched from Wube
6065
INSTALL_CACHE_TAR=1
6166
# set this to a directory where you allow this script to create a 'factorio-install' directory

extras/.githooks/common

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
3+
# This file should be sourced, not executed directly.
4+
5+
root_dir="$(git rev-parse --show-toplevel)"
6+
dockerfiles="${root_dir}/extras/docker/Dockerfile"
7+
8+
function dockertest() {
9+
dist="$1"; shift
10+
versions="$1"; shift
11+
fversion="$1"; shift
12+
targets="$1"; shift
13+
IFS=" " read -r -a extra_args <<< "${1:-}"
14+
15+
for version in $versions; do
16+
image="${dist}-${version}"
17+
for target in $targets; do
18+
echo
19+
echo "Testing ${image}:${target} (factorio ${fversion})"
20+
echo
21+
docker build --build-arg "${dist}_version=${version}" \
22+
--build-arg "factorio_version=${fversion}" \
23+
--target "${target}" \
24+
--tag "${image}-finit:${target}" - < "${dockerfiles}.${dist}" || return 1
25+
options=(-v "${root_dir}:/opt/factorio-init" "${image}-finit:${target}" "${extra_args[@]}" extras/test)
26+
docker run -t --rm "${options[@]}" || return 1
27+
done
28+
done
29+
}
30+
31+
function run_shellchecks() {
32+
docker run --rm -v "${root_dir}:/mnt" koalaman/shellcheck:stable extras/.githooks/* &&
33+
docker run --rm -v "${root_dir}:/mnt" koalaman/shellcheck:stable factorio
34+
}
35+
36+
function run_localtests() {
37+
"${root_dir}/extras/test/libs/bats-core/bin/bats" "${root_dir}/extras/test" || exit 1
38+
}
39+
40+
function run_dockertests() {
41+
factorio_version="1.1.61"
42+
targets="with-test-resources sans-test-resources"
43+
44+
dockertest ubuntu latest "${factorio_version}" "${targets}" "--jobs 10" &&
45+
dockertest "ubuntu" "latest" "${factorio_version}" "with-pre-installed-game" #TODO make pre-installed game tests run in parallel
46+
47+
#dockertest "ubuntu" "20.04 18.04" "${factorio_version}" "${targets}" "--jobs 10" &&
48+
#dockertest "ubuntu" "20.04 18.04" "${factorio_version}" "with-pre-installed-game" && #TODO make pre-installed game tests run in parallel
49+
#dockertest "centos" "centos8" "${factorio_version}" "with-pre-installed-game ${targets}" || exit 1
50+
#dockertest "centos" "centos7" "${factorio_version}" "with-pre-installed-game-glibc with-glibc-sidebyside" || exit 1
51+
}

extras/.githooks/pre-commit

Lines changed: 0 additions & 67 deletions
This file was deleted.

extras/.githooks/pre-push

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
# TODO: Break the running of tests out into a separate script to facilitate:
4+
# - only running selective tests/linting pre-commit, for sanity
5+
# - running all/some tests from commandline (to avoid stashing/doing git specific stuff)
6+
# - running all tests before pushing (ie what is happening now on every pre-commit)
7+
8+
set -euo pipefail
9+
10+
# find out where this repo is situated
11+
root_dir="$(git rev-parse --show-toplevel)"
12+
source "$root_dir/extras/.githooks/common" || exit 1
13+
14+
z40=0000000000000000000000000000000000000000
15+
16+
# shellcheck disable=SC2034
17+
while read -r local_ref local_sha remote_ref remote_sha; do
18+
if [ "$local_sha" = $z40 ]; then
19+
# Handle delete
20+
:
21+
else
22+
[[ "${SKIP_TESTS_PRE_PUSH:-False}" == "True" ]] && exit 0
23+
run_shellchecks &&
24+
run_localtests &&
25+
run_dockertests
26+
exit $?
27+
fi
28+
done

extras/docker/Dockerfile.centos

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ARG centos_version=centos8
2-
ARG factorio_version=1.1.30
2+
ARG factorio_version=1.1.61
33
ARG factorio_user=factorio
44

55
### A base image without test resources:

extras/docker/Dockerfile.ubuntu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ENTRYPOINT ["bash", "/opt/factorio-init/extras/test/libs/bats-core/bin/bats"]
2020
### Build onto the base, add test resources:
2121
FROM sans-test-resources AS with-test-resources
2222
ENV FACTORIO_INIT_WITH_TEST_RESOURCES=1
23-
ARG factorio_version=1.1.30
23+
ARG factorio_version=1.1.61
2424

2525
RUN wget -O /tmp/factorio_headless_x64_${factorio_version}.tar.xz \
2626
https://factorio.com/get-download/${factorio_version}/headless/linux64

extras/factorio.service.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Description=Factorio Server
33
Wants=network-online.target
44
After=network.target network-online.target
5+
StartLimitIntervalSec=600
56

67
[Service]
78
User=factorio
@@ -18,6 +19,7 @@ TimeoutStopSec=20
1819
ExecStop=/opt/factorio-init/factorio stop
1920
RestartSec=20
2021
Restart=on-failure
22+
StartLimitBurst=5
2123

2224
[Install]
2325
WantedBy=multi-user.target

0 commit comments

Comments
 (0)