Skip to content

Mirror sources to dl.static-php.dev #119

Mirror sources to dl.static-php.dev

Mirror sources to dl.static-php.dev #119

name: "Mirror sources to dl.static-php.dev"
on:
workflow_dispatch:
schedule:
- cron: "0 1 */3 * *"
env:
GITHUB_TOKEN: ${{ secrets.S_GITHUB_TOKEN }}
jobs:
# define
define-matrix:
name: "Generate source matrix"
runs-on: ubuntu-latest
outputs:
sources: ${{ steps.step1.outputs.sources }}
steps:
- name: "Checkout"
uses: "actions/checkout@v4"
with:
repository: crazywhalecc/static-php-cli
- name: "Create Matrix Variable"
id: step1
run: |
VALUE=$(cat config/source.json | jq -M -c keys)
echo 'sources='"$VALUE" >> "$GITHUB_OUTPUT"
# parse
download-source:
name: "Download ${{ matrix.source }}"
runs-on: ubuntu-latest
needs: define-matrix
timeout-minutes: 60
strategy:
matrix:
source: ${{ fromJSON(needs.define-matrix.outputs.sources) }}
fail-fast: false
steps:
- name: "Checkout"
uses: "actions/checkout@v4"
with:
repository: crazywhalecc/static-php-cli
- name: "Setup static-php environment"
run: |
bin/setup-runtime
bin/php bin/composer install --no-dev --no-ansi -q --no-interaction
- name: "Download source ${{ matrix.source }}"
run: bin/php bin/spc download ${{ matrix.source }} --debug --ignore-cache-sources --no-alt --shallow-clone
- name: "Parse lock file and re-package with file"
run: |
rename_file() {
local src_file="$1"
local target="$2"
local destination_dir="$3"
if [[ ! -f "$src_file" ]]; then
echo "Error: '$src_file' is not a valid file" >&2
return 1
fi
if [[ "$src_file" =~ \.tar\.(gz|xz)$ ]]; then
local ext=".tar.${BASH_REMATCH[1]}"
local base_name="${src_file%$ext}"
if [[ -z "$base_name" ]]; then
echo "Error: Invalid filename '$src_file'" >&2
return 1
fi
elif [[ "$src_file" =~ \.[^./]+$ ]]; then
local ext=".${src_file##*.}"
local base_name="${src_file%.$ext}"
else
echo "Skip: '$src_file' has no extension" >&2
return 0
fi
local new_name="${target}${ext}"
cp -- "$src_file" "$new_name"
mv "$new_name" "$destination_dir"/
echo "Renamed: $src_file -> $destination_dir/$new_name"
}
mkdir downloads-mirror-${{ matrix.source }}
SOURCE_TYPE=$(cat downloads/.lock.json | jq -M -c -r '."${{ matrix.source }}".source_type')
if [ "$SOURCE_TYPE" = "archive" ]; then
cd downloads
rename_file $(cat .lock.json | jq -M -c -r '."${{ matrix.source }}".filename') ${{ matrix.source }}-spc-mirror ../downloads-mirror-${{ matrix.source }}
cd ..
else
cd downloads
tar --exclude-vcs -cJvf ${{ matrix.source }}-spc-mirror.txz $(cat .lock.json | jq -M -c -r '."${{ matrix.source }}".dirname')
mv ${{ matrix.source }}-spc-mirror.txz ../downloads-mirror-${{ matrix.source }}/
cd ..
fi
- name: "Deploy to OSS"
uses: shallwefootball/s3-upload-action@master
with:
aws_key_id: ${{ secrets.AWS_KEY_ID }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws_bucket: ${{ secrets.AWS_BUCKET }}
source_dir: downloads-mirror-${{ matrix.source }}/
destination_dir: static-php-cli/deps/spc-download-mirror/${{ matrix.source }}/
endpoint: ${{ secrets.AWS_ENDPOINT }}