Automatic Release #26
This file contains 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: Automatic Release | |
on: | |
push: | |
branches: | |
- master | |
paths: | |
- 'seafile-server/**' | |
- 'seahub/**' | |
- 'seahub-media/**' | |
workflow_dispatch: | |
inputs: | |
folder: | |
description: 'Which folder to release (seafile-server/seahub/seahub-media)?' | |
required: true | |
jobs: | |
create_release: | |
runs-on: ubuntu-latest | |
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 | |
FOLDER_CHANGED=$(git diff --name-only HEAD^ HEAD | cut -d '/' -f1 | uniq) | |
fi | |
if [[ -f "$FOLDER_CHANGED/Dockerfile" ]]; then | |
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 | |
echo "FOLDER_CHANGED=$FOLDER_CHANGED" >> $GITHUB_ENV | |
- name: Get Previous Tag and Build Number | |
id: build_number | |
run: | | |
PAGE=1 | |
LATEST_TAG="" | |
while true; do | |
TAGS=$(curl -sH "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
"https://api.github.com/repos/${{ github.repository }}/tags?per_page=100&page=$PAGE") | |
if [[ -z "$TAGS" ]]; then | |
break | |
fi | |
TAG=$(echo "$TAGS" | jq -r --arg FOLDER "$FOLDER_CHANGED" --arg VERSION "$SEAFILE_VERSION" '.[] | select(.name | startswith($FOLDER + "-" + $VERSION)) | .name' | sort -V | tail -1) | |
if [[ -n "$TAG" ]] && [[ -z "$LATEST_TAG" || "$TAG" > "$LATEST_TAG" ]]; then | |
LATEST_TAG="$TAG" | |
fi | |
PAGE=$((PAGE + 1)) | |
done | |
echo "LATEST_TAG=$LATEST_TAG" | |
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV | |
if [[ $LATEST_TAG ]]; then | |
PREVIOUS_BUILD=$(echo $LATEST_TAG | awk -F_ '{print $2}') | |
echo "PREVIOUS_BUILD=$PREVIOUS_BUILD" | |
NEXT_BUILD=$(printf "%03d" $((PREVIOUS_BUILD + 1))) | |
else | |
NEXT_BUILD="001" | |
fi | |
echo "NEXT_BUILD=$NEXT_BUILD" >> $GITHUB_ENV | |
echo "NEXT_BUILD = $NEXT_BUILD" | |
- name: Get Commit Messages | |
id: get_messages | |
run: | | |
MESSAGES="" | |
if [[ -z "$LATEST_TAG" ]]; then | |
COMMIT_RANGE="--all" | |
else | |
LAST_COMMIT_FOR_TAG=$(git rev-list -n 1 refs/tags/$LATEST_TAG) | |
COMMIT_RANGE="${LAST_COMMIT_FOR_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 | |
MESSAGES="Seafile version: $SEAFILE_VERSION"$'\n'"Image build version: $NEXT_BUILD"$'\n'"Changelog:"$'\n'"$MESSAGES" | |
echo "::set-output name=formatted_messages::${MESSAGES//$'\n'/'%0A'}" | |
- name: Create Release | |
if: env.FOLDER_CHANGED != '' && env.SEAFILE_VERSION != '' | |
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: ${{ steps.get_messages.outputs.formatted_messages }} | |
draft: false | |
prerelease: false |