-
-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (68 loc) · 2.9 KB
/
autorelease.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
69
70
71
72
73
74
75
76
77
78
79
name: Create Release with Assets and Details
on:
push:
branches:
- main
jobs:
create-release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Read version
id: read_version
run: |
VERSION=$(cat VERSION)
echo "Version: $VERSION"
echo "::set-output name=version::$VERSION"
- name: Get commit list
id: get_commits
run: |
COMMITS=$(git log --oneline --pretty=format:'* %h - %s by %an' | head -n 10)
echo "Commit list: $COMMITS"
echo "::set-output name=commits::$COMMITS"
- name: Get top contributors
id: get_contributors
run: |
CONTRIBUTORS=$(git shortlog -sn | head -n 5)
echo "Top contributors: $CONTRIBUTORS"
echo "::set-output name=contributors::$CONTRIBUTORS"
- name: Calculate size of source code
id: calculate_size
run: |
SIZE=$(du -sh . | cut -f1)
echo "Source code size: $SIZE"
echo "::set-output name=size::$SIZE"
- name: Create archives
run: |
VERSION=${{ steps.read_version.outputs.version }}
mkdir -p artifacts
rsync -a --exclude=artifacts . artifacts/source/
zip -r artifacts/source.zip artifacts/source
tar -czf artifacts/source.tar.gz -C artifacts source
7z a artifacts/source.7z artifacts/source
- name: Create Release
id: create_release
run: |
VERSION=${{ steps.read_version.outputs.version }}
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
response=$(curl -s -X POST -H "Authorization: token ${GITHUB_TOKEN}" -H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/releases \
-d "{\"tag_name\":\"$VERSION\",\"name\":\"Release $VERSION\",\"body\":\"Release version $VERSION\\n\n### Commits\\n${{ steps.get_commits.outputs.commits }}\\n\n### Top Contributors\\n${{ steps.get_contributors.outputs.contributors }}\\n\n### Source Code Size\\n${{ steps.calculate_size.outputs.size }}\"}")
echo "Release response: $response"
echo "::set-output name=release_response::$response"
release_id=$(echo "$response" | jq -r '.id')
- name: Upload release assets
run: |
VERSION=${{ steps.read_version.outputs.version }}
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
for asset in artifacts/*; do
curl -s -X POST -H "Authorization: token ${GITHUB_TOKEN}" -H "Content-Type: application/octet-stream" \
--data-binary @"$asset" \
"https://uploads.github.com/repos/${{ github.repository }}/releases/$release_id/assets?name=$(basename "$asset")"
done
- name: Summarize Work
run: |
echo "Release created successfully!"
echo "Version: ${{ steps.read_version.outputs.version }}"
echo "Response: ${{ steps.create_release.outputs.release_response }}"