Skip to content

fixed error 404 during test connection could effectively cripple nhen… #18

fixed error 404 during test connection could effectively cripple nhen…

fixed error 404 during test connection could effectively cripple nhen… #18

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:
initialisation:
name: "Initialisation"
env:
working-directory: ${{github.workspace}}
runs-on: "ubuntu-latest"
steps:
- name: "Checkout Repository"
uses: "actions/checkout@v4" # makes repository structure available
with:
fetch-depth: 0 # fetch all commits, so all tags can be accessed
- 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: "TAG"
id: "tag"
run: "echo \"TAG=$(git describe --tags --abbrev=0)\" >> $GITHUB_OUTPUT" # get tag, save in TAG, push to output
- name: "TAG_PREVIOUS"
id: "tag_previous"
run: "echo \"TAG_PREVIOUS=$(git tag --sort=-creatordate | sed -n '2p')\" >> $GITHUB_OUTPUT" # get previous tag, save in TAG_PREVIOUS, 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}}
TAG: ${{steps.tag.outputs.TAG}}
TAG_PREVIOUS: ${{steps.tag_previous.outputs.TAG_PREVIOUS}}
TODAY: ${{steps.today.outputs.TODAY}}
test:
name: "Run Tests"
env:
working-directory: ${{github.workspace}}
needs: ["initialisation"]
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')
if [ "$project_version" == "${{needs.initialisation.outputs.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: ["initialisation", "test"]
runs-on: "ubuntu-latest"
steps:
- name: "Checkout Repository"
uses: "actions/checkout@v4" # makes repository structure available
with:
fetch-depth: 0 # fetch all commits, so we can access all tags
- name: "Generate Changelog"
id: "generate_changelog"
run: |
commit_messages=$(git log --pretty=format:'- %h: %s' '${{needs.initialisation.outputs.TAG_PREVIOUS}}'..'${{needs.initialisation.outputs.TAG}}')
{
echo "changelog<<EOF" # use heredoc to handle multiline output properly
echo "## Changelog"
echo ""
echo "$commit_messages"
echo "EOF"
} >> $GITHUB_OUTPUT
- name: "Create Release"
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
id: "create_release"
uses: "actions/create-release@v1" # function that creates release
with: # parameters
body: ${{steps.generate_changelog.outputs.changelog}} # release text
draft: false
prerelease: false
release_name: "${{needs.initialisation.outputs.TODAY}} ${{env.REPO_NAME}} ${{needs.initialisation.outputs.TAG}}" # 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}}
needs: ["initialisation"]
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: "docker build -t \"ghcr.io/9-fs/${{env.REPO_NAME}}:${{needs.initialisation.outputs.TAG}}\" --no-cache ."
- name: "Save Docker Image"
run: "docker save \"ghcr.io/9-fs/${{env.REPO_NAME}}:${{needs.initialisation.outputs.TAG}}\" > \"./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", "initialisation", "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: "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.initialisation.outputs.TODAY}} ${{env.REPO_NAME}} ${{needs.initialisation.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.initialisation.outputs.TODAY}} ${{env.REPO_NAME}} ${{needs.initialisation.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", "initialisation", "test"]
runs-on: "ubuntu-latest"
steps:
- name: "Load Docker Image"
uses: "actions/cache/restore@v4"
with:
key: "docker"
path: "./target/docker-image.tar"
- 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.initialisation.outputs.TODAY}} ${{env.REPO_NAME}} ${{needs.initialisation.outputs.TAG}} docker.tar"
asset_path: "./target/docker-image.tar"
upload_url: ${{needs.create_release.outputs.github_release}}
- name: "Load Docker Image"
run: "docker load < \"./target/docker-image.tar\""
- name: "Add \"latest\" Tag to Docker Image"
run: "docker tag \"ghcr.io/9-fs/${{env.REPO_NAME}}:${{needs.initialisation.outputs.TAG}}\" \"ghcr.io/9-fs/${{env.REPO_NAME}}:latest\""
- name: "Log In to GitHub Docker Registry"
run: "echo ${{secrets.GITHUB_TOKEN}} | docker login ghcr.io -u \"9-FS\" --password-stdin"
- name: "Push Docker Image to GitHub Docker Registry"
run: "docker push \"ghcr.io/9-fs/${{env.REPO_NAME}}:${{needs.initialisation.outputs.TAG}}\""
- name: "Push Docker Image to GitHub Docker Registry"
run: "docker push \"ghcr.io/9-fs/${{env.REPO_NAME}}:latest\""