Skip to content

Commit

Permalink
rewrote it in rust; changed from loose json to sqlite; changed output…
Browse files Browse the repository at this point in the history
… file format from pdf to cbz to add tags
  • Loading branch information
9FS committed Sep 9, 2024
1 parent e1be3c4 commit f13d9d1
Show file tree
Hide file tree
Showing 33 changed files with 4,776 additions and 1,391 deletions.
15 changes: 7 additions & 8 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
*.exe
*.log
*.pyc
*.token

.hypothesis/
.pytest_cache/
config/
doc_templates/
log/
/config/
/db/
/doc_templates/
/hentai/
/log/
/target/

.env
docker-image.tar
tests/test.py
rustfmt.toml
237 changes: 237 additions & 0 deletions .github/workflows/on tag deploy on GitHub.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
name: "On Tag Deploy on GitHub"
env:
REPO_NAME: "nhentai_archivist"
RUN_TESTS: true
RUST_VERSION: "1.80"
on:
push:
tags:
# - "[0-9]+.[0-9]+.[0-9]+"
- "*" # execute every time tag is pushed


jobs:
datetime:
name: "Get Current Datetime"
env:
working-directory: ${{github.workspace}}
runs-on: "ubuntu-latest"

steps:
- name: "NOW"
id: "now"
run: "echo \"NOW=$(date +'%Y-%m-%dT%H:%M:%S')\" >> $GITHUB_OUTPUT" # get datetime, save in NOW, push to output

- name: "TODAY"
id: "today"
run: "echo \"TODAY=$(date +'%Y-%m-%d')\" >> $GITHUB_OUTPUT" # get date, save in TODAY, push to output

outputs: # set step output as job output so other jobs can access
NOW: ${{steps.now.outputs.NOW}}
TODAY: ${{steps.today.outputs.TODAY}}


test:
name: "Run Tests"
env:
working-directory: ${{github.workspace}}
runs-on: "ubuntu-latest"

steps:
- name: "Checkout Repository"
uses: "actions/checkout@v4" # makes repository structure available

- name: "Install Rust"
uses: "actions-rust-lang/setup-rust-toolchain@v1"
with:
toolchain: ${{env.RUST_VERSION}}

- name: "Check Project Version and Tag Match"
run: |
project_version=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')
tag=${GITHUB_REF#refs/tags/*}
if [ "$project_version" == "$tag" ]; then
exit 0
else
exit 1
fi
- name: "Run Tests"
if: ${{env.RUN_TESTS == 'true'}}
run: "cargo test"


create_release:
name: "Create Release on GitHub"
env:
working-directory: ${{github.workspace}}
needs: ["datetime", "test"]
runs-on: "ubuntu-latest"

steps:
- name: "Create Release"
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
id: "create_release"
uses: "actions/create-release@v1" # function that creates release
with: # parameters
body: # release text
draft: false
prerelease: false
release_name: "${{needs.datetime.outputs.TODAY}} ${{env.REPO_NAME}} ${{github.ref}}" # release title
tag_name: ${{github.ref}} # release tag

outputs:
github_release: ${{steps.create_release.outputs.upload_url}}


build_executables:
name: "Build Executable for ${{matrix.os}}"
env:
working-directory: ${{github.workspace}}
runs-on: "ubuntu-latest"
strategy:
matrix:
os: ["x86_64-unknown-linux-gnu", "x86_64-pc-windows-gnu"]

steps:
- name: "Checkout Repository"
uses: "actions/checkout@v4" # makes repository structure available

- name: "Install Rust"
uses: "actions-rust-lang/setup-rust-toolchain@v1"
with:
target: ${{matrix.os}}
toolchain: ${{env.RUST_VERSION}}

- name: "Install cross" # install cross for cross-compilation
run: "cargo install cross"

- name: "Compile"
run: "cross build --release --target ${{matrix.os}}"

- name: "Cache Executable"
if: ${{matrix.os != 'x86_64-pc-windows-gnu'}}
uses: "actions/cache/save@v4"
with:
key: ${{matrix.os}}
path: "./target/${{matrix.os}}/release/${{env.REPO_NAME}}"

- name: "Cache Executable"
if: ${{matrix.os == 'x86_64-pc-windows-gnu'}}
uses: "actions/cache/save@v4"
with:
key: ${{matrix.os}}
path: "./target/${{matrix.os}}/release/${{env.REPO_NAME}}.exe" # windows executable has .exe extension


build_docker_image:
name: "Build Docker Image"
env:
working-directory: ${{github.workspace}}
runs-on: "ubuntu-latest"

steps:
- name: "Checkout Repository"
uses: "actions/checkout@v4" # makes repository structure available

- name: "Install Docker"
uses: "docker/setup-buildx-action@v1"

- name: "Create \"./target/\" Directory"
run: "mkdir -p \"./target/\""

- name: "Compile"
run: "IMAGE_NAME=\"9-FS/${{env.REPO_NAME}}:latest\" && docker build -t \"${IMAGE_NAME@L}\" --no-cache ."

- name: "Save Docker Image"
run: "IMAGE_NAME=\"9-FS/${{env.REPO_NAME}}:latest\" && docker save \"${IMAGE_NAME@L}\" > \"./target/docker-image.tar\""

- name: "Cache Docker Image"
uses: "actions/cache/save@v4"
with:
key: "docker"
path: "./target/docker-image.tar"


deploy_executables:
name: "Deploy Executable for ${{matrix.os}} on GitHub"
env:
working-directory: ${{github.workspace}}
needs: ["build_executables", "create_release", "datetime", "test"]
runs-on: "ubuntu-latest"
strategy:
matrix:
os: ["x86_64-unknown-linux-gnu", "x86_64-pc-windows-gnu"]

steps:
- name: "Load Executable"
if: ${{matrix.os != 'x86_64-pc-windows-gnu'}}
uses: "actions/cache/restore@v4"
with:
key: ${{matrix.os}}
path: "./target/${{matrix.os}}/release/${{env.REPO_NAME}}"

- name: "Load Executable"
if: ${{matrix.os == 'x86_64-pc-windows-gnu'}}
uses: "actions/cache/restore@v4"
with:
key: ${{matrix.os}}
path: "./target/${{matrix.os}}/release/${{env.REPO_NAME}}.exe"

- name: "Parse Tag"
id: "parse_tag"
run: "echo \"tag=${GITHUB_REF#refs/tags/*}\" >> $GITHUB_OUTPUT" # parse tag because github.ref provides tag as f"refs/tags/{tag}", in create_release it is parsed automatically idk
shell: "bash" # must be bash even on windows, because command to apply value to variable works differently in powershell

- name: "Attach Executable to Release"
if: ${{matrix.os != 'x86_64-pc-windows-gnu'}}
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
uses: "actions/upload-release-asset@v1"
with:
asset_content_type: "application"
asset_name: "${{needs.datetime.outputs.TODAY}} ${{env.REPO_NAME}} ${{steps.parse_tag.outputs.tag}} ${{matrix.os}}"
asset_path: "./target/${{matrix.os}}/release/${{env.REPO_NAME}}"
upload_url: ${{needs.create_release.outputs.github_release}}

- name: "Attach Executable to Release"
if: ${{matrix.os == 'x86_64-pc-windows-gnu'}}
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
uses: "actions/upload-release-asset@v1"
with:
asset_content_type: "application"
asset_name: "${{needs.datetime.outputs.TODAY}} ${{env.REPO_NAME}} ${{steps.parse_tag.outputs.tag}} ${{matrix.os}}.exe"
asset_path: "./target/${{matrix.os}}/release/${{env.REPO_NAME}}.exe"
upload_url: ${{needs.create_release.outputs.github_release}}


deploy_docker_image:
name: "Deploy Docker Image on GitHub"
env:
working-directory: ${{github.workspace}}
needs: ["build_docker_image", "create_release", "datetime", "test"]
runs-on: "ubuntu-latest"

steps:
- name: "Load Docker Image"
uses: "actions/cache/restore@v4"
with:
key: "docker"
path: "./target/docker-image.tar"

- name: "Parse Tag"
id: "parse_tag"
run: "echo \"tag=${GITHUB_REF#refs/tags/*}\" >> $GITHUB_OUTPUT" # parse tag because github.ref provides tag as f"refs/tags/{tag}", in create_release it is parsed automatically idk
shell: "bash" # must be bash even on windows, because command to apply value to variable works differently in powershell

- name: "Attach Docker Image to Release"
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
uses: "actions/upload-release-asset@v1"
with:
asset_content_type: "application"
asset_name: "${{needs.datetime.outputs.TODAY}} ${{env.REPO_NAME}} ${{steps.parse_tag.outputs.tag}} docker.tar"
asset_path: "./target/docker-image.tar"
upload_url: ${{needs.create_release.outputs.github_release}}
Loading

0 comments on commit f13d9d1

Please sign in to comment.