-
Notifications
You must be signed in to change notification settings - Fork 0
128 lines (109 loc) · 4.99 KB
/
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
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
name: Create Release from Vault
on:
push:
branches: [ "main" ]
permissions:
contents: write
jobs:
create-release:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Install yq (YAML CLI parser)
run: |
sudo wget https://github.com/mikefarah/yq/releases/download/v4.35.2/yq_linux_amd64 -O /usr/local/bin/yq
sudo chmod +x /usr/local/bin/yq
- name: Extract version, name, and settings from front matter
id: extract_data
run: |
# Extract only the YAML front matter between the first two --- lines
FRONT_MATTER=$(awk 'NR==1 && /^---$/ {f=1; next} f && /^---$/ {f=0; exit} f' release-info.md)
# Parse the extracted YAML with yq
VERSION=$(echo "$FRONT_MATTER" | yq e '.version' -)
NAME=$(echo "$FRONT_MATTER" | yq e '.release_name' -)
ONLY_NEW=$(echo "$FRONT_MATTER" | yq e '.only_release_if_new' -)
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "release_name=$NAME" >> $GITHUB_OUTPUT
echo "only_release_if_new=$ONLY_NEW" >> $GITHUB_OUTPUT
- name: Extract release body from Markdown (below front matter)
id: extract_body
run: |
# Extract lines after the second '---'
# First remove everything up to and including the first '---'
# Then remove everything up to and including the next '---'
BODY=$(sed '1,/^---$/d' release-info.md | sed '1,/^---$/d')
echo "release_body<<EOF" >> $GITHUB_OUTPUT
echo "$BODY" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Zip the vault (excluding workflows and release-info)
run: |
zip -r obsidian-vault-${{ steps.extract_data.outputs.version }}.zip ./* \
-x ".github/*" \
-x "release-info.md"
- name: Check if release already exists
id: check_release
run: |
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ steps.extract_data.outputs.version }})
if [ "$HTTP_STATUS" = "200" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Decide whether to create release
id: decide
run: |
if [ "${{ steps.extract_data.outputs.only_release_if_new }}" = "true" ] && [ "${{ steps.check_release.outputs.exists }}" = "true" ]; then
echo "should_release=false" >> $GITHUB_OUTPUT
else
echo "should_release=true" >> $GITHUB_OUTPUT
fi
- name: Delete existing release and tag if found
if: steps.decide.outputs.should_release == 'true' && steps.check_release.outputs.exists == 'true'
run: |
RELEASE_ID=$(curl -s \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ steps.extract_data.outputs.version }} \
| jq -r .id)
# Delete the existing release
curl -s \
-X DELETE \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID
# Delete the existing tag reference
curl -s \
-X DELETE \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/git/refs/tags/${{ steps.extract_data.outputs.version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create GitHub Release
if: steps.decide.outputs.should_release == 'true'
id: create_release
uses: actions/create-release@v1
with:
tag_name: ${{ steps.extract_data.outputs.version }}
release_name: ${{ steps.extract_data.outputs.release_name }}
body: ${{ steps.extract_body.outputs.release_body }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload Release Asset
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Provide the token here
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: obsidian-vault-${{ steps.extract_data.outputs.version }}.zip
asset_name: obsidian-vault-${{ steps.extract_data.outputs.version }}.zip
asset_content_type: application/zip