diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..1a592b6 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,101 @@ +name: CI/CD + +on: + push: + tags: [ '*.*.*' ] + branches: [ '*' ] + pull_request: + branches: [ master ] + release: + types: [ published ] + +permissions: + contents: write + id-token: write + packages: write + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v6 + + - name: Setup environment + run: | + git submodule init + git submodule update + + - name: Build + run: | + mkdir ./public-build + docker build --target mpq-extractor-debian -t mpq-extractor-debian . + docker cp $(docker create mpq-extractor-debian):/usr/local/bin/MPQExtractor ./public-build/MPQExtractor + + - name: '"Test"' + run: | + { + echo '```' + # todo replace with `docker run --rm --entrypoint 'bash -c "cmake /src && make tests"' mpq-extractor-builder-debian` in future, + # now just "print help" to prove this thing working. + docker run --rm mpq-extractor-debian -h + echo '```' + } > "$GITHUB_STEP_SUMMARY" + + - name: Save Docker Image to File + run: docker save -o mpq-extractor-debian.tar mpq-extractor-debian + + - name: Upload Image Artifact + uses: actions/upload-artifact@v4 + with: + name: docker-image + path: mpq-extractor-debian.tar + + - name: Upload Binary Artifact + uses: actions/upload-artifact@v4 + with: + name: public-build-artifact + path: ./public-build/ + + publish: + name: Publish + runs-on: ubuntu-latest + needs: [build] + if: startsWith(github.ref, 'refs/tags/') + + steps: + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Download Image Artifact (Docker Image) + uses: actions/download-artifact@v4 + with: + name: docker-image + + - name: Load Image and Push to GHCR + run: | + docker load -i mpq-extractor-debian.tar + + docker tag mpq-extractor-debian ghcr.io/${{ github.repository_owner }}/mpq-extractor-debian:${{ github.ref_name }} + docker tag mpq-extractor-debian ghcr.io/${{ github.repository_owner }}/mpq-extractor-debian:latest + docker push ghcr.io/${{ github.repository_owner }}/mpq-extractor-debian:${{ github.ref_name }} + docker push ghcr.io/${{ github.repository_owner }}/mpq-extractor-debian:latest + + - name: Download Binary Artifact (MPQExtractor) + uses: actions/download-artifact@v4 + with: + name: public-build-artifact + + - name: Create GitHub Release + uses: softprops/action-gh-release@v1 + with: + files: MPQExtractor + generate_release_notes: true + prerelease: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4084f95 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +FROM debian:trixie-slim AS mpq-extractor-builder-debian +RUN < [!NOTE] +> Typically, building `mpq-extractor-debian` image is required only once. +> This image will contain only the built `MPQExtractor` binary, +> without build tools like `gcc` or `make`. +> Compilation process itself occurs inside the `mpq-extractor-builder-debian` container. +> Such design is used to get optimal image. + +> [!TIP] +> When it's required to play with compilation interactively, such command may be used: +> +> ```sh +> docker build --target mpq-extractor-builder-debian -t mpq-extractor-builder-debian . +> docker run -it --rm --volume "$PWD:/src" --entrypoint '/bin/bash' mpq-extractor-builder-debian +> # ... do something inside the container, for example `cmake /src` +> ``` + +3\. Run binary from container + +Synopsis: +``` +docker run --rm -it mpq-extractor-debian [MPQExtractor ARGUMENTS ...] +``` + +Print help: + +```sh +docker run --rm -it mpq-extractor-debian -h +``` + +> [!NOTE] +> Container filesystem is isolated from host filesystem, to make host directories accessible from the container, +> it's required to mount it on `docker run` command invocation, for example: +> +> ```sh +> export MPQ_DATA_DIR="/home/user/Documents/World of Warcraft 3.3.5a/Data" # directory on host +> export OUT_DATA_DIR="/home/user/Documents/MPQExtractor-output" # directory on host +> +> docker run -it --rm \ +> --volume "$MPQ_DATA_DIR:/opt/data" \ +> --volume "$OUT_DATA_DIR:/opt/data/out" \ +> mpq-extractor-debian \ +> -l /opt/data/out/list.txt /opt/data/patch-4.MPQ +> +> cat "$OUT_DATA_DIR/list.txt" # Print file on host (which created in container) +> ``` + +> [!TIP] +> Like in example from previous step, when it's required to play with container (containing +> the only `MPQExtractor`) interactively, such command may be used: +> +> ```sh +> docker run -it --rm --volume "$PWD:/opt/data" --entrypoint '/bin/bash' mpq-extractor-debian +> # ... do something inside the container, for example `MPQExtractor -h` +> ``` + +See [Usage](#usage) section for more usage examples. ## License -MPQExtractor is is made available under the MIT License. The text of the license is in the file 'LICENSE'. +MPQExtractor is made available under the MIT License. The text of the license is in the file 'LICENSE'. Under the MIT License you may use MPQExtractor for any purpose you wish, without warranty, and modify it if you require, subject to one condition: