-
Notifications
You must be signed in to change notification settings - Fork 2
156 lines (142 loc) · 5.02 KB
/
release-master.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
name: Make new release
on:
workflow_dispatch:
schedule:
# Cron is UTC time, so 23:59 CERN time
- cron: "59 22 * * *"
jobs:
# Check if new there were new commits after the newest release tag and save as "new_commits" variable
check_for_commits:
name: Check for new commits
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Get the newest hash and latest release hash
id: tag_and_commit_hash_chech
run: |
latest_commit_hash=${{ github.sha }}
branch_name=${GITHUB_REF##*/}
git fetch --tags
latest_tag=$(git tag -l $branch_name-* | tail -n 1)
latest_tag_hash=$(git rev-parse $latest_tag)
echo "Branch $branch_name"
echo "Newest commit $latest_commit_hash"
echo "Newest tag $latest_tag hash $latest_tag_hash"
if [ "$latest_commit_hash" = "$latest_tag_hash" ]; then
echo "Hashes are equal, no new commits"
echo "::set-output name=new_commits::false"
else
echo "Hashes differ, new commits"
echo "::set-output name=new_commits::true"
fi
outputs:
new_commits: ${{ steps.tag_and_commit_hash_chech.outputs.new_commits }}
# Create a github release
release:
name: Create GitHub release
runs-on: ubuntu-latest
needs: [check_for_commits]
if: ${{ needs.check_for_commits.outputs.new_commits == 'true' }}
steps:
- name: Create tag
id: create_tag
run: |
branch_name=${GITHUB_REF##*/}
release_timestamp=$(TZ=Europe/Paris date +%Y-%m-%d_%H-%M-%S)
tag=$branch_name-$release_timestamp
echo "New tag $tag"
echo "::set-output name=branch_name::$branch_name"
echo "::set-output name=release_timestamp::$release_timestamp"
echo "::set-output name=tag::$tag"
- name: Create release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.create_tag.outputs.tag }}
release_name: ${{ steps.create_tag.outputs.tag }}
draft: true
prerelease: false
- name: Create artifact files
run: |
mkdir info
echo "${{ steps.create_release.outputs.id }}" > info/release_id
echo "${{ steps.create_release.outputs.upload_url }}" > info/upload_url
echo "${{ steps.create_tag.outputs.tag }}.tar.gz" > info/archive_name
echo "${{ steps.create_tag.outputs.release_timestamp }}" > info/release_timestamp
echo "${{ steps.create_tag.outputs.branch_name }}" > info/branch_name
- uses: actions/upload-artifact@v1
with:
name: info
path: info
build:
name: Build release
needs: [check_for_commits, release]
if: ${{ needs.check_for_commits.outputs.new_commits == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v1
with:
name: info
- uses: actions/checkout@v2
with:
path: GridpackMachine
submodules: true
- name: Save timestamp in release
run: cp info/release_timestamp GridpackMachine
- name: Delete .git folder
run: |
cd GridpackMachine
rm -rf .git
rm -f .gitignore
- name: Create archive
id: create_archive
run: |
archive_name=$(cat info/archive_name)
tar -czf $archive_name GridpackMachine/
- name: Get upload info from artifact files
id: upload_info
run: |
upload_url=$(cat info/upload_url)
archive_name=$(cat info/archive_name)
echo "::set-output name=upload_url::$upload_url"
echo "::set-output name=archive_name::$archive_name"
- name: Upload archive
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.upload_info.outputs.upload_url }}
asset_path: ${{ steps.upload_info.outputs.archive_name }}
asset_name: ${{ steps.upload_info.outputs.archive_name }}
asset_content_type: application/gzip
metadata:
name: Publish release
needs: [check_for_commits, build]
if: ${{ needs.check_for_commits.outputs.new_commits == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v1
with:
name: info
- name: Set publish_info
id: publish_info
run: |
release_id=$(cat info/release_id)
branch_name=$(cat info/branch_name)
echo "::set-output name=release_id::$release_id"
echo "::set-output name=branch_name::$branch_name"
- uses: eregon/publish-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_id: ${{ steps.publish_info.outputs.release_id }}
- name: Delete old releases and tags
uses: dev-drprasad/[email protected]
with:
delete_tag_pattern: ${{ steps.publish_info.outputs.branch_name }}-
delete_tags: true
keep_latest: 3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}