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

96 lines
3.3 KiB
YAML
Raw Normal View History

2023-08-26 09:26:17 +00:00
name: Automatic Release
on:
2023-08-27 12:21:26 +00:00
schedule:
- cron: '0 0 * * *' # Scheduled to run every day at midnight
2023-08-27 12:34:52 +00:00
workflow_dispatch: {}
2023-08-26 09:26:17 +00:00
jobs:
create_release:
runs-on: ubuntu-latest
2023-08-30 12:33:37 +00:00
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2023-08-26 13:56:50 +00:00
strategy:
matrix:
2023-08-27 08:50:24 +00:00
folder: ['seafile-server', 'seahub', 'seahub-media', 'seafile-caddy']
2023-08-26 13:56:50 +00:00
fail-fast: false
2023-08-27 12:21:26 +00:00
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
2023-08-27 12:34:52 +00:00
- name: Get Previous Tag and Build Number
id: build_number
run: |
LATEST_TAG=$(git describe --tags --match "${{ matrix.folder }}-*" 2>/dev/null)
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
if [[ -n "$LATEST_TAG" ]]; then
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
2023-08-26 09:26:17 +00:00
- name: Determine Changed Directory and Extract Version
id: dir_version
run: |
2023-08-27 12:34:52 +00:00
if [[ -z "$LATEST_TAG" ]]; then
COMMIT_RANGE="--all"
2023-08-26 09:32:24 +00:00
else
2023-08-27 12:34:52 +00:00
COMMIT_RANGE="${LATEST_TAG}..HEAD"
2023-08-26 09:32:24 +00:00
fi
2023-08-27 12:34:52 +00:00
CHANGED_FOLDERS=$(git diff --name-only $COMMIT_RANGE | cut -d '/' -f1 | uniq)
[[ "$CHANGED_FOLDERS" =~ "${{ matrix.folder }}" ]] && FOLDER_CHANGED="${{ matrix.folder }}" || FOLDER_CHANGED=""
2023-08-26 13:56:50 +00:00
if [ -z "$FOLDER_CHANGED" ]; then
2023-08-27 12:49:52 +00:00
echo "PROCEED=false" >> $GITHUB_ENV
2023-08-27 12:36:18 +00:00
exit 0
2023-08-26 13:56:50 +00:00
fi
2023-08-26 15:26:38 +00:00
echo "FOLDER_CHANGED=$FOLDER_CHANGED" >> $GITHUB_ENV
2023-08-27 12:21:26 +00:00
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
2023-08-27 08:50:24 +00:00
fi
2023-08-26 09:26:17 +00:00
2023-08-30 12:33:37 +00:00
- name: Get Commit Messages and Write to Markdown
2023-08-27 12:49:52 +00:00
if: env.PROCEED != 'false'
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 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-27 12:21:26 +00:00
if [ -z "$MESSAGES" ]; then
2023-08-27 12:49:52 +00:00
echo "PROCEED=false" >> $GITHUB_ENV
2023-08-27 12:36:18 +00:00
exit 0
2023-08-27 11:58:14 +00:00
fi
2023-08-26 10:36:03 +00:00
2023-08-27 08:50:24 +00:00
if [[ "$FOLDER_CHANGED" == "seafile-caddy" ]]; then
2023-08-30 12:33:37 +00:00
echo "Caddy version: $SEAFILE_VERSION" > RELEASE_NOTES.md
2023-08-27 08:50:24 +00:00
else
2023-08-30 12:33:37 +00:00
echo "Seafile version: $SEAFILE_VERSION" > RELEASE_NOTES.md
2023-08-27 08:50:24 +00:00
fi
2023-08-30 12:33:37 +00:00
echo "Image build version: $NEXT_BUILD" >> RELEASE_NOTES.md
echo "Changelog:" >> RELEASE_NOTES.md
echo -e "$MESSAGES" >> RELEASE_NOTES.md
2023-08-26 09:26:17 +00:00
2023-08-30 12:33:37 +00:00
- name: Create and Upload GitHub Release
2023-08-27 12:49:52 +00:00
if: env.PROCEED != 'false'
2023-08-30 12:33:37 +00:00
run: |
gh release create ${{ env.FOLDER_CHANGED }}-${{ env.SEAFILE_VERSION }}_${{ env.NEXT_BUILD }} \
-t ${{ env.FOLDER_CHANGED }}-${{ env.SEAFILE_VERSION }}_${{ env.NEXT_BUILD }} \
-F RELEASE_NOTES.md \
--draft=false \
--prerelease=false