docker-php-extension-installer/.github/workflows/readme-release.yml

212 lines
8.0 KiB
YAML
Raw Normal View History

name: Update README and create release
2020-11-06 16:49:49 +00:00
on:
push:
branches:
- master
create:
tags:
- "*"
repository_dispatch:
types:
- readme-release
workflow_dispatch:
2020-11-06 16:49:49 +00:00
jobs:
2021-02-25 10:09:05 +00:00
readme-release:
2020-11-06 16:49:49 +00:00
runs-on: ubuntu-latest
env:
VERSIONTAG_THIS: ""
steps:
2024-09-09 15:39:17 +00:00
-
name: Checkout
if: >
(github.event_name == 'push' && github.ref == 'refs/heads/master')
|| (github.event_name == 'create' && github.event.ref_type == 'tag')
|| github.event_name == 'repository_dispatch'
2024-06-24 10:03:47 +00:00
uses: actions/checkout@v4
2020-11-06 16:49:49 +00:00
with:
ref: master
fetch-depth: 0
2024-09-09 15:39:17 +00:00
-
name: Update README
if: >
(github.event_name == 'push' && github.ref == 'refs/heads/master')
|| github.event_name == 'repository_dispatch'
run: |
./scripts/update-readme
if ! git ls-files -m | grep -qE '^README\.md$'; then
echo 'README.md has not been changed'
else
echo 'README.md has been updated'
git config user.name 'Michele Locati'
git config user.email 'michele@locati.it'
git add README.md
git commit -m '[skip ci] Automatically update README.md'
git push
fi
2024-09-09 15:39:17 +00:00
-
name: Look for the recent version tags
if: >
(github.event_name == 'push' && github.ref == 'refs/heads/master')
|| (github.event_name == 'create' && github.event.ref_type == 'tag')
|| github.event_name == 'repository_dispatch'
2020-11-06 16:49:49 +00:00
run: |
TAGS="$(git tag --list --sort=-version:refname)"
VERSIONTAG_LAST=
VERSIONTAG_PENULTIMATE=
for TAG in $(git tag --list --sort=-version:refname); do
if printf '%s' "$TAG" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
if test -z "$VERSIONTAG_LAST"; then
VERSIONTAG_LAST="$TAG"
else
VERSIONTAG_PENULTIMATE="$TAG"
break
fi
fi
done
if test -z "$VERSIONTAG_LAST"; then
printf 'Most recent version tag: <none>\n'
else
printf 'Most recent version tag: %s\n' "$VERSIONTAG_LAST"
fi
printf 'VERSIONTAG_LAST=%s\n' "$VERSIONTAG_LAST" >> "$GITHUB_ENV"
printf 'VERSIONTAG_PENULTIMATE=%s\n' "$VERSIONTAG_PENULTIMATE" >> "$GITHUB_ENV"
2024-09-09 15:39:17 +00:00
-
name: Check if we need to create a version tag after a push
2020-11-06 16:49:49 +00:00
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
run: |
VERSIONTAG_THIS=
2020-11-06 16:49:49 +00:00
if test -z "$VERSIONTAG_LAST"; then
printf 'We need to create the first version tag\n'
VERSIONTAG_THIS=1.0.0
elif test "$(git rev-parse HEAD)" = "$(git rev-list -n 1 "refs/tags/$VERSIONTAG_LAST")"; then
2020-11-06 17:20:11 +00:00
printf 'Another action should already take care of creating the release\n'
2020-11-06 16:49:49 +00:00
else
CREATE_TAG=n
for CHANGED_FILE in $(git diff --name-only "refs/tags/$VERSIONTAG_LAST" HEAD); do
case "$CHANGED_FILE" in
2023-12-14 15:16:19 +00:00
install-php-extensions | Dockerfile)
2020-11-06 16:49:49 +00:00
CREATE_TAG=y
;;
esac
done
if test "$CREATE_TAG" = 'y'; then
VERSIONTAG_THIS="${VERSIONTAG_LAST%.*}.$((${VERSIONTAG_LAST##*.}+1))"
printf 'We need to create new version tag %s since relevant files changed\n' "$VERSIONTAG_THIS"
else
printf 'We do not need to create a new version tag since no relevant files changed\n'
fi
fi
printf 'VERSIONTAG_THIS=%s\n' "$VERSIONTAG_THIS" >> "$GITHUB_ENV"
printf 'VERSIONTAG_PREVIOUS=%s\n' "$VERSIONTAG_LAST" >> "$GITHUB_ENV"
2024-09-09 15:39:17 +00:00
-
name: Sleep for a while before creating a tag
if: env.VERSIONTAG_THIS != ''
uses: juliangruber/sleep-action@v1
with:
time: 30s
2024-09-09 15:39:17 +00:00
-
name: Create version tag after a push in the local repository
if: env.VERSIONTAG_THIS != ''
run: |
git tag -- "$VERSIONTAG_THIS"
2020-12-09 13:01:10 +00:00
printf 'VERSIONTAG_THIS_SHA=%s\n' "$(git rev-parse HEAD)" >> "$GITHUB_ENV"
2024-09-09 15:39:17 +00:00
-
name: Create version tag after a push in the remote repository
if: env.VERSIONTAG_THIS != ''
2020-11-06 16:49:49 +00:00
uses: actions/github-script@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${process.env.VERSIONTAG_THIS}`,
2020-12-09 13:01:10 +00:00
sha: process.env.VERSIONTAG_THIS_SHA
2020-11-06 16:49:49 +00:00
})
2024-09-09 15:39:17 +00:00
-
name: Check format of received tag
2020-11-06 16:49:49 +00:00
if: github.event_name == 'create' && github.event.ref_type == 'tag'
run: |
VERSIONTAG_THIS="${GITHUB_REF#refs/tags/}"
2020-11-06 17:05:34 +00:00
if test "$VERSIONTAG_THIS" = "$VERSIONTAG_LAST"; then
2020-11-06 16:49:49 +00:00
if printf '%s' "$VERSIONTAG_THIS" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
printf 'Tag %s is version-like\n' "$VERSIONTAG_THIS"
else
printf 'Tag %s is not version-like\n' "$VERSIONTAG_THIS"
VERSIONTAG_THIS=
fi
else
printf 'Last created tag %s is not %\n' "$VERSIONTAG_THIS" "$VERSIONTAG_LAST"
VERSIONTAG_THIS=
fi
printf 'VERSIONTAG_THIS=%s\n' "$VERSIONTAG_THIS" >> "$GITHUB_ENV"
printf 'VERSIONTAG_PREVIOUS=%s\n' "$VERSIONTAG_PENULTIMATE" >> "$GITHUB_ENV"
2024-09-09 15:39:17 +00:00
-
name: Extract release notes
2020-11-06 16:49:49 +00:00
if: env.VERSIONTAG_THIS != ''
run: |
printf 'Generating release notes for tag %s\n' "$VERSIONTAG_THIS"
if test -z "$VERSIONTAG_PREVIOUS"; then
echo 'No previous tag found'
RELEASE_NOTES='First version'
else
printf 'Generating release notes for commits between %s and %s\n' "$VERSIONTAG_PREVIOUS" "$VERSIONTAG_THIS"
RELEASE_NOTES="$(git log --format='- %s' --no-merges --reverse "refs/tags/$VERSIONTAG_PREVIOUS...refs/tags/$VERSIONTAG_THIS" -- ./install-php-extensions ./Dockerfile | grep -vE '^- \[minor\]')"
2020-11-06 16:49:49 +00:00
fi
printf 'Release notes:\n%s\n' "$RELEASE_NOTES"
printf 'RELEASE_NAME=v%s\n' "$VERSIONTAG_THIS" >> "$GITHUB_ENV"
printf 'RELEASE_NOTES<<EOF\n%s\nEOF\n' "$RELEASE_NOTES" >> "$GITHUB_ENV"
2024-09-09 15:39:17 +00:00
-
name: Set script version
2021-01-14 16:05:23 +00:00
if: env.VERSIONTAG_THIS != ''
run: sed -i -E "s/^(IPE_VERSION=)master$/\1$VERSIONTAG_THIS/" install-php-extensions
2024-09-09 15:39:17 +00:00
-
name: Login to Docker Hub
if: env.VERSIONTAG_THIS != ''
uses: docker/login-action@v3
with:
username: mlocati
password: ${{ secrets.DOCKERHUB_TOKEN }}
2024-09-09 15:39:17 +00:00
-
name: Set up docker buildx
uses: docker/setup-buildx-action@v2
with:
install: true
2024-09-09 15:39:17 +00:00
-
name: Build and push docker image
2021-01-14 16:38:16 +00:00
if: env.VERSIONTAG_THIS != ''
uses: docker/build-push-action@v5
with:
push: true
tags: |
mlocati/php-extension-installer:$VERSIONTAG_THIS
mlocati/php-extension-installer:${VERSIONTAG_THIS%.*}
mlocati/php-extension-installer:${VERSIONTAG_THIS%%.*}
mlocati/php-extension-installer:latest
# Build for all platforms also supported by php images (https://hub.docker.com/_/php/tags)
platforms: |
linux/386
linux/amd64
linux/arm/v5
linux/arm/v7
linux/arm64/v8
linux/mips64le
linux/ppc64le
linux/s390x
2024-09-09 15:39:17 +00:00
-
name: Create release
2020-11-06 16:49:49 +00:00
if: env.VERSIONTAG_THIS != ''
uses: softprops/action-gh-release@v2
2020-11-06 16:49:49 +00:00
with:
tag_name: ${{ env.VERSIONTAG_THIS }}
name: ${{ env.RELEASE_NAME }}
2020-11-06 16:49:49 +00:00
body: ${{ env.RELEASE_NOTES }}
2021-12-05 18:38:50 +00:00
draft: false
2020-11-06 16:49:49 +00:00
prerelease: false
generate_release_notes: false
fail_on_unmatched_files: true
files: |
install-php-extensions