-
Notifications
You must be signed in to change notification settings - Fork 22
68 lines (61 loc) · 2.34 KB
/
auto_release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
name: Automatic Release
on:
push:
branches:
- main
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@v2
- 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 'SEAFILE_VERSION' $FOLDER_CHANGED/Dockerfile | awk -F'SEAFILE_VERSION=' '{print $2}' | awk '{print $1}')
echo "SEAFILE_VERSION=$SEAFILE_VERSION" >> $GITHUB_ENV
fi
echo "FOLDER_CHANGED=$FOLDER_CHANGED" >> $GITHUB_ENV
- name: Get Previous Build Number and Compute Next
id: build_number
run: |
PREVIOUS_BUILD=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/releases | \
jq -r --arg FOLDER "$FOLDER_CHANGED" '.[] | select(.name | startswith($FOLDER)) | .name' | head -1 | awk -F_ '{print $3}')
if [[ $PREVIOUS_BUILD ]]; then
NEXT_BUILD=$(printf "%03d" $((10#$PREVIOUS_BUILD + 1)))
else
NEXT_BUILD="001"
fi
echo "NEXT_BUILD=$NEXT_BUILD" >> $GITHUB_ENV
- name: Get Commit Messages
id: commit_messages
run: |
MESSAGES=$(git log --pretty=format:"%s" -- "$FOLDER_CHANGED" $(git describe --tags --abbrev=0)..HEAD)
echo "MESSAGES=$MESSAGES" >> $GITHUB_ENV
- 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: ${{ env.MESSAGES }}
draft: false
prerelease: false