forked from stevoscriptsteam/stevo_citizenship
-
Notifications
You must be signed in to change notification settings - Fork 0
179 lines (160 loc) · 7.34 KB
/
generate-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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
name: Build and Release
on:
push:
tags:
- "v*.*.*"
permissions:
contents: write
actions: write
jobs:
build_and_release:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_project_information.outputs.version }}
release_body: ${{ steps.prepare_release_body.outputs.body }}
steps:
- name: Checkout code
uses: actions/checkout@v4
# - name: Set up Node.js
# uses: actions/setup-node@v4
# with:
# node-version: "16"
# - name: Install dependencies
# working-directory: ./src
# run: |
# sudo apt install -y jq
# npm install
# - name: Build project
# working-directory: ./src
# run: |
# npm run build
# if [ $? -ne 0 ]; then
# echo "Erro na compilação"
# exit 1
# fi
- name: Get commit messages, version, and repository description
id: get_project_information
run: |
LAST_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
CURRENT_TAG="${GITHUB_REF#refs/tags/}"
if [ -n "$LAST_TAG" ]; then
COMMITS=$(git log $LAST_TAG..$GITHUB_SHA --oneline --pretty=format:"%h %s")
else
echo "Nenhuma tag anterior encontrada. Coletando todos os commits até a tag atual."
COMMITS=$(git log --oneline --pretty=format:"%h %s")
fi
if [ -z "$COMMITS" ]; then
echo "Nenhuma mudança significativa desde a última release." > ./release_body.txt
else
echo "$COMMITS" > ./release_body.txt
fi
echo "version=$CURRENT_TAG" >> $GITHUB_OUTPUT
- name: Prepare release body
id: prepare_release_body
run: |
if [ -f release_body.txt ]; then
RELEASE_NOTES=$(head -n 1900 release_body.txt)
echo "body=$RELEASE_NOTES" >> $GITHUB_OUTPUT
else
echo "Arquivo release_body.txt não encontrado!"
echo "body=Nenhuma nota de release disponível." >> $GITHUB_OUTPUT
fi
- name: Update manifest data
run: |
if [ -f fxmanifest.lua ]; then
REPO_DESCRIPTION=$(curl -s https://api.github.com/repos/${{ github.repository }} | jq -r .description)
sed -i "s/MRIQBOX_VERSION/${{ steps.get_project_information.outputs.version }}/g" fxmanifest.lua
else
echo "Arquivo fxmanifest.lua não encontrado!"
exit 1
fi
- name: Create ZIP file
run: |
mkdir -p "${{ github.event.repository.name }}"
rsync -av \
--exclude='src/' \
--exclude='.github/' \
--exclude='.git/' \
--exclude='*.txt' \
--exclude='*.lock' \
--exclude='.gitignore' \
--exclude='.editorconfig' \
--exclude='*.sh' \
--exclude='*.bat' \
--exclude='${{ github.event.repository.name }}' \
./ "${{ github.event.repository.name }}/"
zip -r --symlinks "${{ github.event.repository.name }}.zip" "${{ github.event.repository.name }}"
- name: Generate Release
uses: comnoco/create-release-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
id: release
with:
tag_name: "${{ steps.get_project_information.outputs.version }}"
release_name: "${{ steps.get_project_information.outputs.version }}"
body_path: release_body.txt
draft: false
prerelease: false
- name: Upload artifacts
uses: shogo82148/[email protected]
with:
upload_url: ${{ steps.release.outputs.upload_url }}
asset_path: ${{ github.event.repository.name }}.zip
post_to_discord:
needs: build_and_release
runs-on: ubuntu-latest
steps:
- name: Post to Discord (with embed)
env:
DISCORD_WEBHOOK_URL: ${{ secrets.UPDATE_DISCORD_WEBHOOK }}
RELEASE_URL: https://github.com/${{ github.repository }}/releases/tag/${{ github.ref_name }}
RELEASE_TAG: ${{ github.ref_name }}
RELEASE_AUTHOR: ${{ github.actor }}
RELEASE_BODY: ${{ needs.build_and_release.outputs.release_body }}
run: |
REPO_DESCRIPTION=$(curl -s https://api.github.com/repos/${{ github.repository }} | jq -r .description)
EMBED_DATA='{
"embeds": [{
"author": {
"name": "MRI QBOX - Updates",
"icon_url": "${{ secrets.LOGO_MRIQBOX_URL }}"
},
"title": "[${{ github.event.repository.name }}] Nova versão disponível: '"${RELEASE_TAG}"'",
"url": "'"${RELEASE_URL}"'",
"description": "'"${REPO_DESCRIPTION}"'",
"fields": [{
"name": "O que há de novo?",
"value": "'"${RELEASE_BODY}"'"
},
{
"name": "Veja todas as mudanças",
"value": "[Veja todas as mudanças aqui](https://github.com/${{ github.repository }}/commits/${{ github.ref_name }})"
},
{
"name": "Precisa de ajuda?",
"value": "[Participe da comunidade](${{ secrets.INVITE_DISCORD_URL}})",
"inline": true
},
{
"name": "Documentação",
"value": "[Acesse aqui](${{ secrets.DOCS_MRIQBOX_URL }})",
"inline": true
}],
"image": {
"url": "${{ secrets.RESOURCE_MRIQBOX_URL }}"
},
"color": 4243543,
"footer": {
"text": "Realizado por: '"${RELEASE_AUTHOR}"'",
"icon_url": "${{ secrets.LOGO_MRIQBOX_URL }}"
},
"timestamp": "'"$(date --utc +%Y-%m-%dT%H:%M:%SZ)"'"
}]
}'
if [ -z "$DISCORD_WEBHOOK_URL" ] || [ -z "$RELEASE_URL" ] || [ -z "$RELEASE_TAG" ]; then
echo "Algumas variáveis obrigatórias estão ausentes. Não será possível enviar o webhook."
exit 1
fi
curl -H "Content-Type: application/json" \
-d "$EMBED_DATA" \
$DISCORD_WEBHOOK_URL