Skip to content

Commit

Permalink
gh action ng (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
valord577 authored Aug 23, 2024
1 parent c106972 commit 090ad93
Show file tree
Hide file tree
Showing 23 changed files with 123 additions and 85 deletions.
32 changes: 32 additions & 0 deletions .github/matrix.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"os": "macos-14",
"platform": "iphoneos",
"arch": "arm64",
"pkg_type": "static"
},
{
"os": "macos-14",
"platform": "iphonesimulator",
"arch": "arm64",
"pkg_type": "static"
},
{
"os": "macos-14",
"platform": "iphonesimulator",
"arch": "x86_64",
"pkg_type": "static"
},
{
"os": "macos-14",
"platform": "macosx",
"arch": "arm64",
"pkg_type": "static"
},
{
"os": "macos-14",
"platform": "macosx",
"arch": "x86_64",
"pkg_type": "static"
}
]
2 changes: 1 addition & 1 deletion .github/oss_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing import Any, Callable, NoReturn
from urllib.parse import quote as escape

sign_expires_in_seconds = "10"
sign_expires_in_seconds = "60"
environ_key_http_debug = "HTTP_DEBUG_MESSAGE"
oss_storage_basedir = os.getenv("GH_OSSUTIL_PKGS")

Expand Down
109 changes: 58 additions & 51 deletions .github/workflows/_buildx.yml → .github/workflows/_matrix.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: _buildx
name: _matrix
on:
workflow_call:
inputs:
Expand All @@ -16,6 +16,7 @@ on:
type: boolean

env:
GH_TOKEN: ${{ github.token }}
GH_OSSUTIL_AK: ${{ secrets.GH_OSSUTIL_AK }}
GH_OSSUTIL_SK: ${{ secrets.GH_OSSUTIL_SK }}
GH_OSSUTIL_BUCKET: ${{ secrets.GH_OSSUTIL_BUCKET }}
Expand All @@ -24,34 +25,57 @@ env:
GH_OSSUTIL_CNAME: ${{ secrets.GH_OSSUTIL_CNAME }}

jobs:
_preset:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: ${{ github.workspace }}
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
pkgver: ${{ steps.set-pkgver.outputs.pkgver }}
steps:
- name: clone with gh
run: |
gh repo clone ${{ github.repositoryUrl }} . -- --no-checkout --single-branch --depth=1
git fetch --no-tags --prune --no-recurse-submodules --depth=1 origin +${{ github.sha }}; git checkout FETCH_HEAD
- name: set matrix
id: set-matrix
run: |
if [[ ${{ (! inputs.disable_shared) }} ]]; then { jq_expr='(.pkg_type=="shared")'; } fi
if [[ ${{ (! inputs.disable_static) }} ]]; then
if [ -z "${jq_expr}" ]; then { jq_expr='(.pkg_type=="static")'; } else { jq_expr="$jq_expr or (.pkg_type==\"static\")"; } fi
fi
printf "\e[1m\e[33m%s\e[0m\n" "jq_expr: $jq_expr"
matrix=$(cat .github/matrix.json | jq -c -M "map(. | select($jq_expr) )")
printf "\e[1m\e[33m%s\e[0m\n" "matrix: $matrix"
echo "matrix={\"include\":$(echo $matrix)}" >> "$GITHUB_OUTPUT"
- name: set pkgver
id: set-pkgver
run: |
pkgver=$(git ls-tree -d --abbrev=7 --format='%(objectname)' HEAD -- deps/${{ github.workflow }})
printf "\e[1m\e[33m%s\e[0m\n" "pkgver: $pkgver"
echo "pkgver=$pkgver" >> "$GITHUB_OUTPUT"
_buildx:
needs: _preset
strategy:
matrix:
pkg_type: [shared, static]
platform: [iphoneos, iphonesimulator, macosx]
arch: [arm64, x86_64]
exclude:
- platform: 'iphoneos'
arch: 'x86_64'
runs-on: macos-14
outputs:
version: ${{ steps.version.outputs._PKG_VERSION }}
matrix: ${{ fromJson(needs._preset.outputs.matrix) }}
runs-on: ${{ matrix.os }}
env:
_REPO_THIS: "_repo_this"
_SETP_CAN_RUN: ${{ (! inputs.disable_shared && matrix.pkg_type == 'shared') || (! inputs.disable_static && matrix.pkg_type == 'static') }}
INST_DIR: "${{ github.workspace }}/${{ github.workflow }}"
CCACHE_DIR: ${{ github.workspace }}/.ccache
CCACHE_GHA_KEY: ${{ matrix.pkg_type }}-${{ matrix.platform }}-${{ matrix.arch }}-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}
CCACHE_GHA_KEY_RESTORE: ${{ matrix.pkg_type }}-${{ matrix.platform }}-${{ matrix.arch }}
steps:
- name: checkout this repo
uses: actions/checkout@v4
with:
path: ${{ env._REPO_THIS }}
- name: clone with gh
run: |
gh repo clone ${{ github.repositoryUrl }} . -- --no-checkout --single-branch --depth=1
git fetch --no-tags --prune --no-recurse-submodules --depth=1 origin +${{ github.sha }}; git checkout FETCH_HEAD
- name: install required software(s)
run: |
brew list -l
brew install ccache nasm
brew list -l; brew install ccache nasm
- name: gh action ccache restore
uses: actions/cache/restore@v4
with:
Expand All @@ -60,66 +84,49 @@ jobs:
restore-keys: |
${{ env.CCACHE_GHA_KEY_RESTORE }}
- name: buildx library - ${{ github.workflow }}
if: ${{ env._SETP_CAN_RUN == 'true' }}
run: |
source ${{ env._REPO_THIS }}/build_${{ matrix.platform }}_${{ matrix.arch }}.sh
source build_${{ matrix.platform }}_${{ matrix.arch }}.sh
compile ${{ github.workflow }} ${{ matrix.pkg_type }} ${{ matrix.platform }} ${{ matrix.arch }}
- name: gh action ccache save
if: ${{ env._SETP_CAN_RUN == 'true' }}
uses: actions/cache/save@v4
with:
path: ${{ env.CCACHE_DIR }}
key: ${{ env.CCACHE_GHA_KEY }}
- name: set required env `_PKG_VERSION`
id: version
if: ${{ env._SETP_CAN_RUN == 'true' }}
run: |
pushd -- "${{ env._REPO_THIS }}/deps/${{ github.workflow }}"
_PKG_VERSION=$(git rev-parse --short=7 HEAD)
popd
echo "_PKG_VERSION=${_PKG_VERSION}" >> "$GITHUB_ENV"
echo "_PKG_VERSION=${_PKG_VERSION}" >> "$GITHUB_OUTPUT"
- name: set required env `_PKG_ZIP_NAME`
if: ${{ env._SETP_CAN_RUN == 'true' }}
run: |
echo "_PKG_ZIP_NAME=${{ github.workflow }}_${{ matrix.platform }}_${{ matrix.arch }}_${{ env._PKG_VERSION }}_${{ matrix.pkg_type }}" >> "$GITHUB_ENV"
echo "_PKG_ZIP_NAME=${{ github.workflow }}_${{ matrix.platform }}_${{ matrix.arch }}_${{ needs._preset.outputs.pkgver }}_${{ matrix.pkg_type }}" >> "$GITHUB_ENV"
- name: compress library - ${{ github.workflow }}
if: ${{ env._SETP_CAN_RUN == 'true' }}
run: |
zip -ry "${{ env._PKG_ZIP_NAME }}.zip" ${{ github.workflow }}
- name: upload library - ${{ github.workflow }}
if: ${{ env._SETP_CAN_RUN == 'true' }}
uses: actions/upload-artifact@v4
with:
name: ${{ env._PKG_ZIP_NAME }}
path: ${{ env._PKG_ZIP_NAME }}.zip

_upload:
needs: _buildx
needs:
- _preset
- _buildx
runs-on: ubuntu-latest
env:
_PUSH_CAN_EXE: ${{ github.event_name == 'push' && (! inputs.disable_upload) }}
steps:
- name: clone with gh
run: |
gh repo clone ${{ github.repositoryUrl }} . -- --no-checkout --single-branch --depth=1
git fetch --no-tags --prune --no-recurse-submodules --depth=1 origin +${{ github.sha }}; git checkout FETCH_HEAD
- name: download ${{ github.workflow }} libraries
uses: actions/download-artifact@v4
with:
path: ${{ github.workspace }}/${{ github.workflow }}
- name: show debug info
run: |
env
echo -e "\n"
echo -e "${PWD}"
echo -e "\n"
ls -Alh -- .
echo -e "\n"
ls -AlhR ${{ github.workflow }}
- name: commit to pre-compiled packages
if: ${{ env._PUSH_CAN_EXE == 'true' }}
run: |
mkdir -p '${{ github.workflow }}/${{ needs._buildx.outputs.version }}'
mv -f ${{ github.workspace }}/${{ github.workflow }}/*/*.zip '${{ github.workflow }}/${{ needs._buildx.outputs.version }}'
mkdir -p '${{ github.workflow }}/${{ needs._preset.outputs.pkgver }}'
mv -f ${{ github.workspace }}/${{ github.workflow }}/*/*.zip '${{ github.workflow }}/${{ needs._preset.outputs.pkgver }}'
for ZIP in `ls -- ${{ github.workflow }}/${{ needs._buildx.outputs.version }}`; do
./.github/oss_v4.py push "${{ github.workflow }}/${{ needs._buildx.outputs.version }}/${ZIP}" \
"${{ github.workflow }}/${{ needs._buildx.outputs.version }}/${ZIP}"
for ZIP in `ls -- ${{ github.workflow }}/${{ needs._preset.outputs.pkgver }}`; do
./.github/oss_v4.py push "${{ github.workflow }}/${{ needs._preset.outputs.pkgver }}/${ZIP}" \
"${{ github.workflow }}/${{ needs._preset.outputs.pkgver }}/${ZIP}"
done
11 changes: 5 additions & 6 deletions .github/workflows/ffmpeg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ on:
branches:
- main
paths:
- '.github/workflows/_buildx.yml'
- '.github/workflows/_matrix.yml'
- '.github/workflows/ffmpeg.yml'
- 'deps/ffmpeg'
- 'patchs/ffmpeg/**'
- 'patches/ffmpeg/**'
- 'scripts/ffmpeg.sh'
- 'build.sh'
- 'env-apple.sh'
Expand All @@ -16,10 +16,10 @@ on:
branches:
- main
paths:
- '.github/workflows/_buildx.yml'
- '.github/workflows/_matrix.yml'
- '.github/workflows/ffmpeg.yml'
- 'deps/ffmpeg'
- 'patchs/ffmpeg/**'
- 'patches/ffmpeg/**'
- 'scripts/ffmpeg.sh'
- 'build.sh'
- 'env-apple.sh'
Expand All @@ -28,7 +28,6 @@ on:
jobs:
build:
secrets: inherit
uses: ./.github/workflows/_buildx.yml
uses: ./.github/workflows/_matrix.yml
with:
disable_shared: false
disable_upload: true
10 changes: 5 additions & 5 deletions .github/workflows/mbedtls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ on:
branches:
- main
paths:
- '.github/workflows/_buildx.yml'
- '.github/workflows/_matrix.yml'
- '.github/workflows/mbedtls.yml'
- 'deps/mbedtls'
- 'patchs/mbedtls/**'
- 'patches/mbedtls/**'
- 'scripts/mbedtls.sh'
- 'build.sh'
- 'env-apple.sh'
pull_request:
branches:
- main
paths:
- '.github/workflows/_buildx.yml'
- '.github/workflows/_matrix.yml'
- '.github/workflows/mbedtls.yml'
- 'deps/mbedtls'
- 'patchs/mbedtls/**'
- 'patches/mbedtls/**'
- 'scripts/mbedtls.sh'
- 'build.sh'
- 'env-apple.sh'

jobs:
build:
secrets: inherit
uses: ./.github/workflows/_buildx.yml
uses: ./.github/workflows/_matrix.yml
10 changes: 5 additions & 5 deletions .github/workflows/sdl2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ on:
branches:
- main
paths:
- '.github/workflows/_buildx.yml'
- '.github/workflows/_matrix.yml'
- '.github/workflows/sdl2.yml'
- 'deps/sdl2'
- 'patchs/sdl2/**'
- 'patches/sdl2/**'
- 'scripts/sdl2.sh'
- 'build.sh'
- 'env-apple.sh'
pull_request:
branches:
- main
paths:
- '.github/workflows/_buildx.yml'
- '.github/workflows/_matrix.yml'
- '.github/workflows/sdl2.yml'
- 'deps/sdl2'
- 'patchs/sdl2/**'
- 'patches/sdl2/**'
- 'scripts/sdl2.sh'
- 'build.sh'
- 'env-apple.sh'

jobs:
build:
secrets: inherit
uses: ./.github/workflows/_buildx.yml
uses: ./.github/workflows/_matrix.yml
4 changes: 2 additions & 2 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ $compile = {
Pop-Location
}

if (Test-Path -PathType Container -Path "${PROJ_ROOT}/patchs/${PKG_NAME}") {
if (Test-Path -PathType Container -Path "${PROJ_ROOT}/patches/${PKG_NAME}") {
Push-Location "${env:SUBPROJ_SRC}"
git reset --hard HEAD

foreach ($patch in (Get-ChildItem -Path "${PROJ_ROOT}/patchs/${PKG_NAME}" -File)) {
foreach ($patch in (Get-ChildItem -Path "${PROJ_ROOT}/patches/${PKG_NAME}" -File)) {
git apply ${patch}.FullName
}
Pop-Location
Expand Down
8 changes: 4 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ case ${TARGET_PLATFORM} in
"macosx" | "iphoneos" | "iphonesimulator")
source "${PROJ_ROOT}/env-apple.sh" ${TARGET_PLATFORM} ${TARGET_ARCH}
;;
?)
*)
;;
esac

Expand Down Expand Up @@ -52,12 +52,12 @@ function compile() {
popd
fi

if [ -e "${PROJ_ROOT}/patchs/${PKG_NAME}" ]; then
if [ -e "${PROJ_ROOT}/patches/${PKG_NAME}" ]; then
pushd -- "${SUBPROJ_SRC}"
git reset --hard HEAD

for patch in $(ls -- "${PROJ_ROOT}/patchs/${PKG_NAME}"); do
git apply "${PROJ_ROOT}/patchs/${PKG_NAME}/${patch}"
for patch in $(ls -- "${PROJ_ROOT}/patches/${PKG_NAME}"); do
git apply "${PROJ_ROOT}/patches/${PKG_NAME}/${patch}"
done
popd
fi
Expand Down
2 changes: 1 addition & 1 deletion deps/ffmpeg
Submodule ffmpeg updated 570 files
2 changes: 1 addition & 1 deletion deps/sdl2
Submodule sdl2 updated 156 files
2 changes: 1 addition & 1 deletion env-apple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ case ${TARGET_PLATFORM} in
"iphonesimulator")
TARGET_FLAG="ios-simulator"
;;
?)
*)
;;
esac

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions scripts/ffmpeg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ case ${PKG_TYPE} in
"shared")
PKG_TYPE_FLAG="--disable-static --enable-shared"
;;
?)
*)
printf "\e[1m\e[31m%s\e[0m\n" "Invalid PKG TYPE: '${PKG_TYPE}'."
exit 1
;;
Expand Down Expand Up @@ -76,7 +76,7 @@ case ${PKG_PLATFORM} in
--disable-libxcb --disable-xlib
"
;;
?)
*)
;;
esac
case ${PKG_PLATFORM} in
Expand All @@ -85,7 +85,7 @@ case ${PKG_PLATFORM} in
"iphoneos" | "iphonesimulator")
CONFIGURE_COMMAND="${CONFIGURE_COMMAND} --disable-programs"
;;
?)
*)
;;
esac

Expand Down
Loading

0 comments on commit 090ad93

Please sign in to comment.