-
Notifications
You must be signed in to change notification settings - Fork 6
89 lines (76 loc) · 3.76 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
name: Sonoran CMS Core Release
on:
push:
branches:
- master
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: Extract Version
id: extract-version
run: |
VERSION=$(grep -oP "version '\K\d+\.\d+\.\d+" sonorancms/fxmanifest.lua)
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Grabbed version number of $VERSION, will be used for this release..."
shell: bash
- name: Create Release Directory
id: create-release-dir
run: |
mkdir release
echo "Created release directory"
shell: bash
- name: Zip Directories
id: zip-dirs
run: |
VERSION=${{ steps.extract-version.outputs.version }}
mkdir [sonorancms]
mv sonorancms [sonorancms]/sonorancms
mv sonorancms_updatehelper [sonorancms]/sonorancms_updatehelper
zip -r "sonorancms_core-$VERSION.zip" [sonorancms]/
mv "sonorancms_core-$VERSION.zip" release/
echo "Zipped sonorancms/ and sonorancms_updatehelper/ directories"
shell: bash
- name: Create or Recreate Release
id: create-update-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION=${{ steps.extract-version.outputs.version }}
RELEASE_NAME="v$VERSION"
RELEASE_TAG="$VERSION"
# Check if the release already exists
if curl --fail -sSL "https://api.github.com/repos/${{ github.repository }}/releases/tags/$RELEASE_TAG"; then
echo "Deleting existing release $RELEASE_NAME"
RELEASE_ID=$(curl -X GET "https://api.github.com/repos/${{ github.repository }}/releases/tags/$RELEASE_TAG" \
-H "Authorization: token $GITHUB_TOKEN" | jq -r '.id')
curl -X DELETE "https://api.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID" \
-H "Authorization: token $GITHUB_TOKEN"
else
echo "Release $RELEASE_NAME does not exist"
fi
# Check if the tag exists, and if it does, delete it
if curl --fail -sSL "https://api.github.com/repos/${{ github.repository }}/git/refs/tags/$RELEASE_TAG"; then
echo "Deleting existing tag $RELEASE_TAG"
REF_SHA=$(curl -sSL "https://api.github.com/repos/${{ github.repository }}/git/refs/tags/$RELEASE_TAG" | jq -r '.object.sha')
curl -X DELETE "https://api.github.com/repos/${{ github.repository }}/git/refs/tags/$RELEASE_TAG" \
-H "Authorization: token $GITHUB_TOKEN"
else
echo "Tag $RELEASE_TAG does not exist"
fi
echo "Creating a new release $RELEASE_NAME"
RESPONSE=$(curl -X POST "https://api.github.com/repos/${{ github.repository }}/releases" \
-H "Authorization: token $GITHUB_TOKEN" \
-d "{\"tag_name\":\"$RELEASE_TAG\",\"name\":\"$RELEASE_NAME\",\"target_commitish\":\"master\",\"draft\":false,\"prerelease\":false,\"generate_release_notes\":true,\"make_latest\":\"true\"}")
echo $RESPONSE
RELEASE_ID=$(echo $RESPONSE | jq -r '.id')
# Upload the zip file as a release asset
echo "Uploading zip to release $RELEASE_NAME"
UPLOAD_URL="https://uploads.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID/assets?name=sonorancms_core-$VERSION.zip"
curl -H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: application/zip" \
--data-binary "@release/sonorancms_core-$VERSION.zip" \
"$UPLOAD_URL"
shell: bash