Skip to content

Commit

Permalink
Cache PHP post-install
Browse files Browse the repository at this point in the history
Cache same PHP packages for all versions

Refactor workflow

Remove bintray and use cloudsmith for build mirror

Use latest zstd from homebrew
  • Loading branch information
shivammathur committed Mar 10, 2021
1 parent 0fd502b commit 1693db3
Show file tree
Hide file tree
Showing 12 changed files with 186 additions and 134 deletions.
129 changes: 0 additions & 129 deletions .github/workflows/build.yml

This file was deleted.

64 changes: 64 additions & 0 deletions .github/workflows/cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Cache PHP
on:
- push
- repository_dispatch
- workflow_dispatch
jobs:
cache:
container: ubuntu:${{ matrix.container }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
container: [20.04, 18.04, 16.04]
php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
if: "!contains(github.event.head_commit.message, 'skip-build')"
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install requirements
run: bash src/install-requirements.sh
- name: Set up Homebrew
env:
HOMEBREW_FORCE_HOMEBREW_ON_LINUX: 1
uses: shivammathur/actions/setup-homebrew@shivammathur-patch-git-retry
- name: Install zstd
run: bash src/install-zstd.sh
- name: Configure git
run: bash src/configure-git.sh
- name: Setup PHP
env:
PHP_VERSION: ${{ matrix.php-versions }}
run: bash src/install-php.sh
- name: Build package
env:
GITHUB_WORKSPACE: ${{ github.workspace }}
PHP_VERSION: ${{ matrix.php-versions }}
run: bash src/package.sh
- name: Upload Artifact
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.php-versions }}
path: builds
release:
runs-on: ubuntu-latest
needs: cache
steps:
- uses: actions/checkout@v2
- run: mkdir builds
- uses: actions/download-artifact@v2
with:
path: builds
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.x
- name: Install cloudsmith-cli
run: pip install --upgrade cloudsmith-cli
- name: Release
run: bash src/release.sh
env:
CLOUDSMITH_API_KEY: ${{ secrets.CLOUDSMITH_API_KEY }}
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_WORKSPACE: ${{ github.workspace }}
1 change: 0 additions & 1 deletion .gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Shivam Mathur
Copyright (c) 2020-21 Shivam Mathur

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# PHP Ubuntu

<a href="https://github.com/shivammathur/php-ubuntu" title="PHP Package Cache"><img alt="Build status" src="https://github.com/shivammathur/php-ubuntu/workflows/Cache%20PHP/badge.svg"></a>
<a href="https://github.com/shivammathur/php-ubuntu/blob/main/LICENSE" title="license"><img alt="LICENSE" src="https://img.shields.io/badge/license-MIT-428f7e.svg"></a>
<a href="https://github.com/shivammathur/php-ubuntu/tree/main/builds" title="builds"><img alt="PHP Versions Supported" src="https://img.shields.io/badge/php-5.6%20to%208.0-8892BF.svg"></a>
<a href="https://github.com/shivammathur/php-ubuntu/blob/main/LICENSE" title="license"><img alt="LICENSE" src="https://img.shields.io/badge/license-MIT-428f7e.svg?logo=open%20source%20initiative&logoColor=white&labelColor=555555"></a>
<a href="https://github.com/shivammathur/php-ubuntu/tree/main/builds" title="builds"><img alt="PHP Versions Supported" src="https://img.shields.io/badge/php-5.6%20to%208.0-777bb3.svg?logo=php&logoColor=white&labelColor=555555"></a>
<a href="https://cloudsmith.io/~shivammathur/repos/php-ubuntu" title="mirror"><img alt="cloudsmith mirror" src="https://img.shields.io/badge/builds-cloudsmith-blue?logo=cloudsmith"></a>

> Cache PHP packages for installing on GitHub Actions
Expand All @@ -13,5 +14,7 @@ The code in this project is licensed under the [MIT license](LICENSE).

## Dependencies

- [ppa:ondrej/php](https://launchpad.net/~ondrej/+archive/ubuntu/php "ppa:ondrej/php")
- [actions/virtual-environments](https://github.com/actions/virtual-environments "actions/virtual-environments")
- [facebook/zstd](https://github.com/facebook/zstd "facebook/zstd")
- [homebrew/setup-homebrew](https://github.com/Homebrew/actions/tree/master/setup-homebrew "Setup Homebrew")
- [ppa:ondrej/php](https://launchpad.net/~ondrej/+archive/ubuntu/php "ppa:ondrej/php")
8 changes: 8 additions & 0 deletions src/configure-git.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
set -x

cd / || exit 1
git config --global user.email "[email protected]"
git init
git add /bin /lib /lib64 /sbin /usr /var
find /etc -maxdepth 1 -mindepth 1 -type d -exec git add {} \;
git commit -m "init"
11 changes: 11 additions & 0 deletions src/install-php.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
set -x

cd /tmp || exit
curl -o /tmp/php.sh -sSL https://raw.githubusercontent.com/actions/virtual-environments/main/images/linux/scripts/installers/php.sh
sed -i "s/^php_versions.*/php_versions=$PHP_VERSION/" /tmp/php.sh
sed -i '/ snmp\|php-pear\|composer\|phpunit\|invoke_tests\|source/d' /tmp/php.sh
sudo DEBIAN_FRONTEND=noninteractive bash /tmp/php.sh || true
sudo rm -rf /var/cache/apt/archives/*.deb || true
for extension in ast imagick pcov raphf propro http; do
sudo apt-get install "php$PHP_VERSION-$extension" -y || true
done
9 changes: 9 additions & 0 deletions src/install-requirements.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set -x

export _APTMGR=apt-get
apt-get update && apt-get install -y curl sudo software-properties-common
add-apt-repository ppa:git-core/ppa
add-apt-repository ppa:apt-fast/stable
LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y git sudo apt-fast gcc make automake pkg-config shtool snmp
4 changes: 4 additions & 0 deletions src/install-zstd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set -x

brew install zstd
zstd -V
22 changes: 22 additions & 0 deletions src/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

get() {
file_path=$1
shift
links=("$@")
for link in "${links[@]}"; do
status_code=$(sudo curl -w "%{http_code}" -o "$file_path" -sL "$link")
[ "$status_code" = "200" ] && break
done
}

install() {
sudo mkdir -p /tmp/php
get /tmp/"$tar_file" "https://github.com/shivammathur/php-ubuntu/releases/latest/download/$tar_file" "https://dl.cloudsmith.io/public/shivammathur/php-ubuntu/raw/files/$tar_file"
sudo tar -I zstd -xf /tmp/"$tar_file" -C /
}

. /etc/lsb-release
version=$1
tar_file=php_"$version"%2Bubuntu"$DISTRIB_RELEASE".tar.zst
install
21 changes: 21 additions & 0 deletions src/package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
set -x

cd / || exit 1
git add /bin /lib /lib64 /sbin /usr /var
find /etc -maxdepth 1 -mindepth 1 -type d -exec git add {} \;
git commit -m "installed php"
mkdir -p /tmp/php
for file in $(git log -p -n 1 --name-only | sed 's/^.*\(\s\).*$/\1/' | xargs -L1 echo); do
sudo cp -r -p --parents "$file" /tmp/php || true
done

. /etc/lsb-release
SEMVER="$(php -v | head -n 1 | cut -f 2 -d ' ' | cut -f 1 -d '-')"
(
cd /tmp/php || exit 1
sudo tar cf - ./* | zstd -22 -T0 --ultra > ../php_"$PHP_VERSION"+ubuntu"$DISTRIB_RELEASE".tar.zst
cp ../php_"$PHP_VERSION"+ubuntu"$DISTRIB_RELEASE".tar.zst ../php_"$SEMVER"+ubuntu"$DISTRIB_RELEASE".tar.zst
)
cd "$GITHUB_WORKSPACE" || exit 1
mkdir builds
sudo mv /tmp/*.zst ./builds
40 changes: 40 additions & 0 deletions src/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
set -x

release_cds() {
for asset in ./builds/*/*; do
assets+=("$asset")
cloudsmith push raw "$repo" "$asset" --republish --summary "$asset" --description "$asset" &
to_wait+=("$!")
done
}

release_create() {
curl -o install.sh -sL https://dl.cloudsmith.io/public/"$repo"/raw/files/php-ubuntu.sh
release_cds
assets+=("./install.sh")
gh release create "builds" "${assets[@]}" -n "builds $version" -t "builds"
}

release_upload() {
gh release download -p "build.log" || true
release_cds
gh release upload "builds" "${assets[@]}" --clobber
}

log() {
echo "$version" | sudo tee -a build.log
gh release upload "builds" build.log --clobber
}

version=$(date '+%Y.%m.%d')
repo="$GITHUB_REPOSITORY"
assets=()
to_wait=()
cd "$GITHUB_WORKSPACE" || exit 1
if ! gh release view builds; then
release_create
else
release_upload
fi
wait "${to_wait[@]}"
log

0 comments on commit 1693db3

Please sign in to comment.