diff --git a/.github/workflows/compilation.yml b/.github/workflows/compilation.yml old mode 100644 new mode 100755 index be573b3..42e955d --- a/.github/workflows/compilation.yml +++ b/.github/workflows/compilation.yml @@ -2,70 +2,157 @@ name: CI on: push: + paths-ignore: + - '**.md' + - '**.rst' pull_request: + paths-ignore: + - '**.md' + - '**.rst' repository_dispatch: - types: [run_build] + types: + - run_build + - run_release workflow_dispatch: {} +env: + HOMEBREW_NO_ANALYTICS: 1 + HOMEBREW_NO_AUTO_UPDATE: 1 + HOMEBREW_NO_INSTALL_UPGRADE: 1 + HOMEBREW_NO_INSTALL_CLEANUP: 1 + DEBIAN_FRONTEND: noninteractive + TZ: Japan jobs: build: - runs-on: ${{ matrix.os[0] }} strategy: matrix: - os: [ - [macos-latest, arm64, bash], - [macos-13, x86_64, bash], - [ubuntu-latest, x86_64, bash], - [windows-latest, x86_64, msys2] - ] + os: + - runs-on: macos-latest + architecture: arm64 + shell: bash + container: null + container-options: " " + macos-package-manager: brew + - runs-on: macos-15-intel + architecture: x86_64 + shell: bash + container: null + container-options: " " + macos-package-manager: brew + - runs-on: macos-latest + architecture: arm64 + shell: bash + container: null + container-options: " " + macos-package-manager: port + - runs-on: ubuntu-latest + architecture: x86_64 + shell: bash + container: "ubuntu:20.04" + container-options: "--user 0" + macos-package-manager: null + - runs-on: ubuntu-24.04-arm + architecture: arm64 + shell: bash + container: "ubuntu:20.04" + container-options: "--user 0" + macos-package-manager: null + - runs-on: windows-latest + architecture: x86_64 + shell: msys2 + container: null + container-options: " " + macos-package-manager: null fail-fast: false + runs-on: ${{ matrix.os.runs-on }} defaults: run: - shell: ${{ matrix.os[2] }} {0} + shell: ${{ matrix.os.shell }} {0} + container: + image: ${{ matrix.os.container }} + options: ${{ matrix.os.container-options }} + timeout-minutes: 240 steps: - - uses: actions/checkout@v4 + - name: Checkout repository + uses: actions/checkout@v4 - name: Install Ubuntu packages - if: matrix.os[0] == 'ubuntu-latest' + if: startsWith(matrix.os.runs-on, 'ubuntu') run: | - sudo apt-get update - sudo apt-get -y install texinfo bison flex gettext libgmp3-dev libmpfr-dev libmpc-dev + apt-get -y update + apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install texinfo bison flex gettext autopoint autoconf automake libgmp3-dev libmpfr-dev libmpc-dev cmake g++ gcc git libgsl-dev make patch zlib1g-dev wget curl - - name: Install macOS packages - if: startsWith(matrix.os[0], 'macos') + - name: Install macOS packages (brew) + if: startsWith(matrix.os.runs-on, 'macos') && matrix.os.macos-package-manager == 'brew' run: | brew update - brew install texinfo bison flex gnu-sed gsl gmp mpfr libmpc + brew install texinfo bison flex gnu-sed autoconf automake libtool gsl gmp mpfr libmpc md5sha1sum wget curl + + - name: Install macOS packages (port) + if: startsWith(matrix.os.runs-on, 'macos') && matrix.os.macos-package-manager == 'port' + run: | + curl -LO https://raw.githubusercontent.com/GiovanniBussi/macports-ci/master/macports-ci + . ./macports-ci install --remove-brew --version=2.11.5 --sync=rsync + sudo port install gsl gmp mpfr libmpc libiconv bison flex gsed texinfo autoconf automake libtool md5sha1sum wget curl - name: Install MSYS2 packages - if: matrix.os[0] == 'windows-latest' + if: startsWith(matrix.os.runs-on, 'windows') uses: msys2/setup-msys2@v2 with: msystem: MINGW32 install: | - base-devel git make texinfo flex bison patch binutils mpc-devel tar + base-devel git make texinfo flex bison patch binutils mpc-devel tar wget curl + autotools gettext gettext-devel mingw-w64-i686-readline mingw-w64-i686-gcc mingw-w64-i686-cmake mingw-w64-i686-make mingw-w64-i686-libogg update: true - name: Runs all the stages in the shell run: | - export PS2DEV=$PWD/ps2dev - export PS2SDK=$PS2DEV/ps2sdk - export PATH="$(brew --prefix gnu-sed)/libexec/gnubin:$PATH" # This is just needed for MacOS - export PATH=$PATH:$PS2DEV/bin:$PS2DEV/ee/bin:$PS2DEV/iop/bin:$PS2DEV/dvp/bin:$PS2SDK/bin - ./toolchain.sh + . ./config/ci-env.sh + if test -f ./build-all.sh; then ./build-all.sh; fi + if test -f ./toolchain.sh; then ./toolchain.sh; fi + + - name: Print version of executables + run: | + if test -f ./config/ci-print-version.sh; then ./config/ci-print-version.sh; fi - name: Get short SHA id: slug - run: echo "sha8=${MSYSTEM}-sha[$(echo ${GITHUB_SHA} | cut -c1-8)" >> $GITHUB_OUTPUT - - - name: Prepare ps2dev folder + run: printf '%s\n' "sha8=$(printf '%s\n' ${GITHUB_SHA} | cut -c1-8)" >> $GITHUB_OUTPUT + + - name: Compress ps2dev folder run: | - tar -zcvf ps2dev-${{matrix.os[0]}}.tar.gz ps2dev + tar -zcvf ps2dev-${{ matrix.os.runs-on }}.tar.gz ps2dev + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ github.event.repository.name }}-${{ matrix.os.runs-on }}-ps2dev-${{ matrix.os.architecture }}-${{ matrix.os.macos-package-manager }}-${{ steps.slug.outputs.sha8 }} + path: ps2dev-${{ matrix.os.runs-on }}.tar.gz + + - name: Extract tag name + if: startsWith(github.ref, 'refs/tags/') + id: tag + run: printf 'VERSION=%s\n' "${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT + + - name: Create pre-release + if: (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main') && github.event.repository.name == 'ps2dev' && matrix.os.macos-package-manager != 'port' + uses: softprops/action-gh-release@v2 + with: + files: ps2dev-${{ matrix.os.runs-on }}.tar.gz + prerelease: true + name: "Development build" + tag_name: latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - uses: actions/upload-artifact@v4 + - name: Release + if: startsWith(github.ref, 'refs/tags/') && github.event.repository.name == 'ps2dev' && matrix.os.macos-package-manager != 'port' + uses: softprops/action-gh-release@v2 with: - name: ps2dev-${{matrix.os[0]}}-ps2dev-${{matrix.os[1]}}-${{ steps.slug.outputs.sha8 }} - path: ps2dev-${{matrix.os[0]}}.tar.gz + files: ps2dev-${{ matrix.os.runs-on }}.tar.gz + tag_name: ${{ steps.tag.outputs.VERSION }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml old mode 100644 new mode 100755 index 3dd9805..f18163e --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -4,44 +4,119 @@ on: push: branches: - master + - main tags: - v* + paths-ignore: + - '**.md' + - '**.rst' + workflow_dispatch: {} repository_dispatch: - types: [run_build] + types: + - run_build jobs: build: - runs-on: ubuntu-latest - env: - DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} - DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - DISPATCH_TOKEN: ${{ secrets.DISPATCH_TOKEN }} + strategy: + matrix: + platform: + - runs-on: ubuntu-latest + container-platform: linux/amd64 + - runs-on: ubuntu-24.04-arm + container-platform: linux/arm64 + runs-on: ${{ matrix.platform.runs-on }} + timeout-minutes: 180 steps: - - uses: actions/checkout@v4 + - name: Checkout repository + uses: actions/checkout@v4 - - name: Extract DOCKER_TAG using tag name - if: startsWith(github.ref, 'refs/tags/') + - name: Prepare run: | - echo "DOCKER_TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV + platform=${{ matrix.platform.container-platform }} + printf 'PLATFORM_PAIR=%s\n' "${platform//\//-}" >> $GITHUB_ENV - - name: Use default DOCKER_TAG - if: startsWith(github.ref, 'refs/tags/') != true - run: | - echo "DOCKER_TAG=latest" >> $GITHUB_ENV + - name: Login to Github Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Prepare additional environment variables from repo + run: if test -f ./config/ci-docker-env.ini; then cat ./config/ci-docker-env.ini | sed -e 's/$REPOSITORY_OWNER/'"${{ github.repository_owner }}"'/g;s/$DOCKER_TAG/'"${{ env.DOCKER_TAG }}"'/g' >> $GITHUB_ENV; fi - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 + - name: Extract DOCKER_TAG using tag name + if: env.BUILD_ARGS_LIST != null + run: | + printf 'BUILD_ARGS_LIST_NEWLINES<> $GITHUB_ENV + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository }} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + - name: Build and Push to container registry + id: build + uses: docker/build-push-action@v6 + with: + platforms: ${{ matrix.platform.container-platform }} + labels: ${{ steps.meta.outputs.labels }} + tags: ghcr.io/${{ github.repository }} + outputs: type=image,push-by-digest=true,name-canonical=true,push=true + build-args: ${{ env.BUILD_ARGS_LIST_NEWLINES }} + + - name: Export digest + run: | + mkdir -p ${{ runner.temp }}/digests + digest="${{ steps.build.outputs.digest }}" + touch "${{ runner.temp }}/digests/${digest#sha256:}" + + - name: Upload digest + uses: actions/upload-artifact@v4 + with: + name: digests-${{ env.PLATFORM_PAIR }} + path: ${{ runner.temp }}/digests/* + if-no-files-found: error + retention-days: 1 + + merge: + needs: + - build + runs-on: ubuntu-latest + timeout-minutes: 20 + env: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + outputs: + dest-repo: ${{ steps.dest-repo.outputs.DEST_REPO }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install Ubuntu packages + run: | + sudo apt-get -y update + sudo apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install jq + + - name: Download digests + uses: actions/download-artifact@v4 + with: + path: ${{ runner.temp }}/digests + pattern: digests-* + merge-multiple: true + - name: Login to DockerHub uses: docker/login-action@v3 if: env.DOCKER_USERNAME != null with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} + username: ${{ env.DOCKER_USERNAME }} + password: ${{ env.DOCKER_PASSWORD }} - name: Login to Github Container Registry uses: docker/login-action@v3 @@ -50,36 +125,96 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract DOCKER_TAG using tag name + if: startsWith(github.ref, 'refs/tags/') + run: | + printf 'DOCKER_TAG=%s\n' "${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV + + - name: Use default DOCKER_TAG + if: startsWith(github.ref, 'refs/tags/') != true + run: | + printf 'DOCKER_TAG=%s\n' "latest" >> $GITHUB_ENV + - name: Set docker tag list to include DockerHub if credentials available if: env.DOCKER_USERNAME != null run: | - echo "DOCKER_TAG_LIST=ghcr.io/${{ github.repository }}:${{ env.DOCKER_TAG }},${{ github.repository }}:${{ env.DOCKER_TAG }}" >> $GITHUB_ENV + printf 'DOCKER_CONTAINER_LIST<> $GITHUB_ENV - name: Set docker tag list to not include DockerHub if credentials not available if: env.DOCKER_USERNAME == null run: | - echo "DOCKER_TAG_LIST=ghcr.io/${{ github.repository }}:${{ env.DOCKER_TAG }}" >> $GITHUB_ENV + printf 'DOCKER_CONTAINER_LIST<> $GITHUB_ENV - - name: Build and Push to container registry - uses: docker/build-push-action@v5 + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 with: - push: true - tags: ${{ env.DOCKER_TAG_LIST }} - build-args: | - BASE_DOCKER_DVP_IMAGE=ghcr.io/${{ github.repository_owner }}/ps2toolchain-dvp:${{ env.DOCKER_TAG }} - BASE_DOCKER_IOP_IMAGE=ghcr.io/${{ github.repository_owner }}/ps2toolchain-iop:${{ env.DOCKER_TAG }} - BASE_DOCKER_EE_IMAGE=ghcr.io/${{ github.repository_owner }}/ps2toolchain-ee:${{ env.DOCKER_TAG }} + images: ${{ env.DOCKER_CONTAINER_LIST }} + tags: | + type=raw,value=${{ env.DOCKER_TAG }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Create manifest list and push + working-directory: ${{ runner.temp }}/digests + run: | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") $(printf 'ghcr.io/${{ github.repository }}@sha256:%s ' *) + + - name: Inspect image + run: | + docker buildx imagetools inspect ghcr.io/${{ github.repository }}:${{ steps.meta.outputs.version }} + + - name: Gather information for repository dispatch + id: dest-repo + run: if test -f ./config/repository-dispatch.ini; then cat ./config/repository-dispatch.ini >> $GITHUB_OUTPUT; fi + + perform-repository-dispatch: + needs: + - merge + runs-on: ubuntu-latest + container: + image: ubuntu:20.04 + options: "--user 0" + timeout-minutes: 20 + env: + DISPATCH_TOKEN: ${{ secrets.DISPATCH_TOKEN }} + strategy: + matrix: + dest-repo: ${{ fromJson(needs.merge.outputs.dest-repo) }} + + steps: + - name: Gather environment variables (normal) + if: github.event_name != 'repository_dispatch' + run: | + printf 'PAYLOAD_REPO_PARENT_NAME=%s\n' "${{ github.repository }}" >> $GITHUB_ENV + printf 'PAYLOAD_REPO_PARENT_SHA=%s\n' "${{ github.sha }}" >> $GITHUB_ENV + + - name: Gather environment variables (dispatch) + if: github.event_name == 'repository_dispatch' + run: | + printf 'PAYLOAD_REPO_PARENT_NAME=%s\n' "${{ github.event.client_payload.parent_name }}" >> $GITHUB_ENV + printf 'PAYLOAD_REPO_PARENT_SHA=%s\n' "${{ github.event.client_payload.parent_sha }}" >> $GITHUB_ENV - name: Send Compile action run: | - export DISPATCH_ACTION="$(echo run_build)" - echo "NEW_DISPATCH_ACTION=$DISPATCH_ACTION" >> $GITHUB_ENV + export DISPATCH_ACTION="$(printf 'run_build\n')" + printf 'NEW_DISPATCH_ACTION=%s\n' "$DISPATCH_ACTION" >> $GITHUB_ENV + + - name: Repository Dispatch to ${{ matrix.dest-repo }} + uses: peter-evans/repository-dispatch@v3 + if: env.DISPATCH_TOKEN != null && !contains(matrix.dest-repo, '/') + with: + repository: ${{ github.repository_owner }}/${{ matrix.dest-repo }} + token: ${{ secrets.DISPATCH_TOKEN }} + event-type: ${{ env.NEW_DISPATCH_ACTION }} + client-payload: '{"ref": "${{ github.ref }}", "parent_name": "${{ env.PAYLOAD_REPO_PARENT_NAME }}", "parent_sha": "${{ env.PAYLOAD_REPO_PARENT_SHA }}"}' - - name: Repository Dispatch + - name: Repository Dispatch to specific ${{ matrix.dest-repo }} uses: peter-evans/repository-dispatch@v3 - if: env.DISPATCH_TOKEN != null + if: env.DISPATCH_TOKEN != null && contains(matrix.dest-repo, '/') with: - repository: ${{ github.repository_owner }}/ps2sdk + repository: ${{ matrix.dest-repo }} token: ${{ secrets.DISPATCH_TOKEN }} event-type: ${{ env.NEW_DISPATCH_ACTION }} - client-payload: '{"ref": "${{ github.ref }}"}' + client-payload: '{"ref": "${{ github.ref }}", "parent_name": "${{ env.PAYLOAD_REPO_PARENT_NAME }}", "parent_sha": "${{ env.PAYLOAD_REPO_PARENT_SHA }}"}' diff --git a/config/ci-docker-env.ini b/config/ci-docker-env.ini new file mode 100644 index 0000000..22c1dd2 --- /dev/null +++ b/config/ci-docker-env.ini @@ -0,0 +1,5 @@ + +BASE_DOCKER_DVP_IMAGE=ghcr.io/$REPOSITORY_OWNER/ps2toolchain-dvp:$DOCKER_TAG +BASE_DOCKER_IOP_IMAGE=ghcr.io/$REPOSITORY_OWNER/ps2toolchain-iop:$DOCKER_TAG +BASE_DOCKER_EE_IMAGE=ghcr.io/$REPOSITORY_OWNER/ps2toolchain-ee:$DOCKER_TAG +BUILD_ARGS_LIST=BASE_DOCKER_DVP_IMAGE BASE_DOCKER_IOP_IMAGE BASE_DOCKER_EE_IMAGE diff --git a/config/ci-env.sh b/config/ci-env.sh new file mode 100755 index 0000000..d21351e --- /dev/null +++ b/config/ci-env.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +export PS2DEV=$PWD/ps2dev +export PATH=$PATH:$PS2DEV/bin +export PATH=$PATH:$PS2DEV/iop/bin +export PATH=$PATH:$PS2DEV/ee/bin +export PATH=$PATH:$PS2DEV/dvp/bin diff --git a/config/repository-dispatch.ini b/config/repository-dispatch.ini new file mode 100644 index 0000000..1730abd --- /dev/null +++ b/config/repository-dispatch.ini @@ -0,0 +1 @@ +DEST_REPO=["ps2sdk"]