Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/filters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
php84-debian12:
- 'php84-debian12/**'
- 'Dockerfile'

php84-debian11:
- 'php84-debian11/**'
- 'Dockerfile'

php83-debian12:
- 'php83-debian12/**'
- 'Dockerfile'

php83-debian11:
- 'php83-debian11/**'
- 'Dockerfile'

php82-debian12:
- 'php82-debian12/**'
- 'Dockerfile'

php82-debian11:
- 'php82-debian11/**'
- 'Dockerfile'

php81-debian12:
- 'php81-debian12/**'
- 'Dockerfile'

php81-debian11:
- 'php81-debian11/**'
- 'Dockerfile'
68 changes: 41 additions & 27 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,55 @@ jobs:
changes:
name: Detect Changes
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
variants: ${{ steps.filter.outputs.changes }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: ${{ startsWith(github.ref, 'refs/tags/v') && 0 || 1 }}

- name: Retrieve the previous release version
if: startsWith(github.ref, 'refs/tags/v')
id: previous_release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Attempt to get the tag of the second-to-last release
PREVIOUS_TAG=$(gh release list --limit 2 --json tagName | jq -r '. | select(length > 1) | .[1].tagName')

if [[ -z "$PREVIOUS_TAG" ]]; then
echo "No previous release found. Falling back to the first commit."
REF=$(git rev-list --max-parents=0 HEAD)
else
echo "Found previous release: $PREVIOUS_TAG"
REF=$PREVIOUS_TAG
fi

echo "The reference point is: $REF"
echo "ref=$REF" >> $GITHUB_OUTPUT

- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
php84-debian12:
- 'php84-debian12/**'
- 'Dockerfile'
php84-debian11:
- 'php84-debian11/**'
- 'Dockerfile'
php83-debian12:
- 'php83-debian12/**'
- 'Dockerfile'
php83-debian11:
- 'php83-debian11/**'
- 'Dockerfile'
php82-debian12:
- 'php82-debian12/**'
- 'Dockerfile'
php82-debian11:
- 'php82-debian11/**'
- 'Dockerfile'
php81-debian12:
- 'php81-debian12/**'
- 'Dockerfile'
php81-debian11:
- 'php81-debian11/**'
- 'Dockerfile'
filters: .github/filters.yml
base: ${{ startsWith(github.ref, 'refs/tags/v') && steps.previous_release.outputs.ref || '' }}

build:
needs: changes
name: Build ${{ matrix.variant }} image
runs-on: ubuntu-latest
if: needs.changes.outputs.variants != '[]'
concurrency:
group: build-${{ matrix.variant }}
cancel-in-progress: true
strategy:
fail-fast: false
matrix:
variant: ${{ fromJson(needs.changes.outputs.variants) }}
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down Expand Up @@ -94,3 +96,15 @@ jobs:

- name: Test
run: make test-setup test-${{ matrix.variant }}

- name: Login to GitHub Container Registry
if: startsWith(github.ref, 'refs/tags/v')
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Push to GitHub Container Registry
if: startsWith(github.ref, 'refs/tags/v')
run: make push-${{ matrix.variant }}
107 changes: 107 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Release

on:
release:
types: [published]

jobs:
changes:
name: Detect changes since last release
runs-on: ubuntu-latest
outputs:
variants: ${{ steps.filter.outputs.changes }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Retrieve the previous release version
id: previous_release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Attempt to get the tag of the second-to-last release
PREVIOUS_TAG=$(gh release list --limit 2 --json tagName | jq -r '. | select(length > 1) | .[1].tagName')

if [[ -z "$PREVIOUS_TAG" ]]; then
echo "No previous release found. Falling back to the first commit."
REF=$(git rev-list --max-parents=0 HEAD)
else
echo "Found previous release: $PREVIOUS_TAG"
REF=$PREVIOUS_TAG
fi

echo "The reference point is: $REF"
echo "ref=$REF" >> $GITHUB_OUTPUT

- name: Detect changed variants
uses: dorny/paths-filter@v3
id: filter
with:
filters: .github/filters.yml
base: ${{ steps.previous_release.outputs.ref }}

release:
name: Release ${{ matrix.variant }}
needs: changes
runs-on: ubuntu-latest
if: needs.changes.outputs.variants != '[]'
permissions:
contents: write
strategy:
fail-fast: false
matrix:
variant: ${{ fromJson(needs.changes.outputs.variants) }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'

- name: Get composer cache directory
id: composer-cache
working-directory: ./publish
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('publish/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
working-directory: ./publish
run: composer install --prefer-dist

- name: Pull image from registry
run: |
TAG=$(echo "${{ matrix.variant }}" | sed 's/^php//')
docker pull ghcr.io/${{ github.repository_owner }}/php:$TAG

- name: Export artifact
env:
DOCKER_REGISTRY: ghcr.io
DOCKER_IMAGE: ${{ github.repository_owner }}/php
run: make export/${{ matrix.variant }}

- name: Upload release asset
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload ${{ github.event.release.tag_name }} \
./export/${{ matrix.variant }}.zip \
--clobber

- name: Publish to Alibaba Cloud
env:
OSS_BUCKET: ${{ secrets.OSS_BUCKET }}
ACS_ACCESS_KEY_ID: ${{ secrets.ACS_ACCESS_KEY_ID }}
ACS_ACCESS_KEY_SECRET: ${{ secrets.ACS_ACCESS_KEY_SECRET }}
run: |
RELEASE="${{ github.event.release.tag_name }}" \
make publish-${{ matrix.variant }}
15 changes: 9 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
OBJECTS = php81 php82 php83 php84
VARIANTS = $(addsuffix -debian11,$(OBJECTS)) $(addsuffix -debian12,$(OBJECTS))
DOCKER_REGISTRY ?= ghcr.io
DOCKER_IMAGE ?= dew-serverless/php
DOCKER_BUILD_EXTRA ?=

.PHONY: build export publish clean
Expand All @@ -8,8 +10,7 @@ build-%:
BUILD_ARGS="$(shell awk '/^[a-zA-Z0-9]+ *=/ { printf "--build-arg %s_VERSION=%s ", toupper($$1), $$3 }' "$*/dependencies.ini" | xargs)" && \
docker buildx build $$BUILD_ARGS $(DOCKER_BUILD_EXTRA) \
--load \
-t dew/$* \
-t ghcr.io/dew-serverless/php:$(subst php,,$*) \
-t $(DOCKER_BUILD_EXTRA)/$(DOCKER_IMAGE):$(subst php,,$*) \
.

build: $(addprefix build-,$(VARIANTS))
Expand All @@ -25,18 +26,20 @@ test-%:
test: test-setup $(addprefix test-,$(VARIANTS))

export/%:
CID=$$(docker create dew/$*) && docker cp $$CID:/opt ./export/$* && docker rm $$CID
cd export/$*; zip -r ../$*.zip .
CID=$$(docker create $(DOCKER_REGISTRY)/$(DOCKER_IMAGE):$(subst php,,$*)) && \
docker cp $$CID:/opt ./export/$* && \
docker rm $$CID && \
cd export/$* && zip -r ../$*.zip .

export: $(addprefix export/,$(VARIANTS))

publish-%: export/%
php publish/publish.php $*
php publish/publish.php $* $(RELEASE)

publish: $(addprefix publish-,$(VARIANTS))

push-%: build-%
docker push ghcr.io/dew-serverless/php:$(subst php,,$*)
docker push $(DOCKER_REGISTRY)/$(DOCKER_IMAGE):$(subst php,,$*)

push: $(addprefix push-,$(VARIANTS))

Expand Down
4 changes: 2 additions & 2 deletions publish/Crc64.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ final class Crc64
0xD80C07CD << 32 | 0x676F8394, 0x9AFCE626 << 32 | 0xCE85B507,
];

public static function make(string $value): int
public static function make(string $value): string
{
// Final XOR: 0xFFFFFFFFFFFFFFFF
$finalXor = (1 << 64) - 1;
Expand All @@ -177,7 +177,7 @@ public static function make(string $value): int

$checksum = static::reflect64($checksum);

return $checksum ^ $finalXor;
return sprintf('%u', $checksum ^ $finalXor);
}

private static function reflect8(int $value): int
Expand Down
2 changes: 1 addition & 1 deletion publish/composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"require": {
"dew-serverless/acs-sdk-php": "^0.7.0",
"dew-serverless/acs-sdk-php": "^0.9.0",
"php-http/guzzle7-adapter": "^1.1",
"guzzlehttp/guzzle": "^7.0"
},
Expand Down
14 changes: 7 additions & 7 deletions publish/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading