From 231db021a61518d7a0c6b08423fd74f92fe754d3 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Wed, 12 Jan 2022 22:42:11 +0000 Subject: [PATCH 01/11] Have just 1 script which runs all the different parts of the build --- .github/scripts/run-branch-build.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/scripts/run-branch-build.sh diff --git a/.github/scripts/run-branch-build.sh b/.github/scripts/run-branch-build.sh new file mode 100644 index 00000000..0da4872f --- /dev/null +++ b/.github/scripts/run-branch-build.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +set -e # Fail if any command fails + +CARGO_PROJECT_FILES=( agb-*/Cargo.toml agb/Cargo.toml examples/*/Cargo.toml book/games/*/Cargo.toml ) + +for CARGO_PROJECT_FILE in "${CARGO_PROJECT_FILES[@]}"; do + PROJECT_DIR=$(dirname "$CARGO_PROJECT_FILE") + + echo "Checking project $PROJECT_DIR" + (cd "$PROJECT_DIR" && cargo build) + + if echo "$PROJECT_DIR" | grep -qE '^agb'; then + echo "Running clippy on $PROJECT_DIR" + (cd "$PROJECT_DIR" && cargo clippy) + + echo "Testing $PROJECT_DIR in debug mode" + (cd "$PROJECT_DIR" && cargo test) + + echo "Testing $PROJECT_DIR and release mode" + (cd "$PROJECT_DIR" && cargo test --release) + fi +done \ No newline at end of file From b7d52c8ec2d4aaf3514ab7c7a725b3910b282918 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Wed, 12 Jan 2022 22:42:55 +0000 Subject: [PATCH 02/11] Replace the many steps in the build with just running the script --- .github/workflows/rust.yml | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index aa5c65e1..235ab98f 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -31,33 +31,8 @@ jobs: run: cargo install --path mgba-test-runner --verbose - name: Install gbafix run: cargo install gbafix - - name: Build agb library - working-directory: agb - run: cargo build --verbose - - name: Run Clippy on agb - working-directory: agb - run: cargo clippy --verbose - - name: Run Clippy on agb image converter - working-directory: agb-image-converter - run: cargo clippy --verbose - - name: Run Clippy on agb sound converter - working-directory: agb-sound-converter - run: cargo clippy --verbose - - name: Run Clippy on agb macros - working-directory: agb-macros - run: cargo clippy --verbose - - name: Run Clippy on agb fixnum - working-directory: agb-fixnum - run: cargo clippy --verbose - - name: Run Tests for fixnum - working-directory: agb-fixnum - run: cargo test --verbose - - name: Run Tests for agb in debug mode - working-directory: agb - run: cargo test --verbose - - name: Run Tests for agb in release mode - working-directory: agb - run: cargo test --verbose --release + - name: Build and test all crates + run: bash .github/scripts/run-branch-build.sh - name: Build example projects run: bash .github/scripts/build-example-gba-files.sh \ No newline at end of file From da1fea86feb2bcfc1caab53c687a9417a8c2fc77 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Wed, 12 Jan 2022 22:46:48 +0000 Subject: [PATCH 03/11] Add generic publish crate script --- .github/scripts/publish-crate.sh | 8 ++++++++ .github/scripts/run-branch-build.sh | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .github/scripts/publish-crate.sh diff --git a/.github/scripts/publish-crate.sh b/.github/scripts/publish-crate.sh new file mode 100644 index 00000000..4c27c22e --- /dev/null +++ b/.github/scripts/publish-crate.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +set -e # Fail if any command fails + +RELEASE_TAG=$(git tag --points-at HEAD) + +PROJECT=${RELEASE_TAG/\/*/} +(cd "$PROJECT" && cargo publish) diff --git a/.github/scripts/run-branch-build.sh b/.github/scripts/run-branch-build.sh index 0da4872f..25411942 100644 --- a/.github/scripts/run-branch-build.sh +++ b/.github/scripts/run-branch-build.sh @@ -20,4 +20,4 @@ for CARGO_PROJECT_FILE in "${CARGO_PROJECT_FILES[@]}"; do echo "Testing $PROJECT_DIR and release mode" (cd "$PROJECT_DIR" && cargo test --release) fi -done \ No newline at end of file +done From 71e2e64c4887ceabd264e12edc8f7689d1fbbd96 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Wed, 12 Jan 2022 22:47:59 +0000 Subject: [PATCH 04/11] Replace all the crate builds with a single 'publish subcrate' --- .github/workflows/publish-agb-macros.yml | 20 ------------------- .github/workflows/publish-image-converter.yml | 20 ------------------- .github/workflows/publish-sound-converter.yml | 20 ------------------- ...h-agb-fixnum.yml => publish-sub-crate.yml} | 9 ++++----- 4 files changed, 4 insertions(+), 65 deletions(-) delete mode 100644 .github/workflows/publish-agb-macros.yml delete mode 100644 .github/workflows/publish-image-converter.yml delete mode 100644 .github/workflows/publish-sound-converter.yml rename .github/workflows/{publish-agb-fixnum.yml => publish-sub-crate.yml} (71%) diff --git a/.github/workflows/publish-agb-macros.yml b/.github/workflows/publish-agb-macros.yml deleted file mode 100644 index 53783780..00000000 --- a/.github/workflows/publish-agb-macros.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Publish agb-macros - -on: - push: - tags: - - agb-macros/v* - -jobs: - build: - runs-on: ubuntu-20.04 - steps: - - name: Install build tools - run: sudo apt-get update && sudo apt-get install build-essential binutils-arm-none-eabi -y - - name: Check out repository - uses: actions/checkout@v2 - - name: Login to crates.io - run: cargo login ${{ secrets.CRATE_API }} - - name: Publish agb-macros - run: cargo publish - working-directory: ./agb-macros \ No newline at end of file diff --git a/.github/workflows/publish-image-converter.yml b/.github/workflows/publish-image-converter.yml deleted file mode 100644 index 8dfb3844..00000000 --- a/.github/workflows/publish-image-converter.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Publish agb-image-converter - -on: - push: - tags: - - agb-image-converter/v* - -jobs: - build: - runs-on: ubuntu-20.04 - steps: - - name: Install build tools - run: sudo apt-get update && sudo apt-get install build-essential binutils-arm-none-eabi -y - - name: Check out repository - uses: actions/checkout@v2 - - name: Login to crates.io - run: cargo login ${{ secrets.CRATE_API }} - - name: Publish agb-image-converter - run: cargo publish - working-directory: ./agb-image-converter \ No newline at end of file diff --git a/.github/workflows/publish-sound-converter.yml b/.github/workflows/publish-sound-converter.yml deleted file mode 100644 index 6ac465fa..00000000 --- a/.github/workflows/publish-sound-converter.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Publish agb-sound-converter - -on: - push: - tags: - - agb-sound-converter/v* - -jobs: - build: - runs-on: ubuntu-20.04 - steps: - - name: Install build tools - run: sudo apt-get update && sudo apt-get install build-essential binutils-arm-none-eabi -y - - name: Check out repository - uses: actions/checkout@v2 - - name: Login to crates.io - run: cargo login ${{ secrets.CRATE_API }} - - name: Publish agb-sound-converter - run: cargo publish - working-directory: ./agb-sound-converter \ No newline at end of file diff --git a/.github/workflows/publish-agb-fixnum.yml b/.github/workflows/publish-sub-crate.yml similarity index 71% rename from .github/workflows/publish-agb-fixnum.yml rename to .github/workflows/publish-sub-crate.yml index 3ff76916..04103352 100644 --- a/.github/workflows/publish-agb-fixnum.yml +++ b/.github/workflows/publish-sub-crate.yml @@ -1,9 +1,9 @@ -name: Publish agb-fixnum +name: Publish sub crate on: push: tags: - - agb-fixnum/v* + - */v* jobs: build: @@ -15,6 +15,5 @@ jobs: uses: actions/checkout@v2 - name: Login to crates.io run: cargo login ${{ secrets.CRATE_API }} - - name: Publish agb-fixnum - run: cargo publish - working-directory: ./agb-fixnum \ No newline at end of file + - name: Publish crate + run: bash .github/scripts/publish-crate.sh From c575f6328181bee9af81b00db2b9689995c324c6 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Wed, 12 Jan 2022 22:50:59 +0000 Subject: [PATCH 05/11] Allow any project to be released in release.sh --- release.sh | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/release.sh b/release.sh index 9e90d56c..9b9f91b4 100755 --- a/release.sh +++ b/release.sh @@ -31,26 +31,19 @@ case "$PROJECT" in DIRECTORY="agb" TAGNAME="v$VERSION" ;; - agb-image-converter) - DIRECTORY="agb-image-converter" - TAGNAME="agb-image-converter/v$VERSION" - ;; - agb-sound-converter) - DIRECTORY="agb-sound-converter" - TAGNAME="agb-sound-converter/v$VERSION" - ;; - agb-macros) - DIRECTORY="agb-macros" - TAGNAME="agb-macros/v$VERSION" + agb-*) + if [ -f "$PROJECT/Cargo.toml" ]; then + DIRECTORY=$PROJECT + TAGNAME="$PROJECT/v$VERSION" + else + echo "Unknown project name $PROJECT" + exit 1 + fi ;; mgba-test-runner) DIRECTORY="mgba-test-runner" TAGNAME="mgba-test-runner/v$VERSION" ;; - agb-fixnum) - DIRECTORY="agb-fixnum" - TAGNAME="agb-fixnum/v$VERSION" - ;; *) echo "Unknown project name $PROJECT" exit 1 From bead62911a97790a092fdcd3d24704815c507be6 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Wed, 12 Jan 2022 22:52:27 +0000 Subject: [PATCH 06/11] Prefixing a string with a * in yaml is apparently not allowed --- .github/workflows/publish-sub-crate.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-sub-crate.yml b/.github/workflows/publish-sub-crate.yml index 04103352..13240fed 100644 --- a/.github/workflows/publish-sub-crate.yml +++ b/.github/workflows/publish-sub-crate.yml @@ -3,7 +3,7 @@ name: Publish sub crate on: push: tags: - - */v* + - "*/v*" jobs: build: From c0bf88e77137f16333eb7488ced098fbeaefdc14 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Wed, 12 Jan 2022 22:57:42 +0000 Subject: [PATCH 07/11] Fix typo --- .github/scripts/run-branch-build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/run-branch-build.sh b/.github/scripts/run-branch-build.sh index 25411942..45a5a8c4 100644 --- a/.github/scripts/run-branch-build.sh +++ b/.github/scripts/run-branch-build.sh @@ -17,7 +17,7 @@ for CARGO_PROJECT_FILE in "${CARGO_PROJECT_FILES[@]}"; do echo "Testing $PROJECT_DIR in debug mode" (cd "$PROJECT_DIR" && cargo test) - echo "Testing $PROJECT_DIR and release mode" + echo "Testing $PROJECT_DIR in release mode" (cd "$PROJECT_DIR" && cargo test --release) fi done From 0aa5d51c6fc1ef498204f05db61b2daa312a8edd Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Wed, 12 Jan 2022 22:57:47 +0000 Subject: [PATCH 08/11] Build example gba files into `examples/target` --- .github/scripts/build-example-gba-files.sh | 6 ++++-- examples/.gitignore | 1 - 2 files changed, 4 insertions(+), 3 deletions(-) delete mode 100644 examples/.gitignore diff --git a/.github/scripts/build-example-gba-files.sh b/.github/scripts/build-example-gba-files.sh index c1a79701..beee0401 100755 --- a/.github/scripts/build-example-gba-files.sh +++ b/.github/scripts/build-example-gba-files.sh @@ -17,10 +17,12 @@ function build_rom() { (cd "$GAME_FOLDER" && cargo build --release --verbose --target thumbv4t-none-eabi) + mkdir -p examples/target/examples + arm-none-eabi-objcopy -O binary "$TARGET_FOLDER/thumbv4t-none-eabi/release/$GAME_NAME" "$GBA_FILE" gbafix -p "-t${INTERNAL_NAME:0:12}" "-c${INTERNAL_NAME:0:4}" -mGC "$GBA_FILE" - cp -v "$GBA_FILE" "examples/$GAME_NAME.gba" + cp -v "$GBA_FILE" "examples/target/examples/$GAME_NAME.gba" } mkdir -p examples/target @@ -30,4 +32,4 @@ build_rom "examples/the-hat-chooses-the-wizard" "HATWIZARD" build_rom "book/games/pong" "PONG" -zip examples/target/examples.zip examples/*.gba \ No newline at end of file +(cd examples/target && zip examples.zip examples/*.gba) \ No newline at end of file diff --git a/examples/.gitignore b/examples/.gitignore deleted file mode 100644 index fdcffe19..00000000 --- a/examples/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.gba \ No newline at end of file From fdc234b60b9d39c61bf1cb1320695c9cf27edff7 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Wed, 12 Jan 2022 23:11:54 +0000 Subject: [PATCH 09/11] Add a step to build the book to the normal branch build --- .github/workflows/rust.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 235ab98f..ba70b868 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -31,8 +31,12 @@ jobs: run: cargo install --path mgba-test-runner --verbose - name: Install gbafix run: cargo install gbafix + - name: Install mdbook + run: cargo install mdbook - name: Build and test all crates run: bash .github/scripts/run-branch-build.sh - name: Build example projects run: bash .github/scripts/build-example-gba-files.sh - \ No newline at end of file + - name: Build the book + run: mdbook build + working-directory: book \ No newline at end of file From 43f806f1169f72653a842ca99c70d2acec668318 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Wed, 12 Jan 2022 23:13:31 +0000 Subject: [PATCH 10/11] Add deploying the book as a step for releasing agb --- .github/workflows/publish-agb.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/publish-agb.yml b/.github/workflows/publish-agb.yml index fe64e7b3..776bae6d 100644 --- a/.github/workflows/publish-agb.yml +++ b/.github/workflows/publish-agb.yml @@ -36,3 +36,14 @@ jobs: asset_name: examples.zip tag: ${{ github.ref }} overwrite: true + + - name: Install mdbook + run: cargo install mdbook + - name: Build the book + run: mdbook build + working-directory: book + - name: Deploy the book + uses: JamesIves/github-pages-deploy-action@v4.2.2 + with: + branch: gh-pages + folder: book/book From e0b43acf42a9b4080dc2d4ab9c6c00aef62e8794 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Wed, 12 Jan 2022 23:28:12 +0000 Subject: [PATCH 11/11] Move building the book to its own workflow since it takes forever to install mdbook --- .github/workflows/build-book.yml | 38 ++++++++++++++++++++++++++++++++ .github/workflows/rust.yml | 7 +----- 2 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/build-book.yml diff --git a/.github/workflows/build-book.yml b/.github/workflows/build-book.yml new file mode 100644 index 00000000..53acff48 --- /dev/null +++ b/.github/workflows/build-book.yml @@ -0,0 +1,38 @@ +name: Build book + +on: + push: + branches: [ master ] + paths: + 'book/**' + pull_request: + branches: [ master ] + paths: + 'book/**' + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + runs-on: ubuntu-20.04 + steps: + - name: Set CARGO_TARGET_DIR + run: echo "CARGO_TARGET_DIR=$HOME/target" >> $GITHUB_ENV + - name: Install build tools + run: sudo apt-get update && sudo apt-get install build-essential binutils-arm-none-eabi libelf-dev zip -y + - uses: actions/checkout@v2 + - name: Cache + uses: actions/cache@v2.1.7 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + ~/target + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + + - name: Install mdbook + run: cargo install mdbook + - name: Build the book + run: mdbook build + working-directory: book \ No newline at end of file diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index ba70b868..363ff545 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -31,12 +31,7 @@ jobs: run: cargo install --path mgba-test-runner --verbose - name: Install gbafix run: cargo install gbafix - - name: Install mdbook - run: cargo install mdbook - name: Build and test all crates run: bash .github/scripts/run-branch-build.sh - name: Build example projects - run: bash .github/scripts/build-example-gba-files.sh - - name: Build the book - run: mdbook build - working-directory: book \ No newline at end of file + run: bash .github/scripts/build-example-gba-files.sh \ No newline at end of file