seafile-containerized/.github/workflows/auto_release.yml

105 lines
3.8 KiB
YAML
Raw Normal View History

2023-08-26 09:26:17 +00:00
name: Automatic Release
on:
push:
branches:
2023-08-26 11:01:45 +00:00
- master
2023-08-26 09:32:24 +00:00
paths:
- 'seafile-server/**'
- 'seahub/**'
- 'seahub-media/**'
workflow_dispatch:
inputs:
folder:
description: 'Which folder to release (seafile-server/seahub/seahub-media)?'
required: true
2023-08-26 09:26:17 +00:00
jobs:
create_release:
runs-on: ubuntu-latest
2023-08-26 13:56:50 +00:00
strategy:
matrix:
folder: ['seafile-server', 'seahub', 'seahub-media']
fail-fast: false
2023-08-26 09:26:17 +00:00
steps:
- name: Check out code
2023-08-26 09:36:31 +00:00
uses: actions/checkout@v3
2023-08-26 10:30:20 +00:00
with:
fetch-depth: 0
2023-08-26 09:26:17 +00:00
- name: Determine Changed Directory and Extract Version
id: dir_version
run: |
2023-08-26 09:32:24 +00:00
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
FOLDER_CHANGED=${{ github.event.inputs.folder }}
else
2023-08-26 13:56:50 +00:00
CHANGED_FOLDERS=$(git diff --name-only HEAD^ HEAD | cut -d '/' -f1 | uniq)
[[ "$CHANGED_FOLDERS" =~ "${{ matrix.folder }}" ]] && FOLDER_CHANGED="${{ matrix.folder }}" || FOLDER_CHANGED=""
2023-08-26 09:32:24 +00:00
fi
2023-08-26 13:56:50 +00:00
echo "FOLDER_CHANGED=$FOLDER_CHANGED"
if [ -z "$FOLDER_CHANGED" ]; then
echo "Skipping as ${{ matrix.folder }} didn't change."
exit 0
fi
2023-08-26 09:26:17 +00:00
if [[ -f "$FOLDER_CHANGED/Dockerfile" ]]; then
2023-08-26 11:22:49 +00:00
SEAFILE_VERSION=$(grep -m 1 'SEAFILE_VERSION' $FOLDER_CHANGED/Dockerfile | awk -F'SEAFILE_VERSION=' '{print $2}' | awk '{print $1}' | tr -d '\n')
2023-08-26 09:26:17 +00:00
echo "SEAFILE_VERSION=$SEAFILE_VERSION" >> $GITHUB_ENV
fi
2023-08-26 11:59:05 +00:00
- name: Get Previous Tag and Build Number
2023-08-26 13:56:50 +00:00
if: env.FOLDER_CHANGED != '' && env.SEAFILE_VERSION != ''
2023-08-26 09:26:17 +00:00
id: build_number
run: |
2023-08-26 12:07:43 +00:00
LATEST_TAG=$(curl -sH "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/tags?per_page=100" | \
jq -r --arg FOLDER "$FOLDER_CHANGED" --arg VERSION "$SEAFILE_VERSION" '.[] | select(.name | startswith($FOLDER + "-" + $VERSION)) | .name' | sort -V | tail -1)
2023-08-26 13:56:50 +00:00
2023-08-26 09:58:49 +00:00
echo "LATEST_TAG=$LATEST_TAG"
2023-08-26 11:59:05 +00:00
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
2023-08-26 09:45:24 +00:00
if [[ $LATEST_TAG ]]; then
2023-08-26 09:58:49 +00:00
PREVIOUS_BUILD=$(echo $LATEST_TAG | awk -F_ '{print $2}')
echo "PREVIOUS_BUILD=$PREVIOUS_BUILD"
2023-08-26 09:48:51 +00:00
NEXT_BUILD=$(printf "%03d" $((PREVIOUS_BUILD + 1)))
2023-08-26 09:26:17 +00:00
else
NEXT_BUILD="001"
fi
echo "NEXT_BUILD=$NEXT_BUILD" >> $GITHUB_ENV
2023-08-26 09:58:49 +00:00
echo "NEXT_BUILD = $NEXT_BUILD"
2023-08-26 09:26:17 +00:00
- name: Get Commit Messages
2023-08-26 13:56:50 +00:00
if: env.FOLDER_CHANGED != '' && env.SEAFILE_VERSION != ''
2023-08-26 10:42:27 +00:00
id: get_messages
2023-08-26 09:26:17 +00:00
run: |
2023-08-26 10:14:54 +00:00
MESSAGES=""
2023-08-26 11:59:05 +00:00
if [[ -z "$LATEST_TAG" ]]; then
2023-08-26 10:25:44 +00:00
COMMIT_RANGE="--all"
else
2023-08-26 11:59:05 +00:00
LAST_COMMIT_FOR_TAG=$(git rev-list -n 1 refs/tags/$LATEST_TAG)
2023-08-26 10:25:44 +00:00
COMMIT_RANGE="${LAST_COMMIT_FOR_TAG}..HEAD"
fi
2023-08-26 10:36:03 +00:00
2023-08-26 10:25:44 +00:00
for commit in $(git log --pretty=format:'%H' $COMMIT_RANGE); do
if git diff-tree --no-commit-id --name-only -r $commit | grep "^$FOLDER_CHANGED/"; then
MESSAGE=$(git log --format=%B -n 1 $commit)
2023-08-26 10:42:27 +00:00
MESSAGES="$MESSAGES- $commit: $MESSAGE"$'\n'
2023-08-26 10:25:44 +00:00
fi
2023-08-26 10:14:54 +00:00
done
2023-08-26 10:36:03 +00:00
2023-08-26 10:42:27 +00:00
MESSAGES="Seafile version: $SEAFILE_VERSION"$'\n'"Image build version: $NEXT_BUILD"$'\n'"Changelog:"$'\n'"$MESSAGES"
2023-08-26 10:49:45 +00:00
echo "::set-output name=formatted_messages::${MESSAGES//$'\n'/'%0A'}"
2023-08-26 09:26:17 +00:00
- name: Create Release
if: env.FOLDER_CHANGED != '' && env.SEAFILE_VERSION != ''
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
2023-08-26 09:42:09 +00:00
tag_name: ${{ env.FOLDER_CHANGED }}-${{ env.SEAFILE_VERSION }}_${{ env.NEXT_BUILD }}
release_name: ${{ env.FOLDER_CHANGED }}-${{ env.SEAFILE_VERSION }}_${{ env.NEXT_BUILD }}
2023-08-26 10:42:27 +00:00
body: ${{ steps.get_messages.outputs.formatted_messages }}
2023-08-26 09:26:17 +00:00
draft: false
2023-08-26 13:56:50 +00:00
prerelease: false