-
Notifications
You must be signed in to change notification settings - Fork 6
145 lines (125 loc) · 5.61 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
name: Sonoran CMS Core Release
on:
push:
branches:
- master
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: Set Auth Token
run: |
if [ -z "${{ secrets.PAT_OVERRIDE }}" ]; then
echo "AUTH_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
else
echo "AUTH_TOKEN=${{ secrets.PAT_OVERRIDE }}" >> $GITHUB_ENV
fi
shell: bash
- 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
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 $AUTH_TOKEN" | jq -r '.id')
curl -X DELETE "https://api.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID" \
-H "Authorization: token $AUTH_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 $AUTH_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 $AUTH_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 $AUTH_TOKEN" \
-H "Content-Type: application/zip" \
--data-binary "@release/sonorancms_core-$VERSION.zip" \
"$UPLOAD_URL"
shell: bash
upload-artifact:
if: github.ref != 'refs/heads/master' # Run only on non-master branches
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: Set Auth Token
run: |
if [ -z "${{ secrets.PAT_OVERRIDE }}" ]; then
echo "AUTH_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
else
echo "AUTH_TOKEN=${{ secrets.PAT_OVERRIDE }}" >> $GITHUB_ENV
fi
shell: bash
- 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: Upload ZIP as Artifact
uses: actions/upload-artifact@v4
with:
name: sonorancms_core-artifact
path: sonorancms_core-*.zip