stages:
- prepare
- cargo_tests
- platform_build
- deploy
cache: &global_cache
key: ${CI_COMMIT_REF_SLUG}
paths:
- .cargo/bin
- .cargo/registry/index
- .cargo/registry/home
- target
policy: pull-push
variables:
CACHE_HOME: ${CI_PROJECT_DIR}/.cargo
prepare:
stage: prepare
image: "rust:latest"
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- if: $CI_COMMIT_TAG
script:
- echo LABT_VERSION=$(awk -F ' = ' '$1 ~ /^version$/ {gsub(/["]/, "", $2); print($2)}' Cargo.toml) > variables.env
- echo "PKG_REGISTRY_URL=${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic" >> variables.env
- cat variables.env
artifacts:
reports:
dotenv: variables.env
cargo_test:
stage: cargo_tests
image: "rust:latest"
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- if: $CI_COMMIT_TAG
before_script:
- apt-get update -yqq
- apt-get install -yqq --no-install-recommends build-essential
script:
- rustc --version && cargo --version - cargo test --workspace --features vendored-lua
cache:
policy: pull
when: on_success
<<: *global_cache
build_linux:
stage: platform_build
image: "rust:latest"
before_script:
- apt-get update -yqq
- apt-get install -yqq --no-install-recommends build-essential
rules:
- if: $CI_COMMIT_TAG
script:
- echo "=== BUILDING FOR x86_64 linux gnu ==="
- rustup target add x86_64-unknown-linux-gnu
- cargo build --target=x86_64-unknown-linux-gnu --release --features vendored-lua
- mkdir bin
- ls -la
- ls -la target
- mv target/x86_64-unknown-linux-gnu/release/labt bin/labt_v${LABT_VERSION}_x86_64
artifacts:
paths:
- bin/
cache:
policy: pull-push
<< : *global_cache
build_windows:
stage: platform_build
image: "rust:latest"
before_script:
- apt-get update -yqq
- apt-get install -yqq --no-install-recommends build-essential gcc-mingw-w64
- apt-get install -yqq --no-install-recommends nsis zip
- wget https://nsis.sourceforge.io/mediawiki/images/7/7f/EnVar_plugin.zip
- unzip -j EnVar_plugin.zip Plugins/x86-unicode/EnVar.dll -d plugins
- rm EnVar_plugin.zip
rules:
- if: $CI_COMMIT_TAG
script:
- echo "=== BUILDING FOR x86_64 linux gnu ==="
- rustup target add x86_64-pc-windows-gnu
- cargo build --target=x86_64-pc-windows-gnu --release --features vendored-lua
- mkdir bin
- ls -a
- ls -a target
- mv target/x86_64-pc-windows-gnu/release/labt.exe labt.exe
- makensis -DVERSION=${LABT_VERSION} windows-installer.nsi
- mv labt.exe bin/labt_v${LABT_VERSION}_x86_64-windows.exe
- mv labt-v${LABT_VERSION}_x86_64_windows-installer.exe bin/
artifacts:
paths:
- bin/
cache:
policy: pull-push
<< : *global_cache
release_job:
stage: deploy
needs:
- prepare
- build_linux
- build_windows
image: registry.gitlab.com/gitlab-org/release-cli:latest
script: echo "=== CREATING RELEASE ==="
rules:
- if: $CI_COMMIT_TAG
release:
tag_name: "v${LABT_VERSION}"
description: "Lightweight Android Build tool (LABt) v${LABT_VERSION}"
ref: $CI_COMMIT_SHA
assets:
links:
- name: "labt_v${LABT_VERSION}_x86_64_linux"
url: "${PKG_REGISTRY_URL}/x86_64-unknown-linux-gnu/v${LABT_VERSION}/labt"
- name: "labt_v${LABT_VERSION}_x86_64_windows.exe"
url: "${PKG_REGISTRY_URL}/x86_64-pc-windows-gnu/v${LABT_VERSION}/labt.exe"
- name: "labt_v${LABT_VERSION}_x86_64_windows-installer.exe"
url: "${PKG_REGISTRY_URL}/x86_64-pc-windows-gnu/v${LABT_VERSION}/labt-installer.exe"
upload_job:
stage: deploy
image: curlimages/curl:latest
needs:
- prepare
- build_linux
- build_windows
rules:
- if: $CI_COMMIT_TAG
script:
- echo "=== UPLOADING ==="
- ls -a bin/
- 'curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file bin/labt_v${LABT_VERSION}_x86_64 ${PKG_REGISTRY_URL}/x86_64-unknown-linux-gnu/v${LABT_VERSION}/labt'
- 'curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file bin/labt_v${LABT_VERSION}_x86_64-windows.exe ${PKG_REGISTRY_URL}/x86_64-pc-windows-gnu/v${LABT_VERSION}/labt.exe'
- 'curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file bin/labt-v${LABT_VERSION}_x86_64_windows-installer.exe ${PKG_REGISTRY_URL}/x86_64-pc-windows-gnu/v${LABT_VERSION}/labt-installer.exe'