-
-
Notifications
You must be signed in to change notification settings - Fork 23
160 lines (153 loc) · 5.5 KB
/
Copy pathrelease.yml
File metadata and controls
160 lines (153 loc) · 5.5 KB
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
name: Release
on:
push:
branches: [main]
workflow_dispatch:
jobs:
version_check:
runs-on: ubuntu-latest
outputs:
should_update: ${{ steps.outputs.outputs.should_update }}
version: ${{ steps.outputs.outputs.version }}
previous_version: ${{ steps.get_latest_tag.outputs.tag }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Get version
id: get_version
run: |
echo "version=$(grep -oP '(?<=version: ")[^"]*' config.yml)" >> $GITHUB_OUTPUT
- name: Get latest version tag
id: get_latest_tag
uses: WyriHaximus/github-action-get-previous-tag@v2
with:
pattern: v*
fallback: 0.0.0
- name: Compare versions
id: compare_versions
run: |
echo "should_update=$(python3 -c "from packaging import version; print(version.parse('${{ steps.get_version.outputs.version }}') > version.parse('${{ steps.get_latest_tag.outputs.tag }}'))")" >> $GITHUB_OUTPUT
- name: Set outputs
id: outputs
if: steps.compare_versions.outputs.should_update == 'True'
run: |
echo "should_update=True" >> $GITHUB_OUTPUT
echo "version=${{ steps.get_version.outputs.version }}" >> $GITHUB_OUTPUT
create_release:
needs: version_check
if: needs.version_check.outputs.should_update == 'True'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
ref: main
- name: Get Changelog
id: get_changelog
run: |
{
echo 'changelog<<CHANGELOG_EOF'
git log -1 --pretty=format:"%b"
echo ""
echo 'CHANGELOG_EOF'
} >> "$GITHUB_OUTPUT"
- name: Create release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.version_check.outputs.version }}
body: |
${{ steps.get_changelog.outputs.changelog }}
Full Changelog: ${{ github.server_url }}/${{ github.repository }}/compare/${{ needs.version_check.outputs.previous_version }}...v${{ needs.version_check.outputs.version }}
- name: Send changelog to Discord
uses: tsickert/discord-webhook@v5.3.0
with:
webhook-url: ${{ secrets.WEBHOOK_URL }}
content: |
# Version ${{ needs.version_check.outputs.version }}
<@&${{ secrets.WEBHOOK_ROLE }}>
${{ steps.get_changelog.outputs.changelog }}
publish_images:
needs: [version_check, create_release]
if: needs.version_check.outputs.should_update == 'True'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
ref: main
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPO_NAME }}
ghcr.io/${{ github.repository }}
tags: |
type=raw,value=latest
type=semver,pattern={{version}},value=${{ needs.version_check.outputs.version }}
type=semver,pattern={{major}}.{{minor}},value=${{ needs.version_check.outputs.version }}
type=semver,pattern={{major}},value=${{ needs.version_check.outputs.version }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64,linux/arm/v7
cache-from: type=gha
cache-to: type=gha,mode=max
deployment:
needs: [version_check, create_release]
if: needs.version_check.outputs.should_update == 'True'
runs-on: self-hosted
steps:
- name: Set up context
run: |
echo "VIRTUAL_ENV=${{ secrets.VENV_DIRECTORY }}" >> $GITHUB_ENV
echo "${{ secrets.VENV_DIRECTORY }}/bin" >> $GITHUB_PATH
- name: Stop
run: |
pm2 stop ${{ secrets.PM2_PROCESS_NAME }}
- name: Reset local environment
run: |
rm -f log.txt
git reset --hard
git clean -fd
working-directory: ${{ secrets.DIRECTORY }}
- name: Checkout
run: |
git fetch --all --tags
git checkout refs/tags/v${{ needs.version_check.outputs.version }}
working-directory: ${{ secrets.DIRECTORY }}
- name: Install dependencies
run: |
pip install --force-reinstall -r requirements.txt
working-directory: ${{ secrets.DIRECTORY }}
- name: Migrate database
run: |
masonite-orm migrate -C database/config.py -d database/migrations
working-directory: ${{ secrets.DIRECTORY }}
- name: Start
run: |
pm2 start ${{ secrets.PM2_PROCESS_NAME }}