Compare commits
23 commits
Author | SHA1 | Date | |
---|---|---|---|
asonix | 4717e4fdb2 | ||
asonix | 73002d4d35 | ||
asonix | a335225088 | ||
asonix | 0d9ec4cc87 | ||
asonix | 21ffc4111e | ||
asonix | a2abc146f4 | ||
asonix | 7b188e2fa1 | ||
asonix | 801747c7bc | ||
asonix | 39e2344fb2 | ||
asonix | d163a3cf79 | ||
asonix | c834b6c913 | ||
asonix | 74b011afe9 | ||
asonix | 4ccba45d58 | ||
asonix | 5db1dbc96c | ||
asonix | 2d5da08bad | ||
asonix | 17177cb6ea | ||
asonix | 26df437691 | ||
asonix | 64ea25c915 | ||
asonix | 203ffbbbaf | ||
asonix | 88aa177f7c | ||
asonix | afe081a099 | ||
asonix | 5b02cbec16 | ||
asonix | faec338d57 |
61
.forgejo/workflows/check.yaml
Normal file
61
.forgejo/workflows/check.yaml
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- '*'
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
clippy:
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: docker.io/asonix/actions-base-image:0.1
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout warriors-names
|
||||||
|
uses: https://github.com/actions/checkout@v4
|
||||||
|
-
|
||||||
|
name: Cargo Cache
|
||||||
|
uses: https://git.asonix.dog/asonix/actions/cache-rust-dependencies@main
|
||||||
|
-
|
||||||
|
name: Clippy
|
||||||
|
run: |
|
||||||
|
cargo clippy --no-default-features -- -D warnings
|
||||||
|
|
||||||
|
tests:
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: docker.io/asonix/actions-base-image:0.1
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout warriors-names
|
||||||
|
uses: https://github.com/actions/checkout@v4
|
||||||
|
-
|
||||||
|
name: Cargo Cache
|
||||||
|
uses: https://git.asonix.dog/asonix/actions/cache-rust-dependencies@main
|
||||||
|
-
|
||||||
|
name: Test
|
||||||
|
run: cargo test
|
||||||
|
|
||||||
|
check:
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
target:
|
||||||
|
- x86_64-unknown-linux-musl
|
||||||
|
- armv7-unknown-linux-musleabihf
|
||||||
|
- aarch64-unknown-linux-musl
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: docker.io/asonix/actions-base-image:0.1
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout warriors-names
|
||||||
|
uses: https://github.com/actions/checkout@v4
|
||||||
|
-
|
||||||
|
name: Cargo Cache
|
||||||
|
uses: https://git.asonix.dog/asonix/actions/cache-rust-dependencies@main
|
||||||
|
-
|
||||||
|
name: Debug builds
|
||||||
|
run: cargo zigbuild --target ${{ matrix.target }}
|
225
.forgejo/workflows/publish.yaml
Normal file
225
.forgejo/workflows/publish.yaml
Normal file
|
@ -0,0 +1,225 @@
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*.*.*'
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY_IMAGE: asonix/warriors-names
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
clippy:
|
||||||
|
runs-on: base-image
|
||||||
|
container:
|
||||||
|
image: docker.io/asonix/actions-base-image:0.1
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout warriors-names
|
||||||
|
uses: https://github.com/actions/checkout@v4
|
||||||
|
-
|
||||||
|
name: Cargo Cache
|
||||||
|
uses: https://git.asonix.dog/asonix/actions/cache-rust-dependencies@main
|
||||||
|
-
|
||||||
|
name: Clippy
|
||||||
|
run: |
|
||||||
|
cargo clippy --no-default-features -- -D warnings
|
||||||
|
|
||||||
|
tests:
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: docker.io/asonix/actions-base-image:0.1
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout warriors-names
|
||||||
|
uses: https://github.com/actions/checkout@v4
|
||||||
|
-
|
||||||
|
name: Cargo Cache
|
||||||
|
uses: https://git.asonix.dog/asonix/actions/cache-rust-dependencies@main
|
||||||
|
-
|
||||||
|
name: Test
|
||||||
|
run: cargo test
|
||||||
|
|
||||||
|
build:
|
||||||
|
needs:
|
||||||
|
- clippy
|
||||||
|
- tests
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: docker.io/asonix/actions-base-image:0.1
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
info:
|
||||||
|
- target: x86_64-unknown-linux-musl
|
||||||
|
artifact: linux-amd64
|
||||||
|
platform: linux/amd64
|
||||||
|
- target: armv7-unknown-linux-musleabihf
|
||||||
|
artifact: linux-arm32v7
|
||||||
|
platform: linux/arm/v7
|
||||||
|
- target: aarch64-unknown-linux-musl
|
||||||
|
artifact: linux-arm64v8
|
||||||
|
platform: linux/arm64
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout warriors-names
|
||||||
|
uses: https://github.com/actions/checkout@v4
|
||||||
|
-
|
||||||
|
name: Cargo Cache
|
||||||
|
uses: https://git.asonix.dog/asonix/actions/cache-rust-dependencies@main
|
||||||
|
-
|
||||||
|
name: Prepare Platform
|
||||||
|
run: |
|
||||||
|
platform=${{ matrix.info.platform }}
|
||||||
|
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
|
||||||
|
shell: bash
|
||||||
|
-
|
||||||
|
name: Docker meta
|
||||||
|
id: meta
|
||||||
|
uses: https://github.com/docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: ${{ env.REGISTRY_IMAGE }}
|
||||||
|
flavor: |
|
||||||
|
latest=auto
|
||||||
|
suffix=-${{ matrix.info.artifact }}
|
||||||
|
tags: |
|
||||||
|
type=raw,value=latest,enable={{ is_default_branch }}
|
||||||
|
type=semver,pattern={{version}}
|
||||||
|
type=semver,pattern={{major}}.{{minor}}
|
||||||
|
type=semver,pattern={{major}}
|
||||||
|
-
|
||||||
|
name: Set up QEMU
|
||||||
|
uses: https://github.com/docker/setup-qemu-action@v3
|
||||||
|
-
|
||||||
|
name: Set up Docker Buildx
|
||||||
|
uses: https://github.com/docker/setup-buildx-action@v3
|
||||||
|
-
|
||||||
|
name: Docker login
|
||||||
|
uses: https://github.com/docker/login-action@v3
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
-
|
||||||
|
name: Compile warriors-names
|
||||||
|
run: cargo zigbuild --target ${{ matrix.info.target }} --release
|
||||||
|
-
|
||||||
|
name: Prepare artifacts
|
||||||
|
run: |
|
||||||
|
mkdir artifacts
|
||||||
|
cp target/${{ matrix.info.target }}/release/warriors-names artifacts/warriors-names-${{ matrix.info.artifact }}
|
||||||
|
-
|
||||||
|
uses: https://github.com/actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: binaries
|
||||||
|
path: artifacts/
|
||||||
|
-
|
||||||
|
name: Prepare binary
|
||||||
|
run: |
|
||||||
|
cp target/${{ matrix.info.target }}/release/warriors-names docker/forgejo/warriors-names
|
||||||
|
-
|
||||||
|
name: Build and push ${{ matrix.info.platform }} docker image
|
||||||
|
id: build
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: ./docker/forgejo
|
||||||
|
platforms: ${{ matrix.info.platform }}
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},name-canonical=true,push=true
|
||||||
|
-
|
||||||
|
name: Export digest
|
||||||
|
run: |
|
||||||
|
mkdir -p /tmp/digests
|
||||||
|
digest="${{ steps.build.outputs.digest }}"
|
||||||
|
touch "/tmp/digests/${digest#sha256:}"
|
||||||
|
echo "Created /tmp/digests/${digest#sha256:}"
|
||||||
|
shell: bash
|
||||||
|
-
|
||||||
|
name: Upload ${{ matrix.info.platform }} digest
|
||||||
|
uses: https://github.com/actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: digests
|
||||||
|
path: /tmp/digests/*
|
||||||
|
if-no-files-found: error
|
||||||
|
retention-days: 1
|
||||||
|
|
||||||
|
publish-docker:
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: docker.io/asonix/actions-base-image:0.1
|
||||||
|
needs: [build]
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Download digests
|
||||||
|
uses: https://github.com/actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: digests
|
||||||
|
path: /tmp/digests
|
||||||
|
pattern: digests-*
|
||||||
|
merge-multiple: true
|
||||||
|
-
|
||||||
|
name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
-
|
||||||
|
name: Docker login
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
-
|
||||||
|
name: Docker meta
|
||||||
|
id: meta
|
||||||
|
uses: https://github.com/docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: ${{ env.REGISTRY_IMAGE }}
|
||||||
|
flavor: |
|
||||||
|
latest=auto
|
||||||
|
tags: |
|
||||||
|
type=raw,value=latest,enable={{ is_default_branch }}
|
||||||
|
type=semver,pattern={{version}}
|
||||||
|
type=semver,pattern={{major}}.{{minor}}
|
||||||
|
type=semver,pattern={{major}}
|
||||||
|
-
|
||||||
|
name: Create manifest list and push
|
||||||
|
working-directory: /tmp/digests
|
||||||
|
run: |
|
||||||
|
tags=$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "${DOCKER_METADATA_OUTPUT_JSON}")
|
||||||
|
images=$(printf "${{ env.REGISTRY_IMAGE }}@sha256:%s " *)
|
||||||
|
echo "Running 'docker buildx imagetools create ${tags[@]} ${images[@]}'"
|
||||||
|
docker buildx imagetools create ${tags[@]} ${images[@]}
|
||||||
|
shell: bash
|
||||||
|
-
|
||||||
|
name: Inspect Image
|
||||||
|
run: |
|
||||||
|
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
|
||||||
|
|
||||||
|
publish-forgejo:
|
||||||
|
needs: [build]
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: docker.io/asonix/actions-base-image:0.1
|
||||||
|
steps:
|
||||||
|
- uses: https://github.com/actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: binaries
|
||||||
|
path: artifacts/
|
||||||
|
merge-multiple: true
|
||||||
|
- uses: actions/forgejo-release@v1
|
||||||
|
with:
|
||||||
|
direction: upload
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
release-dir: artifacts/
|
||||||
|
|
||||||
|
publish-crate:
|
||||||
|
needs: [build]
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: docker.io/asonix/actions-base-image:0.1
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout warriors-names
|
||||||
|
uses: https://github.com/actions/checkout@v4
|
||||||
|
-
|
||||||
|
name: Cargo Cache
|
||||||
|
uses: https://git.asonix.dog/asonix/actions/cache-rust-dependencies@main
|
||||||
|
-
|
||||||
|
name: Publish Crate
|
||||||
|
run: cargo publish --token ${{ secrets.CRATES_IO_TOKEN }}
|
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,3 +1,6 @@
|
||||||
/target
|
/target
|
||||||
Token.toml
|
Token.toml
|
||||||
Config.toml
|
Config.toml
|
||||||
|
.envrc
|
||||||
|
.direnv
|
||||||
|
result
|
||||||
|
|
1058
Cargo.lock
generated
1058
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
21
Cargo.toml
21
Cargo.toml
|
@ -1,18 +1,25 @@
|
||||||
[package]
|
[package]
|
||||||
name = "warriors-names"
|
name = "warriors-names"
|
||||||
version = "0.1.4"
|
description = "A bot that generates warriors cat names and posts them to mastodon"
|
||||||
|
version = "0.2.3"
|
||||||
authors = ["asonix <asonix@asonix.dog>"]
|
authors = ["asonix <asonix@asonix.dog>"]
|
||||||
edition = "2018"
|
license = "AGPL-3.0"
|
||||||
|
repository = "https://git.asonix.dog/asonix/warriors-names"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
[profile.release]
|
||||||
|
strip = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
rand = "0.7"
|
rand = "0.8"
|
||||||
reqwest = { version = "0.10", default-features = false, features = ["json", "rustls-tls"] }
|
reqwest = { version = "0.11", default-features = false, features = [
|
||||||
|
"json",
|
||||||
|
"rustls-tls",
|
||||||
|
] }
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
toml = "0.5"
|
toml = "0.8"
|
||||||
tokio = { version = "0.3", features = ["full"] }
|
tokio = { version = "1", features = ["full"] }
|
||||||
tokio-compat-02 = "0.1"
|
|
||||||
url = { version = "2.0", features = ["serde"] }
|
url = { version = "2.0", features = ["serde"] }
|
||||||
|
|
|
@ -43,9 +43,7 @@
|
||||||
"chance": 0.5,
|
"chance": 0.5,
|
||||||
"join": ", "
|
"join": ", "
|
||||||
}, {
|
}, {
|
||||||
"from": [
|
"from": ["small"],
|
||||||
"small"
|
|
||||||
],
|
|
||||||
"to": [
|
"to": [
|
||||||
"sleek",
|
"sleek",
|
||||||
"swift",
|
"swift",
|
||||||
|
@ -87,7 +85,13 @@
|
||||||
"variants": "any",
|
"variants": "any",
|
||||||
"depends": "color-modifier",
|
"depends": "color-modifier",
|
||||||
"chance": 0.3,
|
"chance": 0.3,
|
||||||
"order": "{color-modifier} {base}"
|
"order": "{color-modifier} {base}",
|
||||||
|
"weights": [
|
||||||
|
[1, "light"],
|
||||||
|
[1, "dark"],
|
||||||
|
[1, "pale"],
|
||||||
|
[1, "bright"]
|
||||||
|
]
|
||||||
}]
|
}]
|
||||||
}, {
|
}, {
|
||||||
"name": "post-descriptor",
|
"name": "post-descriptor",
|
||||||
|
@ -106,7 +110,12 @@
|
||||||
"chance": 1,
|
"chance": 1,
|
||||||
"order": "{eye-color} {base}"
|
"order": "{eye-color} {base}"
|
||||||
}, {
|
}, {
|
||||||
"variants": ["paws", "stripes", "spots", "splotches"],
|
"variants": [
|
||||||
|
"paws",
|
||||||
|
"stripes",
|
||||||
|
"spots",
|
||||||
|
"splotches"
|
||||||
|
],
|
||||||
"depends": "pelt-color",
|
"depends": "pelt-color",
|
||||||
"chance": 1,
|
"chance": 1,
|
||||||
"order": "{pelt-color} {base}"
|
"order": "{pelt-color} {base}"
|
||||||
|
@ -129,10 +138,16 @@
|
||||||
"dark",
|
"dark",
|
||||||
"light",
|
"light",
|
||||||
"pale",
|
"pale",
|
||||||
"bright"
|
"bright",
|
||||||
|
"jet"
|
||||||
],
|
],
|
||||||
"depends": [{
|
"depends": [{
|
||||||
"variants": "any",
|
"variants": [
|
||||||
|
"light",
|
||||||
|
"pale",
|
||||||
|
"dark",
|
||||||
|
"bright"
|
||||||
|
],
|
||||||
"depends": "very",
|
"depends": "very",
|
||||||
"chance": 0.2,
|
"chance": 0.2,
|
||||||
"order": "{very} {base}"
|
"order": "{very} {base}"
|
||||||
|
@ -150,33 +165,19 @@
|
||||||
"ginger",
|
"ginger",
|
||||||
"brown",
|
"brown",
|
||||||
"reddish-brown",
|
"reddish-brown",
|
||||||
|
"golden",
|
||||||
"golden-brown",
|
"golden-brown",
|
||||||
"dusky-brown",
|
"dusky-brown",
|
||||||
"white"
|
"white"
|
||||||
],
|
],
|
||||||
"depends": [{
|
"depends": [{
|
||||||
"variants": [
|
|
||||||
"black",
|
|
||||||
"gray",
|
|
||||||
"silver",
|
|
||||||
"blue-gray",
|
|
||||||
"ginger",
|
|
||||||
"brown",
|
|
||||||
"reddish-brown",
|
|
||||||
"golden-brown",
|
|
||||||
"dusky-brown",
|
|
||||||
"white"
|
|
||||||
],
|
|
||||||
"depends": "solid",
|
|
||||||
"chance": 0.2,
|
|
||||||
"order": "{solid} {base}"
|
|
||||||
}, {
|
|
||||||
"variants": ["black"],
|
"variants": ["black"],
|
||||||
"depends": "color-modifier",
|
"depends": "color-modifier",
|
||||||
"chance": 0.3,
|
"chance": 0.3,
|
||||||
"order": "{color-modifier} {base}",
|
"order": "{color-modifier} {base}",
|
||||||
"weights": [
|
"weights": [
|
||||||
[1, "dark"]
|
[1, "dark"],
|
||||||
|
[2, "jet"]
|
||||||
]
|
]
|
||||||
}, {
|
}, {
|
||||||
"variants": [
|
"variants": [
|
||||||
|
@ -186,12 +187,14 @@
|
||||||
"ginger",
|
"ginger",
|
||||||
"brown",
|
"brown",
|
||||||
"reddish-brown",
|
"reddish-brown",
|
||||||
|
"golden",
|
||||||
"golden-brown"
|
"golden-brown"
|
||||||
],
|
],
|
||||||
"depends": "color-modifier",
|
"depends": "color-modifier",
|
||||||
"chance": 0.3,
|
"chance": 0.3,
|
||||||
"order": "{color-modifier} {base}",
|
"order": "{color-modifier} {base}",
|
||||||
"weights": [
|
"weights": [
|
||||||
|
[1, "dark"],
|
||||||
[1, "light"],
|
[1, "light"],
|
||||||
[1, "pale"],
|
[1, "pale"],
|
||||||
[1, "bright"]
|
[1, "bright"]
|
||||||
|
@ -204,6 +207,23 @@
|
||||||
"weights": [
|
"weights": [
|
||||||
[1, "bright"]
|
[1, "bright"]
|
||||||
]
|
]
|
||||||
|
}, {
|
||||||
|
"variants": [
|
||||||
|
"black",
|
||||||
|
"gray",
|
||||||
|
"silver",
|
||||||
|
"blue-gray",
|
||||||
|
"ginger",
|
||||||
|
"brown",
|
||||||
|
"reddish-brown",
|
||||||
|
"golden",
|
||||||
|
"golden-brown",
|
||||||
|
"dusky-brown",
|
||||||
|
"white"
|
||||||
|
],
|
||||||
|
"depends": "solid",
|
||||||
|
"chance": 0.2,
|
||||||
|
"order": "{solid} {base}"
|
||||||
}]
|
}]
|
||||||
}, {
|
}, {
|
||||||
"name": "gembder",
|
"name": "gembder",
|
||||||
|
@ -221,8 +241,15 @@
|
||||||
],
|
],
|
||||||
"silent": ["cat"],
|
"silent": ["cat"],
|
||||||
"depends": [{
|
"depends": [{
|
||||||
"variants": ["tortoiseshell", "tabby"],
|
"variants": [
|
||||||
|
"tortoiseshell",
|
||||||
|
"tabby"
|
||||||
|
],
|
||||||
"depends": "pelt-color",
|
"depends": "pelt-color",
|
||||||
|
"forbids": [{
|
||||||
|
"name": "solid",
|
||||||
|
"variants": ["solid"]
|
||||||
|
}],
|
||||||
"chance": 0.5,
|
"chance": 0.5,
|
||||||
"order": "{pelt-color} {base}"
|
"order": "{pelt-color} {base}"
|
||||||
}, {
|
}, {
|
||||||
|
@ -252,7 +279,19 @@
|
||||||
"order": "{base} {gembder}",
|
"order": "{base} {gembder}",
|
||||||
"default": "cat"
|
"default": "cat"
|
||||||
}, {
|
}, {
|
||||||
"variants": "any",
|
"variants": [
|
||||||
|
"tabby",
|
||||||
|
"tortoiseshell"
|
||||||
|
],
|
||||||
|
"depends": "descriptor",
|
||||||
|
"forbids": [{
|
||||||
|
"name": "descriptor",
|
||||||
|
"variants": ["mottled"]
|
||||||
|
}],
|
||||||
|
"chance": 0.5,
|
||||||
|
"order": "{descriptor} {base}"
|
||||||
|
}, {
|
||||||
|
"variants": ["cat"],
|
||||||
"depends": "descriptor",
|
"depends": "descriptor",
|
||||||
"chance": 0.5,
|
"chance": 0.5,
|
||||||
"order": "{descriptor} {base}"
|
"order": "{descriptor} {base}"
|
||||||
|
|
82
Name.json
82
Name.json
|
@ -110,7 +110,68 @@
|
||||||
"minnow",
|
"minnow",
|
||||||
"pounce",
|
"pounce",
|
||||||
"pebble",
|
"pebble",
|
||||||
"ripple"
|
"ripple",
|
||||||
|
"ice",
|
||||||
|
"fox",
|
||||||
|
"dove",
|
||||||
|
"kink",
|
||||||
|
"flame",
|
||||||
|
"olive",
|
||||||
|
"snake",
|
||||||
|
"scorch",
|
||||||
|
"sedge",
|
||||||
|
"ember",
|
||||||
|
"dew",
|
||||||
|
"ant",
|
||||||
|
"heather",
|
||||||
|
"mallow",
|
||||||
|
"mint",
|
||||||
|
"nettle",
|
||||||
|
"sneeze",
|
||||||
|
"otter",
|
||||||
|
"pine",
|
||||||
|
"blossom",
|
||||||
|
"bumble",
|
||||||
|
"briar",
|
||||||
|
"rose",
|
||||||
|
"ferret",
|
||||||
|
"apple",
|
||||||
|
"rat",
|
||||||
|
"starling",
|
||||||
|
"whisker",
|
||||||
|
"furze",
|
||||||
|
"boulder",
|
||||||
|
"sun",
|
||||||
|
"mossy",
|
||||||
|
"beetle",
|
||||||
|
"petal",
|
||||||
|
"grass",
|
||||||
|
"hollow",
|
||||||
|
"dusk",
|
||||||
|
"sky",
|
||||||
|
"sharp",
|
||||||
|
"short",
|
||||||
|
"clover",
|
||||||
|
"echo",
|
||||||
|
"cherry",
|
||||||
|
"sparrow",
|
||||||
|
"rock",
|
||||||
|
"sage",
|
||||||
|
"bounce",
|
||||||
|
"tiny",
|
||||||
|
"buzzard",
|
||||||
|
"seed",
|
||||||
|
"milk",
|
||||||
|
"lark",
|
||||||
|
"sloe",
|
||||||
|
"wasp",
|
||||||
|
"ebony",
|
||||||
|
"freckle",
|
||||||
|
"billy",
|
||||||
|
"snook",
|
||||||
|
"fallow",
|
||||||
|
"lichen",
|
||||||
|
"fawn"
|
||||||
],
|
],
|
||||||
"suffix": [
|
"suffix": [
|
||||||
"kit",
|
"kit",
|
||||||
|
@ -146,7 +207,24 @@
|
||||||
"wing",
|
"wing",
|
||||||
"fall",
|
"fall",
|
||||||
"bird",
|
"bird",
|
||||||
"feather"
|
"feather",
|
||||||
|
"mist",
|
||||||
|
"blaze",
|
||||||
|
"water",
|
||||||
|
"spots",
|
||||||
|
"shine",
|
||||||
|
"leap",
|
||||||
|
"petal",
|
||||||
|
"scar",
|
||||||
|
"strike",
|
||||||
|
"trout",
|
||||||
|
"willow",
|
||||||
|
"light",
|
||||||
|
"flight",
|
||||||
|
"watcher",
|
||||||
|
"dapple",
|
||||||
|
"fire",
|
||||||
|
"fern"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
23
docker/forgejo/Dockerfile
Normal file
23
docker/forgejo/Dockerfile
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
FROM alpine:3.19
|
||||||
|
|
||||||
|
ARG UID=991
|
||||||
|
ARG GID=991
|
||||||
|
|
||||||
|
ENV \
|
||||||
|
UID=${UID} \
|
||||||
|
GID=${GID}
|
||||||
|
|
||||||
|
USER root
|
||||||
|
RUN \
|
||||||
|
addgroup -g "${GID}" app && \
|
||||||
|
adduser -D -G app -u "${UID}" -g "" -h /opt/app app && \
|
||||||
|
apk add tini && \
|
||||||
|
chown -R app:app /mnt
|
||||||
|
|
||||||
|
COPY warriors-names /usr/local/bin/warriors-names
|
||||||
|
|
||||||
|
USER app
|
||||||
|
VOLUME /mnt
|
||||||
|
WORKDIR /mnt
|
||||||
|
ENTRYPOINT ["/sbin/tini", "--"]
|
||||||
|
CMD ["/usr/local/bin/warriors-names"]
|
|
@ -1,74 +0,0 @@
|
||||||
FROM rustembedded/cross:x86_64-unknown-linux-musl AS x86_64-builder
|
|
||||||
|
|
||||||
ARG UID=991
|
|
||||||
ARG GID=991
|
|
||||||
|
|
||||||
ENV TOOLCHAIN=stable
|
|
||||||
ENV TARGET=x86_64-unknown-linux-musl
|
|
||||||
ENV TOOL=x86_64-linux-musl
|
|
||||||
|
|
||||||
RUN \
|
|
||||||
apt-get update && \
|
|
||||||
apt-get upgrade -y
|
|
||||||
|
|
||||||
RUN \
|
|
||||||
addgroup --gid "${GID}" build && \
|
|
||||||
adduser \
|
|
||||||
--disabled-password \
|
|
||||||
--gecos "" \
|
|
||||||
--ingroup build \
|
|
||||||
--uid "${UID}" \
|
|
||||||
--home /opt/build \
|
|
||||||
build
|
|
||||||
|
|
||||||
ADD https://sh.rustup.rs /opt/build/rustup.sh
|
|
||||||
|
|
||||||
RUN \
|
|
||||||
chown -R build:build /opt/build
|
|
||||||
|
|
||||||
USER build
|
|
||||||
WORKDIR /opt/build
|
|
||||||
|
|
||||||
ENV PATH=/opt/build/.cargo/bin:/usr/local/musl/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
|
||||||
|
|
||||||
RUN \
|
|
||||||
chmod +x rustup.sh && \
|
|
||||||
./rustup.sh --default-toolchain $TOOLCHAIN --profile minimal -y && \
|
|
||||||
rustup target add $TARGET
|
|
||||||
|
|
||||||
FROM x86_64-builder as builder
|
|
||||||
|
|
||||||
ARG TAG=main
|
|
||||||
ARG REPOSITORY=https://git.asonix.dog/asonix/warriors-names
|
|
||||||
ARG BINARY=warriors-names
|
|
||||||
|
|
||||||
RUN \
|
|
||||||
git clone -b $TAG $REPOSITORY repo
|
|
||||||
|
|
||||||
WORKDIR /opt/build/repo
|
|
||||||
|
|
||||||
RUN \
|
|
||||||
cargo build --release --target $TARGET && \
|
|
||||||
$TOOL-strip target/$TARGET/release/$BINARY
|
|
||||||
|
|
||||||
FROM amd64/alpine:3.11
|
|
||||||
|
|
||||||
ARG UID=991
|
|
||||||
ARG GID=991
|
|
||||||
ARG BINARY=warriors-names
|
|
||||||
|
|
||||||
COPY --from=builder /opt/build/repo/target/x86_64-unknown-linux-musl/release/$BINARY /usr/bin/$BINARY
|
|
||||||
|
|
||||||
RUN \
|
|
||||||
apk add tini && \
|
|
||||||
addgroup -g $GID warriors && \
|
|
||||||
adduser -D -G warriors -u $UID -g "" -h /opt/warriors warriors
|
|
||||||
|
|
||||||
RUN \
|
|
||||||
chown -R warriors:warriors /mnt
|
|
||||||
|
|
||||||
VOLUME /mnt
|
|
||||||
WORKDIR /opt/warriors
|
|
||||||
USER warriors
|
|
||||||
ENTRYPOINT ["/sbin/tini", "--"]
|
|
||||||
CMD ["/usr/bin/warriors-names"]
|
|
|
@ -1,74 +0,0 @@
|
||||||
FROM rustembedded/cross:arm-unknown-linux-musleabihf AS arm32v7-builder
|
|
||||||
|
|
||||||
ARG UID=991
|
|
||||||
ARG GID=991
|
|
||||||
|
|
||||||
ENV TOOLCHAIN=stable
|
|
||||||
ENV TARGET=arm-unknown-linux-musleabihf
|
|
||||||
ENV TOOL=arm-linux-musleabihf
|
|
||||||
|
|
||||||
RUN \
|
|
||||||
apt-get update && \
|
|
||||||
apt-get upgrade -y
|
|
||||||
|
|
||||||
RUN \
|
|
||||||
addgroup --gid "${GID}" build && \
|
|
||||||
adduser \
|
|
||||||
--disabled-password \
|
|
||||||
--gecos "" \
|
|
||||||
--ingroup build \
|
|
||||||
--uid "${UID}" \
|
|
||||||
--home /opt/build \
|
|
||||||
build
|
|
||||||
|
|
||||||
ADD https://sh.rustup.rs /opt/build/rustup.sh
|
|
||||||
|
|
||||||
RUN \
|
|
||||||
chown -R build:build /opt/build
|
|
||||||
|
|
||||||
USER build
|
|
||||||
WORKDIR /opt/build
|
|
||||||
|
|
||||||
ENV PATH=/opt/build/.cargo/bin:/usr/local/musl/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
|
||||||
|
|
||||||
RUN \
|
|
||||||
chmod +x rustup.sh && \
|
|
||||||
./rustup.sh --default-toolchain $TOOLCHAIN --profile minimal -y && \
|
|
||||||
rustup target add $TARGET
|
|
||||||
|
|
||||||
FROM arm32v7-builder as builder
|
|
||||||
|
|
||||||
ARG TAG=main
|
|
||||||
ARG REPOSITORY=https://git.asonix.dog/asonix/warriors-names
|
|
||||||
ARG BINARY=warriors-names
|
|
||||||
|
|
||||||
RUN \
|
|
||||||
git clone -b $TAG $REPOSITORY repo
|
|
||||||
|
|
||||||
WORKDIR /opt/build/repo
|
|
||||||
|
|
||||||
RUN \
|
|
||||||
cargo build --release --target $TARGET && \
|
|
||||||
$TOOL-strip target/$TARGET/release/$BINARY
|
|
||||||
|
|
||||||
FROM arm32v7/alpine:3.11
|
|
||||||
|
|
||||||
ARG UID=991
|
|
||||||
ARG GID=991
|
|
||||||
ARG BINARY=warriors-names
|
|
||||||
|
|
||||||
COPY --from=builder /opt/build/repo/target/arm-unknown-linux-musleabihf/release/$BINARY /usr/bin/$BINARY
|
|
||||||
|
|
||||||
RUN \
|
|
||||||
apk add tini && \
|
|
||||||
addgroup -g $GID warriors && \
|
|
||||||
adduser -D -G warriors -u $UID -g "" -h /opt/warriors warriors
|
|
||||||
|
|
||||||
RUN \
|
|
||||||
chown -R warriors:warriors /mnt
|
|
||||||
|
|
||||||
VOLUME /mnt
|
|
||||||
WORKDIR /opt/warriors
|
|
||||||
USER warriors
|
|
||||||
ENTRYPOINT ["/sbin/tini", "--"]
|
|
||||||
CMD ["/usr/bin/warriors-names"]
|
|
|
@ -1,74 +0,0 @@
|
||||||
FROM rustembedded/cross:aarch64-unknown-linux-musl AS aarch64-builder
|
|
||||||
|
|
||||||
ARG UID=991
|
|
||||||
ARG GID=991
|
|
||||||
|
|
||||||
ENV TOOLCHAIN=stable
|
|
||||||
ENV TARGET=aarch64-unknown-linux-musl
|
|
||||||
ENV TOOL=aarch64-linux-musl
|
|
||||||
|
|
||||||
RUN \
|
|
||||||
apt-get update && \
|
|
||||||
apt-get upgrade -y
|
|
||||||
|
|
||||||
RUN \
|
|
||||||
addgroup --gid "${GID}" build && \
|
|
||||||
adduser \
|
|
||||||
--disabled-password \
|
|
||||||
--gecos "" \
|
|
||||||
--ingroup build \
|
|
||||||
--uid "${UID}" \
|
|
||||||
--home /opt/build \
|
|
||||||
build
|
|
||||||
|
|
||||||
ADD https://sh.rustup.rs /opt/build/rustup.sh
|
|
||||||
|
|
||||||
RUN \
|
|
||||||
chown -R build:build /opt/build
|
|
||||||
|
|
||||||
USER build
|
|
||||||
WORKDIR /opt/build
|
|
||||||
|
|
||||||
ENV PATH=/opt/build/.cargo/bin:/usr/local/musl/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
|
||||||
|
|
||||||
RUN \
|
|
||||||
chmod +x rustup.sh && \
|
|
||||||
./rustup.sh --default-toolchain $TOOLCHAIN --profile minimal -y && \
|
|
||||||
rustup target add $TARGET
|
|
||||||
|
|
||||||
FROM aarch64-builder as builder
|
|
||||||
|
|
||||||
ARG TAG=main
|
|
||||||
ARG REPOSITORY=https://git.asonix.dog/asonix/warriors-names
|
|
||||||
ARG BINARY=warriors-names
|
|
||||||
|
|
||||||
RUN \
|
|
||||||
git clone -b $TAG $REPOSITORY repo
|
|
||||||
|
|
||||||
WORKDIR /opt/build/repo
|
|
||||||
|
|
||||||
RUN \
|
|
||||||
cargo build --release --target $TARGET && \
|
|
||||||
$TOOL-strip target/$TARGET/release/$BINARY
|
|
||||||
|
|
||||||
FROM arm64v8/alpine:3.11
|
|
||||||
|
|
||||||
ARG UID=991
|
|
||||||
ARG GID=991
|
|
||||||
ARG BINARY=warriors-names
|
|
||||||
|
|
||||||
COPY --from=builder /opt/build/repo/target/aarch64-unknown-linux-musl/release/$BINARY /usr/bin/$BINARY
|
|
||||||
|
|
||||||
RUN \
|
|
||||||
apk add tini && \
|
|
||||||
addgroup -g $GID warriors && \
|
|
||||||
adduser -D -G warriors -u $UID -g "" -h /opt/warriors warriors
|
|
||||||
|
|
||||||
RUN \
|
|
||||||
chown -R warriors:warriors /mnt
|
|
||||||
|
|
||||||
VOLUME /mnt
|
|
||||||
WORKDIR /opt/warriors
|
|
||||||
USER warriors
|
|
||||||
ENTRYPOINT ["/sbin/tini", "--"]
|
|
||||||
CMD ["/usr/bin/warriors-names"]
|
|
|
@ -1,76 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
function require() {
|
|
||||||
if [ "$1" = "" ]; then
|
|
||||||
echo "input '$2' required"
|
|
||||||
print_help
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function print_help() {
|
|
||||||
echo "deploy.sh"
|
|
||||||
echo ""
|
|
||||||
echo "Usage:"
|
|
||||||
echo " deploy.sh [tag]"
|
|
||||||
echo ""
|
|
||||||
echo "Args:"
|
|
||||||
echo " tag: The git tag to be applied to the repository and docker build"
|
|
||||||
echo " branch: The git branch to use for tagging and publishing"
|
|
||||||
}
|
|
||||||
|
|
||||||
function build_image() {
|
|
||||||
tag=$1
|
|
||||||
arch=$2
|
|
||||||
|
|
||||||
docker build \
|
|
||||||
--pull \
|
|
||||||
--build-arg TAG=$tag \
|
|
||||||
-t asonix/warriors-names:$arch-$tag \
|
|
||||||
-t asonix/warriors-names:$arch-latest \
|
|
||||||
-f Dockerfile.$arch \
|
|
||||||
.
|
|
||||||
|
|
||||||
docker push asonix/warriors-names:$arch-$tag
|
|
||||||
docker push asonix/warriors-names:$arch-latest
|
|
||||||
}
|
|
||||||
|
|
||||||
# Creating the new tag
|
|
||||||
new_tag="$1"
|
|
||||||
branch="$2"
|
|
||||||
|
|
||||||
require "$new_tag" "tag"
|
|
||||||
require "$branch" "branch"
|
|
||||||
|
|
||||||
if ! docker run --rm -it arm64v8/alpine:3.11 /bin/sh -c 'echo "docker is configured correctly"'
|
|
||||||
then
|
|
||||||
echo "docker is not configured to run on qemu-emulated architectures, fixing will require sudo"
|
|
||||||
sudo docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
|
|
||||||
fi
|
|
||||||
|
|
||||||
set -xe
|
|
||||||
|
|
||||||
git checkout $branch
|
|
||||||
|
|
||||||
# Changing the docker-compose prod
|
|
||||||
sed -i "s/asonix\/warriors-names:.*/asonix\/warriors-names:$new_tag/" docker-compose.yml
|
|
||||||
git add ../prod/docker-compose.yml
|
|
||||||
|
|
||||||
# The commit
|
|
||||||
git commit -m"Version $new_tag"
|
|
||||||
git tag $new_tag
|
|
||||||
|
|
||||||
# Push
|
|
||||||
git push origin $new_tag
|
|
||||||
git push
|
|
||||||
|
|
||||||
# Build for arm64v8, arm32v7, and amd64
|
|
||||||
build_image $new_tag arm64v8
|
|
||||||
build_image $new_tag arm32v7
|
|
||||||
build_image $new_tag amd64
|
|
||||||
|
|
||||||
# Build for other archs
|
|
||||||
# TODO
|
|
||||||
|
|
||||||
./manifest.sh asonix/warriors-names $new_tag
|
|
||||||
./manifest.sh asonix/warriors-names latest
|
|
|
@ -2,7 +2,7 @@ version: '3.3'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
warriors-names:
|
warriors-names:
|
||||||
image: asonix/warriors-names:v0.1.4
|
image: asonix/warriors-names:v0.2.1
|
||||||
restart: always
|
restart: always
|
||||||
volumes:
|
volumes:
|
||||||
- ./volumes/warriors-names:/opt/warriors
|
- ./volumes/warriors-names:/opt/warriors
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
function require() {
|
|
||||||
if [ "$1" = "" ]; then
|
|
||||||
echo "input '$2' required"
|
|
||||||
print_help
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
function print_help() {
|
|
||||||
echo "deploy.sh"
|
|
||||||
echo ""
|
|
||||||
echo "Usage:"
|
|
||||||
echo " manifest.sh [repository] [tag]"
|
|
||||||
echo ""
|
|
||||||
echo "Args:"
|
|
||||||
echo " repository: The docker repository hosting the images"
|
|
||||||
echo " tag: The git tag to be applied to the image manifest"
|
|
||||||
}
|
|
||||||
|
|
||||||
repo=$1
|
|
||||||
new_tag=$2
|
|
||||||
|
|
||||||
require "$repo" "repository"
|
|
||||||
require "$new_tag" "tag"
|
|
||||||
|
|
||||||
set -xe
|
|
||||||
|
|
||||||
docker manifest create $repo:$new_tag \
|
|
||||||
-a $repo:arm64v8-$new_tag \
|
|
||||||
-a $repo:arm32v7-$new_tag \
|
|
||||||
-a $repo:amd64-$new_tag
|
|
||||||
|
|
||||||
docker manifest annotate $repo:$new_tag \
|
|
||||||
$repo:arm64v8-$new_tag --os linux --arch arm64 --variant v8
|
|
||||||
|
|
||||||
docker manifest annotate $repo:$new_tag \
|
|
||||||
$repo:arm32v7-$new_tag --os linux --arch arm --variant v7
|
|
||||||
|
|
||||||
docker manifest annotate $repo:$new_tag \
|
|
||||||
$repo:amd64-$new_tag --os linux --arch amd64
|
|
||||||
|
|
||||||
docker manifest push $repo:$new_tag --purge
|
|
61
flake.lock
Normal file
61
flake.lock
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"flake-utils": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1705309234,
|
||||||
|
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1707546158,
|
||||||
|
"narHash": "sha256-nYYJTpzfPMDxI8mzhQsYjIUX+grorqjKEU9Np6Xwy/0=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "d934204a0f8d9198e1e4515dd6fec76a139c87f0",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"systems": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
34
flake.nix
Normal file
34
flake.nix
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
{
|
||||||
|
description = "warriors-names";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = { self, nixpkgs, flake-utils }:
|
||||||
|
flake-utils.lib.eachDefaultSystem (system:
|
||||||
|
let
|
||||||
|
pkgs = import nixpkgs {
|
||||||
|
inherit system;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
packages = rec {
|
||||||
|
warriors-names = pkgs.callPackage ./warriors-names.nix { };
|
||||||
|
|
||||||
|
default = warriors-names;
|
||||||
|
};
|
||||||
|
|
||||||
|
apps = rec {
|
||||||
|
dev = flake-utils.lib.mkApp { drv = self.packages.${system}.warriors-names; };
|
||||||
|
default = dev;
|
||||||
|
};
|
||||||
|
|
||||||
|
devShell = with pkgs; mkShell {
|
||||||
|
nativeBuildInputs = [ cargo cargo-outdated clippy gcc rust-analyzer rustc rustfmt ];
|
||||||
|
|
||||||
|
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
|
@ -9,7 +9,7 @@ fn select(variants: &HashSet<String>, weights: &[(u64, String)], rng: &mut impl
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let total = filtered.iter().fold(0, |acc, (weight, _)| acc + weight);
|
let total = filtered.iter().fold(0, |acc, (weight, _)| acc + weight);
|
||||||
let selected = rng.gen_range(0, total);
|
let selected = rng.gen_range(0..total);
|
||||||
|
|
||||||
let (s, _) = filtered
|
let (s, _) = filtered
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -46,24 +46,37 @@ struct Entry {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Entry {
|
impl Entry {
|
||||||
fn gen(
|
fn gen<'a, 'b>(
|
||||||
&self,
|
&'a self,
|
||||||
weights: Option<&[(u64, String)]>,
|
weights: Option<&[(u64, String)]>,
|
||||||
entries: &[Entry],
|
entries: &'a [Entry],
|
||||||
|
forbids: &'b mut Vec<Vec<&'a Forbid>>,
|
||||||
rng: &mut impl Rng,
|
rng: &mut impl Rng,
|
||||||
) -> String {
|
) -> String
|
||||||
|
where
|
||||||
|
'a: 'b,
|
||||||
|
{
|
||||||
let variant = self.gen_variant(weights, rng);
|
let variant = self.gen_variant(weights, rng);
|
||||||
|
|
||||||
let building = self.gen_depends(&variant, entries, rng);
|
if forbids.iter().any(|f| {
|
||||||
|
f.iter()
|
||||||
|
.any(|f| f.name == self.name && f.variants.contains(&variant))
|
||||||
|
}) {
|
||||||
|
return String::new();
|
||||||
|
}
|
||||||
|
|
||||||
|
let building = self.gen_depends(&variant, entries, forbids, rng);
|
||||||
|
|
||||||
let mut seen = HashSet::new();
|
let mut seen = HashSet::new();
|
||||||
seen.insert(variant.clone());
|
seen.insert(variant.clone());
|
||||||
self.gen_next(building, &variant, weights, entries, &mut seen, rng)
|
self.gen_next(
|
||||||
|
building, &variant, weights, entries, forbids, &mut seen, rng,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gen_variant(&self, weights: Option<&[(u64, String)]>, rng: &mut impl Rng) -> String {
|
fn gen_variant(&self, weights: Option<&[(u64, String)]>, rng: &mut impl Rng) -> String {
|
||||||
if let Some(weights) = weights {
|
if let Some(weights) = weights {
|
||||||
return select(&self.variants, &weights, rng);
|
return select(&self.variants, weights, rng);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.variants
|
self.variants
|
||||||
|
@ -74,27 +87,41 @@ impl Entry {
|
||||||
.to_string()
|
.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gen_depends(&self, variant: &str, entries: &[Entry], rng: &mut impl Rng) -> String {
|
fn gen_depends<'a, 'b>(
|
||||||
|
&'a self,
|
||||||
|
variant: &str,
|
||||||
|
entries: &'a [Entry],
|
||||||
|
forbids: &'b mut Vec<Vec<&'a Forbid>>,
|
||||||
|
rng: &mut impl Rng,
|
||||||
|
) -> String
|
||||||
|
where
|
||||||
|
'a: 'b,
|
||||||
|
{
|
||||||
let base = if self.silent.contains(variant) {
|
let base = if self.silent.contains(variant) {
|
||||||
String::new()
|
String::new()
|
||||||
} else {
|
} else {
|
||||||
variant.to_string()
|
variant.to_string()
|
||||||
};
|
};
|
||||||
|
|
||||||
self.depends
|
self.depends.iter().fold(base, |acc, depend| {
|
||||||
.iter()
|
depend.gen(acc, variant, entries, forbids, rng)
|
||||||
.fold(base, |acc, depend| depend.gen(acc, variant, entries, rng))
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gen_next(
|
#[allow(clippy::too_many_arguments)]
|
||||||
&self,
|
fn gen_next<'a, 'b>(
|
||||||
|
&'a self,
|
||||||
building: String,
|
building: String,
|
||||||
variant: &str,
|
variant: &str,
|
||||||
weights: Option<&[(u64, String)]>,
|
weights: Option<&[(u64, String)]>,
|
||||||
entries: &[Entry],
|
entries: &'a [Entry],
|
||||||
|
forbids: &'b mut Vec<Vec<&'a Forbid>>,
|
||||||
seen: &mut HashSet<String>,
|
seen: &mut HashSet<String>,
|
||||||
rng: &mut impl Rng,
|
rng: &mut impl Rng,
|
||||||
) -> String {
|
) -> String
|
||||||
|
where
|
||||||
|
'a: 'b,
|
||||||
|
{
|
||||||
let (s, _, _) = self.next.iter().fold(
|
let (s, _, _) = self.next.iter().fold(
|
||||||
(building, variant.to_string(), seen),
|
(building, variant.to_string(), seen),
|
||||||
|(acc, v, seen), next| {
|
|(acc, v, seen), next| {
|
||||||
|
@ -103,11 +130,11 @@ impl Entry {
|
||||||
return (acc, variant, seen);
|
return (acc, variant, seen);
|
||||||
}
|
}
|
||||||
seen.insert(variant.clone());
|
seen.insert(variant.clone());
|
||||||
|
let depends = self.gen_depends(&variant, entries, forbids, rng);
|
||||||
let depends = self.gen_depends(&variant, entries, rng);
|
|
||||||
let building = next.join(acc, &depends);
|
let building = next.join(acc, &depends);
|
||||||
|
|
||||||
let building = self.gen_next(building, &variant, weights, entries, seen, rng);
|
let building =
|
||||||
|
self.gen_next(building, &variant, weights, entries, forbids, seen, rng);
|
||||||
|
|
||||||
return (building, variant, seen);
|
return (building, variant, seen);
|
||||||
}
|
}
|
||||||
|
@ -120,6 +147,12 @@ impl Entry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
struct Forbid {
|
||||||
|
name: String,
|
||||||
|
variants: Anyable,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(serde::Deserialize)]
|
#[derive(serde::Deserialize)]
|
||||||
struct Next {
|
struct Next {
|
||||||
from: Anyable,
|
from: Anyable,
|
||||||
|
@ -206,10 +239,23 @@ struct Depend {
|
||||||
order: String,
|
order: String,
|
||||||
weights: Option<Vec<(u64, String)>>,
|
weights: Option<Vec<(u64, String)>>,
|
||||||
default: Option<String>,
|
default: Option<String>,
|
||||||
|
|
||||||
|
#[serde(default)]
|
||||||
|
forbids: Vec<Forbid>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Depend {
|
impl Depend {
|
||||||
fn gen(&self, acc: String, variant: &str, entries: &[Entry], rng: &mut impl Rng) -> String {
|
fn gen<'a, 'b>(
|
||||||
|
&'a self,
|
||||||
|
acc: String,
|
||||||
|
variant: &str,
|
||||||
|
entries: &'a [Entry],
|
||||||
|
forbids: &'b mut Vec<Vec<&'a Forbid>>,
|
||||||
|
rng: &mut impl Rng,
|
||||||
|
) -> String
|
||||||
|
where
|
||||||
|
'a: 'b,
|
||||||
|
{
|
||||||
if !self.variants.contains(variant) {
|
if !self.variants.contains(variant) {
|
||||||
return acc;
|
return acc;
|
||||||
}
|
}
|
||||||
|
@ -225,17 +271,27 @@ impl Depend {
|
||||||
return acc;
|
return acc;
|
||||||
}
|
}
|
||||||
|
|
||||||
let entry = entries
|
let local_forbids = self.forbids.iter().collect();
|
||||||
.into_iter()
|
|
||||||
.find(|entry| entry.name == self.depends)
|
|
||||||
.expect(&format!("Missing entry for {}", self.depends));
|
|
||||||
|
|
||||||
let value = entry.gen(self.weights.as_ref().map(Vec::as_slice), entries, rng);
|
forbids.push(local_forbids);
|
||||||
|
|
||||||
|
let entry = entries
|
||||||
|
.iter()
|
||||||
|
.find(|entry| entry.name == self.depends)
|
||||||
|
.unwrap_or_else(|| panic!("Missing entry for {}", self.depends));
|
||||||
|
|
||||||
|
let value = entry.gen(self.weights.as_deref(), entries, forbids, rng);
|
||||||
|
|
||||||
|
forbids.pop();
|
||||||
|
|
||||||
if acc.is_empty() {
|
if acc.is_empty() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if value.is_empty() {
|
||||||
|
return acc;
|
||||||
|
}
|
||||||
|
|
||||||
self.join(acc, &value)
|
self.join(acc, &value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,9 +314,11 @@ impl Config {
|
||||||
.entries
|
.entries
|
||||||
.iter()
|
.iter()
|
||||||
.find(|entry| entry.name == self.root)
|
.find(|entry| entry.name == self.root)
|
||||||
.expect(&format!("Invalid config: no entry called {}", self.root));
|
.unwrap_or_else(|| panic!("Invalid config: no entry called {}", self.root));
|
||||||
|
|
||||||
root.gen(None, &self.entries, rng)
|
let mut forbids = Vec::new();
|
||||||
|
|
||||||
|
root.gen(None, &self.entries, &mut forbids, rng)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
27
src/main.rs
27
src/main.rs
|
@ -2,8 +2,7 @@ use anyhow::{anyhow, Result};
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
use reqwest::{header::HeaderMap, Client};
|
use reqwest::{header::HeaderMap, Client};
|
||||||
use std::{path::Path, time::Duration};
|
use std::{path::Path, time::Duration};
|
||||||
use tokio::{fs::File, prelude::*, time::interval};
|
use tokio::{fs::File, io::AsyncReadExt, io::AsyncWriteExt, time::interval};
|
||||||
use tokio_compat_02::FutureExt;
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
mod description;
|
mod description;
|
||||||
|
@ -79,7 +78,6 @@ impl Mastodon {
|
||||||
scope: "read write",
|
scope: "read write",
|
||||||
})
|
})
|
||||||
.send()
|
.send()
|
||||||
.compat()
|
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if !res.status().is_success() {
|
if !res.status().is_success() {
|
||||||
|
@ -89,38 +87,38 @@ impl Mastodon {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let token: Token = res.json().compat().await?;
|
let token: Token = res.json().await?;
|
||||||
Ok(token)
|
Ok(token)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn read_token(path: impl AsRef<Path>) -> Result<Token> {
|
async fn read_token(path: impl AsRef<Path>) -> Result<Token> {
|
||||||
let mut file = File::open(path).await?;
|
let mut file = File::open(path).await?;
|
||||||
let mut contents = vec![];
|
let mut contents = String::new();
|
||||||
file.read_to_end(&mut contents).await?;
|
file.read_to_string(&mut contents).await?;
|
||||||
|
|
||||||
let token: Token = toml::from_slice(&contents)?;
|
let token: Token = toml::from_str(&contents)?;
|
||||||
Ok(token)
|
Ok(token)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn write_token(path: impl AsRef<Path>, token: &Token) -> Result<()> {
|
async fn write_token(path: impl AsRef<Path>, token: &Token) -> Result<()> {
|
||||||
let token_bytes = toml::to_vec(token)?;
|
let token_bytes = toml::to_string(token)?;
|
||||||
let mut file = File::create(path).await?;
|
let mut file = File::create(path).await?;
|
||||||
file.write_all(&token_bytes).await?;
|
file.write_all(token_bytes.as_bytes()).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
async fn open(path: impl AsRef<Path>) -> Result<Self> {
|
async fn open(path: impl AsRef<Path>) -> Result<Self> {
|
||||||
let mut file = File::open(path).await?;
|
let mut file = File::open(path).await?;
|
||||||
let mut contents = vec![];
|
let mut contents = String::new();
|
||||||
file.read_to_end(&mut contents).await?;
|
file.read_to_string(&mut contents).await?;
|
||||||
|
|
||||||
let config: Config = toml::from_slice(&contents)?;
|
let config: Config = toml::from_str(&contents)?;
|
||||||
Ok(config)
|
Ok(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn to_state(
|
async fn into_state(
|
||||||
self,
|
self,
|
||||||
token_path: impl AsRef<Path>,
|
token_path: impl AsRef<Path>,
|
||||||
name: name::Config,
|
name: name::Config,
|
||||||
|
@ -175,7 +173,6 @@ impl State {
|
||||||
visibility: "unlisted",
|
visibility: "unlisted",
|
||||||
})
|
})
|
||||||
.send()
|
.send()
|
||||||
.compat()
|
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if !res.status().is_success() {
|
if !res.status().is_success() {
|
||||||
|
@ -202,7 +199,7 @@ async fn main() -> Result<()> {
|
||||||
let duration = Duration::from_secs(60) * config.timing.duration;
|
let duration = Duration::from_secs(60) * config.timing.duration;
|
||||||
let mut ticker = interval(duration);
|
let mut ticker = interval(duration);
|
||||||
|
|
||||||
let state = config.to_state("Token.toml", name, description).await?;
|
let state = config.into_state("Token.toml", name, description).await?;
|
||||||
|
|
||||||
let mut rng = thread_rng();
|
let mut rng = thread_rng();
|
||||||
loop {
|
loop {
|
||||||
|
|
21
warriors-names.nix
Normal file
21
warriors-names.nix
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
{ lib
|
||||||
|
, nixosTests
|
||||||
|
, rustPlatform
|
||||||
|
}:
|
||||||
|
|
||||||
|
rustPlatform.buildRustPackage {
|
||||||
|
pname = "warriors-names";
|
||||||
|
version = "0.2.3";
|
||||||
|
src = ./.;
|
||||||
|
cargoLock.lockFile = ./Cargo.lock;
|
||||||
|
|
||||||
|
nativeBuildInputs = [ ];
|
||||||
|
|
||||||
|
passthru.tests = { inherit (nixosTests) warriors-names; };
|
||||||
|
|
||||||
|
meta = with lib; {
|
||||||
|
description = "A simple image hosting service";
|
||||||
|
homepage = "https://git.asonix.dog/asonix/warriors-names";
|
||||||
|
license = with licenses; [ agpl3Plus ];
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in a new issue