-
Notifications
You must be signed in to change notification settings - Fork 0
143 lines (119 loc) · 4.39 KB
/
build-and-publish.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
name: .NET Core Build and Release
on:
push:
workflow_dispatch:
jobs:
build_and_test:
runs-on: ubuntu-latest
permissions:
packages: read
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: "8.0.x"
- name: Setup JQ
run: sudo apt-get install -y jq
- name: Cache FFmpeg
id: cache-ffmpeg
uses: actions/cache@v2
with:
path: ffmpeg/
key: ffmpeg-${{ runner.os }}
- name: Download FFmpeg
if: steps.cache-ffmpeg.outputs.cache-hit != 'true'
run: |
mkdir -p ffmpeg
wget -O ffmpeg.tar.xz https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz
tar xvf ffmpeg.tar.xz -C ffmpeg --strip-components=1
- name: Add FFmpeg into path
run: |
echo "$(pwd)/ffmpeg" >> $GITHUB_PATH
- name: Check FFmpeg Version
run: ffmpeg -version
- name: Restore dependencies and cache
uses: actions/cache@v2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/*.fsproj', '**/*.vbproj') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: "18"
- name: Install LESS
run: npm install -g less
- name: Compile LESS files
run: |
lessc SwipetorApp/wwwroot/public/styles/public.less SwipetorApp/wwwroot/public/styles/public.css
lessc SwipetorApp/wwwroot/admin/styles/_main.less SwipetorApp/wwwroot/admin/styles/_main.css
rm -f SwipetorApp/wwwroot/public/styles/*.less
rm -f SwipetorApp/wwwroot/admin/styles/*.less
- name: Restore, Build and Test
run: |
dotnet nuget add source --username atas --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/atas/index.json"
dotnet restore
dotnet build --no-restore
dotnet test --no-build --verbosity normal --filter FullyQualifiedName~Tests
- name: Publish Application
run: dotnet publish --configuration Release --output ./publish
- name: Archive Published App
run: tar -czf swpserver.tar.gz -C ./publish .
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: swpserver
path: swpserver.tar.gz
release:
runs-on: ubuntu-latest
permissions:
contents: write
needs: build_and_test
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: swpserver
- name: Set next version
run: |
next_version=$(git for-each-ref --sort=-creatordate --format '%(refname:short)' refs/tags/v* | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1 | awk -F '.' '{print $1 "." $2 "." $3+1}')
next_version=${next_version#v}
echo "next_version=$next_version"
echo "next_version=$next_version" >> $GITHUB_ENV
- name: Commit msg
id: commit_msg
run: |
COMMIT_MSG=$(git log -1 --pretty=%B)
echo "commit_msg=$commit_msg" >> $GITHUB_ENV
- name: Create GitHub Release
run: |
mv swpserver.tar.gz swpserver-$next_version.tar.gz
gh release create "v$next_version" swpserver-$next_version.tar.gz\
--title "Release v$next_version" \
--notes "$commit_msg"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
deploy:
runs-on: ubuntu-latest
needs: release
if: github.ref == 'refs/heads/main'
environment: main
steps:
- name: Set up SSH
run: |
mkdir -p ~/.ssh/
ls -lha ~/.ssh
echo "${{ secrets.SSH_KEY }}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
- name: Trigger pull-deploy
run: |
ssh -p${{ secrets.SSH_PORT }} ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "/opt/swipetor/bin/pull-deploy/run.sh"