Automatic Release #413
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: | |
workflow_dispatch: {} | |
jobs: | |
create_release: | |
runs-on: ubuntu-latest | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
strategy: | |
matrix: | |
folder: ['seafile-server', 'seahub', 'seahub-media', 'seafile-caddy'] | |
fail-fast: false | |
steps: | |
- name: Check out code | |
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 | |
with: | |
fetch-depth: 0 | |
- name: Get Previous Tag and Build Number | |
id: build_number | |
run: | | |
LATEST_TAG=$(git describe --tags --abbrev=0 --match "${{ matrix.folder }}-[0-9]*" 2>/dev/null) | |
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV | |
PREVIOUS_VERSION=$(echo $LATEST_TAG | awk -F'[-_]' '{print $(NF-1)}') | |
PREVIOUS_BUILD=$(echo $LATEST_TAG | awk -F_ '{print $2}') | |
if [[ "${{ matrix.folder }}" == "seafile-caddy" ]]; then | |
CURRENT_VERSION=$(grep -m 1 'FROM caddy:' ${{ matrix.folder }}/Dockerfile | awk -F':' '{print $2}' | awk -F'-' '{print $1}' | tr -d '\n') | |
else | |
CURRENT_VERSION=$(grep -m 1 'SEAFILE_VERSION' ${{ matrix.folder }}/Dockerfile | awk -F'SEAFILE_VERSION=' '{print $2}' | awk '{print $1}' | tr -d '\n') | |
fi | |
echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV | |
if [[ "$PREVIOUS_VERSION" != "$CURRENT_VERSION" ]] || [[ -z "$LATEST_TAG" ]]; then | |
NEXT_BUILD="001" | |
else | |
NEXT_BUILD=$(printf "%03d" $((10#$PREVIOUS_BUILD + 1))) | |
fi | |
echo "NEXT_BUILD=$NEXT_BUILD" >> $GITHUB_ENV | |
- name: Determine Changed Directory | |
id: dir_version | |
run: | | |
if [[ -z "$LATEST_TAG" ]]; then | |
COMMIT_RANGE="--all" | |
else | |
COMMIT_RANGE="${LATEST_TAG}..HEAD" | |
fi | |
echo "COMMIT_RANGE=${LATEST_TAG}..HEAD" >> $GITHUB_ENV | |
CHANGED_FOLDERS=$(git diff --name-only $COMMIT_RANGE | cut -d '/' -f1 | uniq) | |
[[ "$CHANGED_FOLDERS" =~ "${{ matrix.folder }}" ]] && FOLDER_CHANGED="${{ matrix.folder }}" || FOLDER_CHANGED="" | |
if [ -z "$FOLDER_CHANGED" ]; then | |
echo "PROCEED=false" >> $GITHUB_ENV | |
exit 0 | |
fi | |
echo "FOLDER_CHANGED=$FOLDER_CHANGED" >> $GITHUB_ENV | |
- name: Get Commit Messages and Write to Markdown | |
if: env.PROCEED != 'false' | |
id: get_messages | |
run: | | |
MESSAGES="" | |
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 | |
echo "PROCEED=false" >> $GITHUB_ENV | |
exit 0 | |
fi | |
if [[ "$FOLDER_CHANGED" == "seafile-caddy" ]]; then | |
echo "Caddy version: $CURRENT_VERSION" > RELEASE_NOTES.md | |
else | |
echo "Seafile version: $CURRENT_VERSION" > RELEASE_NOTES.md | |
fi | |
echo "Image build version: $NEXT_BUILD" >> RELEASE_NOTES.md | |
echo "Changelog:" >> RELEASE_NOTES.md | |
echo -e "$MESSAGES" >> RELEASE_NOTES.md | |
- name: Create and Upload GitHub Release | |
if: env.PROCEED != 'false' | |
run: | | |
gh release create ${{ env.FOLDER_CHANGED }}-${{ env.CURRENT_VERSION }}_${{ env.NEXT_BUILD }} \ | |
-t ${{ env.FOLDER_CHANGED }}-${{ env.CURRENT_VERSION }}_${{ env.NEXT_BUILD }} \ | |
-F RELEASE_NOTES.md \ | |
--draft=false \ | |
--prerelease=false |