Skip to content

Commit ec5076c

Browse files
authored
Merge pull request #16 from dew-serverless/ci-release
Introduce release workflow
2 parents 2a202cc + ab3ebf4 commit ec5076c

File tree

8 files changed

+263
-79
lines changed

8 files changed

+263
-79
lines changed

.github/filters.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
php84-debian12:
2+
- 'php84-debian12/**'
3+
- 'Dockerfile'
4+
5+
php84-debian11:
6+
- 'php84-debian11/**'
7+
- 'Dockerfile'
8+
9+
php83-debian12:
10+
- 'php83-debian12/**'
11+
- 'Dockerfile'
12+
13+
php83-debian11:
14+
- 'php83-debian11/**'
15+
- 'Dockerfile'
16+
17+
php82-debian12:
18+
- 'php82-debian12/**'
19+
- 'Dockerfile'
20+
21+
php82-debian11:
22+
- 'php82-debian11/**'
23+
- 'Dockerfile'
24+
25+
php81-debian12:
26+
- 'php81-debian12/**'
27+
- 'Dockerfile'
28+
29+
php81-debian11:
30+
- 'php81-debian11/**'
31+
- 'Dockerfile'

.github/workflows/build.yml

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,53 +7,55 @@ jobs:
77
changes:
88
name: Detect Changes
99
runs-on: ubuntu-latest
10-
permissions:
11-
pull-requests: read
1210
outputs:
1311
variants: ${{ steps.filter.outputs.changes }}
1412
steps:
1513
- name: Checkout code
1614
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: ${{ startsWith(github.ref, 'refs/tags/v') && 0 || 1 }}
17+
18+
- name: Retrieve the previous release version
19+
if: startsWith(github.ref, 'refs/tags/v')
20+
id: previous_release
21+
env:
22+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
run: |
24+
# Attempt to get the tag of the second-to-last release
25+
PREVIOUS_TAG=$(gh release list --limit 2 --json tagName | jq -r '. | select(length > 1) | .[1].tagName')
26+
27+
if [[ -z "$PREVIOUS_TAG" ]]; then
28+
echo "No previous release found. Falling back to the first commit."
29+
REF=$(git rev-list --max-parents=0 HEAD)
30+
else
31+
echo "Found previous release: $PREVIOUS_TAG"
32+
REF=$PREVIOUS_TAG
33+
fi
34+
35+
echo "The reference point is: $REF"
36+
echo "ref=$REF" >> $GITHUB_OUTPUT
37+
1738
- uses: dorny/paths-filter@v3
1839
id: filter
1940
with:
20-
filters: |
21-
php84-debian12:
22-
- 'php84-debian12/**'
23-
- 'Dockerfile'
24-
php84-debian11:
25-
- 'php84-debian11/**'
26-
- 'Dockerfile'
27-
php83-debian12:
28-
- 'php83-debian12/**'
29-
- 'Dockerfile'
30-
php83-debian11:
31-
- 'php83-debian11/**'
32-
- 'Dockerfile'
33-
php82-debian12:
34-
- 'php82-debian12/**'
35-
- 'Dockerfile'
36-
php82-debian11:
37-
- 'php82-debian11/**'
38-
- 'Dockerfile'
39-
php81-debian12:
40-
- 'php81-debian12/**'
41-
- 'Dockerfile'
42-
php81-debian11:
43-
- 'php81-debian11/**'
44-
- 'Dockerfile'
41+
filters: .github/filters.yml
42+
base: ${{ startsWith(github.ref, 'refs/tags/v') && steps.previous_release.outputs.ref || '' }}
4543

4644
build:
4745
needs: changes
4846
name: Build ${{ matrix.variant }} image
4947
runs-on: ubuntu-latest
48+
if: needs.changes.outputs.variants != '[]'
5049
concurrency:
5150
group: build-${{ matrix.variant }}
5251
cancel-in-progress: true
5352
strategy:
5453
fail-fast: false
5554
matrix:
5655
variant: ${{ fromJson(needs.changes.outputs.variants) }}
56+
permissions:
57+
contents: read
58+
packages: write
5759
steps:
5860
- name: Checkout code
5961
uses: actions/checkout@v4
@@ -94,3 +96,15 @@ jobs:
9496

9597
- name: Test
9698
run: make test-setup test-${{ matrix.variant }}
99+
100+
- name: Login to GitHub Container Registry
101+
if: startsWith(github.ref, 'refs/tags/v')
102+
uses: docker/login-action@v3
103+
with:
104+
registry: ghcr.io
105+
username: ${{ github.actor }}
106+
password: ${{ secrets.GITHUB_TOKEN }}
107+
108+
- name: Push to GitHub Container Registry
109+
if: startsWith(github.ref, 'refs/tags/v')
110+
run: make push-${{ matrix.variant }}

.github/workflows/release.yml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Release
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
changes:
9+
name: Detect changes since last release
10+
runs-on: ubuntu-latest
11+
outputs:
12+
variants: ${{ steps.filter.outputs.changes }}
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Retrieve the previous release version
20+
id: previous_release
21+
env:
22+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
run: |
24+
# Attempt to get the tag of the second-to-last release
25+
PREVIOUS_TAG=$(gh release list --limit 2 --json tagName | jq -r '. | select(length > 1) | .[1].tagName')
26+
27+
if [[ -z "$PREVIOUS_TAG" ]]; then
28+
echo "No previous release found. Falling back to the first commit."
29+
REF=$(git rev-list --max-parents=0 HEAD)
30+
else
31+
echo "Found previous release: $PREVIOUS_TAG"
32+
REF=$PREVIOUS_TAG
33+
fi
34+
35+
echo "The reference point is: $REF"
36+
echo "ref=$REF" >> $GITHUB_OUTPUT
37+
38+
- name: Detect changed variants
39+
uses: dorny/paths-filter@v3
40+
id: filter
41+
with:
42+
filters: .github/filters.yml
43+
base: ${{ steps.previous_release.outputs.ref }}
44+
45+
release:
46+
name: Release ${{ matrix.variant }}
47+
needs: changes
48+
runs-on: ubuntu-latest
49+
if: needs.changes.outputs.variants != '[]'
50+
permissions:
51+
contents: write
52+
strategy:
53+
fail-fast: false
54+
matrix:
55+
variant: ${{ fromJson(needs.changes.outputs.variants) }}
56+
steps:
57+
- name: Checkout code
58+
uses: actions/checkout@v4
59+
60+
- name: Set up PHP
61+
uses: shivammathur/setup-php@v2
62+
with:
63+
php-version: '8.4'
64+
65+
- name: Get composer cache directory
66+
id: composer-cache
67+
working-directory: ./publish
68+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
69+
70+
- name: Cache dependencies
71+
uses: actions/cache@v4
72+
with:
73+
path: ${{ steps.composer-cache.outputs.dir }}
74+
key: ${{ runner.os }}-composer-${{ hashFiles('publish/composer.lock') }}
75+
restore-keys: ${{ runner.os }}-composer-
76+
77+
- name: Install dependencies
78+
working-directory: ./publish
79+
run: composer install --prefer-dist
80+
81+
- name: Pull image from registry
82+
run: |
83+
TAG=$(echo "${{ matrix.variant }}" | sed 's/^php//')
84+
docker pull ghcr.io/${{ github.repository_owner }}/php:$TAG
85+
86+
- name: Export artifact
87+
env:
88+
DOCKER_REGISTRY: ghcr.io
89+
DOCKER_IMAGE: ${{ github.repository_owner }}/php
90+
run: make export/${{ matrix.variant }}
91+
92+
- name: Upload release asset
93+
env:
94+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
95+
run: |
96+
gh release upload ${{ github.event.release.tag_name }} \
97+
./export/${{ matrix.variant }}.zip \
98+
--clobber
99+
100+
- name: Publish to Alibaba Cloud
101+
env:
102+
OSS_BUCKET: ${{ secrets.OSS_BUCKET }}
103+
ACS_ACCESS_KEY_ID: ${{ secrets.ACS_ACCESS_KEY_ID }}
104+
ACS_ACCESS_KEY_SECRET: ${{ secrets.ACS_ACCESS_KEY_SECRET }}
105+
run: |
106+
RELEASE="${{ github.event.release.tag_name }}" \
107+
make publish-${{ matrix.variant }}

Makefile

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
OBJECTS = php81 php82 php83 php84
22
VARIANTS = $(addsuffix -debian11,$(OBJECTS)) $(addsuffix -debian12,$(OBJECTS))
3+
DOCKER_REGISTRY ?= ghcr.io
4+
DOCKER_IMAGE ?= dew-serverless/php
35
DOCKER_BUILD_EXTRA ?=
46

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

1516
build: $(addprefix build-,$(VARIANTS))
@@ -25,18 +26,20 @@ test-%:
2526
test: test-setup $(addprefix test-,$(VARIANTS))
2627

2728
export/%:
28-
CID=$$(docker create dew/$*) && docker cp $$CID:/opt ./export/$* && docker rm $$CID
29-
cd export/$*; zip -r ../$*.zip .
29+
CID=$$(docker create $(DOCKER_REGISTRY)/$(DOCKER_IMAGE):$(subst php,,$*)) && \
30+
docker cp $$CID:/opt ./export/$* && \
31+
docker rm $$CID && \
32+
cd export/$* && zip -r ../$*.zip .
3033

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

3336
publish-%: export/%
34-
php publish/publish.php $*
37+
php publish/publish.php $* $(RELEASE)
3538

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

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

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

publish/Crc64.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ final class Crc64
156156
0xD80C07CD << 32 | 0x676F8394, 0x9AFCE626 << 32 | 0xCE85B507,
157157
];
158158

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

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

180-
return $checksum ^ $finalXor;
180+
return sprintf('%u', $checksum ^ $finalXor);
181181
}
182182

183183
private static function reflect8(int $value): int

publish/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"require": {
3-
"dew-serverless/acs-sdk-php": "^0.7.0",
3+
"dew-serverless/acs-sdk-php": "^0.9.0",
44
"php-http/guzzle7-adapter": "^1.1",
55
"guzzlehttp/guzzle": "^7.0"
66
},

publish/composer.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)