Check and upgrade tengine container version #73
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Check and upgrade tengine container version | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 0 * * *' | |
permissions: | |
contents: write | |
packages: write | |
jobs: | |
upgrade-container-version: | |
name: "Upgrade container version" | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
item: [simple, min] | |
steps: | |
- name: Set build flags by version | |
id: set-config | |
run: | | |
echo "Set '${{ matrix.item }}' version file and config flags" | |
ITEM="${{ matrix.item }}" | |
version_file="version_${ITEM}" | |
echo "version_file=${version_file}" >> $GITHUB_OUTPUT | |
- name: Clone repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-tags: true | |
fetch-depth: 0 | |
- name: Clone tengine repository | |
uses: actions/checkout@v4 | |
with: | |
repository: alibaba/tengine | |
ref: master | |
path: int.tmp | |
fetch-tags: true | |
fetch-depth: 0 | |
- name: Check version | |
id: check-version | |
shell: bash | |
run: | | |
cd int.tmp | |
TAG=$(git tag -l '[0-9]*.[0-9]*.[0-9]*' | sort -V | tail -n 1) | |
git checkout $TAG | |
echo -n "${TAG#v}" > version | |
cd .. | |
if [ ! -f "./tengine/${{ steps.set-config.outputs.version_file }}" ]; then | |
echo -n "0.0.0" > ./tengine/${{ steps.set-config.outputs.version_file }} | |
fi | |
LAST_VERSION=$(cat ./int.tmp/version) | |
CURRENT_VERSION=$(cat ./tengine/${{ steps.set-config.outputs.version_file }}) | |
IFS='.' read -r -a last_version_parts <<< "$LAST_VERSION" | |
IFS='.' read -r -a current_version_parts <<< "$CURRENT_VERSION" | |
action="" | |
for i in {0..2}; do | |
if (( ${last_version_parts[i]} > ${current_version_parts[i]} )); then | |
action="update" | |
break | |
fi | |
done | |
if [ -z "$action" ]; then | |
action="no-change" | |
fi | |
echo "$action" | |
echo "action=${action}" >> $GITHUB_OUTPUT | |
echo "version=${LAST_VERSION}" >> $GITHUB_OUTPUT | |
- name: Set up QEMU | |
if: steps.check-version.outputs.action == 'update' | |
id: qemu | |
uses: docker/setup-qemu-action@v3 | |
with: | |
image: tonistiigi/binfmt:latest | |
platforms: all | |
- name: Set up Docker Buildx | |
if: steps.check-version.outputs.action == 'update' | |
id: buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Docker Login | |
if: steps.check-version.outputs.action == 'update' | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push container image | |
if: steps.check-version.outputs.action == 'update' | |
run: | | |
version="${{ steps.check-version.outputs.version }}" | |
build_type="${{ matrix.item }}" | |
make push PROJECT=tengine VERSION=$version IMG_TAG_EXTRA="-$build_type" IMG_BUILD_TYPE="$build_type" | |
- name: Git version change and push | |
if: steps.check-version.outputs.action == 'update' | |
run: | | |
author_name=$(git log -1 --pretty=format:'%an') | |
author_email=$(git log -1 --pretty=format:'%ae') | |
git config user.name "${author_name}" | |
git config user.email "${author_email}" | |
version="${{ steps.check-version.outputs.version }}" | |
echo -n "${version}" > tengine/${{ steps.set-config.outputs.version_file }} | |
git pull | |
sleep 3 | |
git pull | |
git add . | |
git commit -m "feat: [bot] upgrade container image tengine '${{ matrix.item }}' to '${version}' version" | |
git push origin ${{ github.event.repository.default_branch }} |