Skip to content

Automatic Release

Automatic Release #35

Workflow file for this run

name: Automatic Release
on:
schedule:
- cron: '0 0 * * *' # Scheduled to run every day at midnight
workflow_dispatch:
inputs:
folder:
description: 'Which folder to release?'
required: true
jobs:
create_release:
runs-on: ubuntu-latest
strategy:
matrix:
folder: ['seafile-server', 'seahub', 'seahub-media', 'seafile-caddy']
fail-fast: false
steps:
- name: Check out code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Determine Changed Directory and Extract Version
id: dir_version
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
FOLDER_CHANGED=${{ github.event.inputs.folder }}
else
CHANGED_FOLDERS=$(git diff --name-only $(git describe --tags --abbrev=0)..HEAD | cut -d '/' -f1 | uniq)
[[ "$CHANGED_FOLDERS" =~ "${{ matrix.folder }}" ]] && FOLDER_CHANGED="${{ matrix.folder }}" || FOLDER_CHANGED=""
fi
if [ -z "$FOLDER_CHANGED" ]; then
exit 78
fi
echo "FOLDER_CHANGED=$FOLDER_CHANGED" >> $GITHUB_ENV
if [[ "$FOLDER_CHANGED" == "seafile-caddy" ]]; then
CADDY_VERSION=$(grep -m 1 'FROM caddy:' $FOLDER_CHANGED/Dockerfile | awk -F':' '{print $2}' | awk -F'-' '{print $1}' | tr -d '\n')
echo "SEAFILE_VERSION=$CADDY_VERSION" >> $GITHUB_ENV
else
SEAFILE_VERSION=$(grep -m 1 'SEAFILE_VERSION' $FOLDER_CHANGED/Dockerfile | awk -F'SEAFILE_VERSION=' '{print $2}' | awk '{print $1}' | tr -d '\n')
echo "SEAFILE_VERSION=$SEAFILE_VERSION" >> $GITHUB_ENV
fi
- name: Get Previous Tag and Build Number
id: build_number
run: |
LATEST_TAG=$(git describe --tags --match "${{ env.FOLDER_CHANGED }}-*" 2>/dev/null)
if [[ -n "$LATEST_TAG" ]]; then
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
PREVIOUS_BUILD=$(echo $LATEST_TAG | awk -F_ '{print $2}')
NEXT_BUILD=$(printf "%03d" $((PREVIOUS_BUILD + 1)))
else
NEXT_BUILD="001"
fi
echo "NEXT_BUILD=$NEXT_BUILD" >> $GITHUB_ENV
- name: Get Commit Messages
id: get_messages
run: |
MESSAGES=""
if [[ -z "$LATEST_TAG" ]]; then
COMMIT_RANGE="--all"
else
COMMIT_RANGE="${LATEST_TAG}..HEAD"
fi
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)
MESSAGES="$MESSAGES- $commit: $MESSAGE"$'\n'
fi
done
if [ -z "$MESSAGES" ]; then
exit 78
fi
if [[ "$FOLDER_CHANGED" == "seafile-caddy" ]]; then
MESSAGES="Caddy version: $SEAFILE_VERSION"$'\n'"Image build version: $NEXT_BUILD"$'\n'"Changelog:"$'\n'"$MESSAGES"
else
MESSAGES="Seafile version: $SEAFILE_VERSION"$'\n'"Image build version: $NEXT_BUILD"$'\n'"Changelog:"$'\n'"$MESSAGES"
fi
MESSAGES="${MESSAGES//$'\n'/%0A}"
echo "MESSAGES=$MESSAGES" >> $GITHUB_ENV
- name: Create Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.FOLDER_CHANGED }}-${{ env.SEAFILE_VERSION }}_${{ env.NEXT_BUILD }}
release_name: ${{ env.FOLDER_CHANGED }}-${{ env.SEAFILE_VERSION }}_${{ env.NEXT_BUILD }}
body: |
${{ env.MESSAGES }}
draft: false
prerelease: false