-
-
Notifications
You must be signed in to change notification settings - Fork 31
181 lines (156 loc) · 7.29 KB
/
deployment.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
180
181
name: build-and-deploy
on:
# Run on push to any branches listed
# Any new features that should be auto built and deployed should be in a branch under "feature/"
# example: feature/net7 or feature/quakenet
push:
branches:
- develop
- feature/*
- hotfix/*
# Run when there is a release published
release:
types: [ published ]
# Allows for this workflow to be run manually
workflow_dispatch:
jobs:
# This job is responsible for building the package that will be deployed to the server.
# It is run in a windows container so that Version.exe and other Windows based tools are able to be executed.
build-package:
runs-on: windows-latest
environment: cncnet
outputs:
# This the fully qualified version string that is used for deploy purposes.
packageUploadVersion: ${{ env.GitVersion_MajorMinorPatch }}${{ env.GitVersion_PreReleaseLabelWithDash }}
mirrorLinkName: ${{ env.GitVersion_PreReleaseLabel }}
steps:
# Checkout the repo
- name: Checkout repo
uses: actions/checkout@v3
with:
fetch-depth: 0 # required for gitversion
- name: Install Tools NPM Libs
working-directory: tools
run: npm ci
# This step validates the format of the tag created, if this was a published release.
# Currently, it must be in the format "yr-X.Y" or "yr-X.Y.Z"
- name: Validate Tag Name
if: github.event_name == 'release'
working-directory: tools
run: |
npm run release-tag-validator
- name: Install GitVersion
uses: gittools/actions/gitversion/[email protected]
with:
versionSpec: '5.x'
# Run Gitversion - https://gitversion.net/docs/
- name: Run GitVersion
uses: gittools/actions/gitversion/[email protected]
# Update versionconfig.ini with gitversion version info
- name: Update versionconfig.ini
# replace the second line in the file with the proper version number (X.Y.Z-dev.N)
run: sed -i "2 s/.*/${{env.GitVersion_SemVer}}/" ./package/versionconfig.ini
- name: Pack Game Assets
working-directory: tools
run: npm run mix-packer
- name: Version Writer
working-directory: tools
run: npm run version-writer
# Create package archive
- name: Create package artifact (tar)
run: tar -C ./package -czvf package.tar.gz .
- name: Create package artifact (zip)
run: 7z.exe a package.zip ./package
# Create installer
- name: Build Installer
working-directory: tools
run: npm run build-installer
# Upload package archive as a workflow artifact
- name: Upload Package Workflow Artifact
uses: actions/upload-artifact@v3
with:
name: package
path: ./package.tar.gz
if-no-files-found: error
# Upload installer as a workflow artifact
- name: Upload Installer Workflow Artifact
uses: actions/upload-artifact@v3
with:
name: installer
path: ./CnCNet5_YR_Installer.exe
if-no-files-found: error
# Upload package archive (tar) to any relevant releases for current tag
# If there is no release/tag, this will not do anything
- name: Upload Package Release Asset (tar)
if: github.event_name == 'release'
working-directory: tools
run: npm run release-asset-uploader -- --token ${{ secrets.GITHUB_TOKEN }} --assetName "package_${{env.GitVersion_SemVer}} (tar)" --assetPath ../package.tar.gz
# Upload package archive (zip) to any relevant releases for current tag
# If there is no release/tag, this will not do anything
- name: Upload Package Release Asset (zip)
if: github.event_name == 'release'
working-directory: tools
run: npm run release-asset-uploader -- --token ${{ secrets.GITHUB_TOKEN }} --assetName "package_${{env.GitVersion_SemVer}} (zip)" --assetPath ../package.zip
# Upload installer to any relevant releases for current tag
# If there is no release/tag, this will not do anything
- name: Upload Installer Release Asset
if: github.event_name == 'release'
working-directory: tools
run: npm run release-asset-uploader -- --token ${{ secrets.GITHUB_TOKEN }} --assetName "CnCNet5_YR_Installer_${{env.GitVersion_SemVer}} (exe)" --assetPath ../CnCNet5_YR_Installer.exe
# This job downloads the package artifact from the previous job and deploys it to the server.
deploy-package:
# if previous job was successful
if: ${{ success() }}
runs-on: ubuntu-latest
environment: cncnet
needs: build-package
steps:
# Download the package artifact from previous job
- name: Get artifact
uses: actions/download-artifact@v3
with:
name: package
# Deploy the package to the server
- name: Deploy package
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
passphrase: ${{ secrets.SSH_PASS }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
overwrite: true
source: "package.tar.gz"
target: "${{ secrets.SSH_PATH_UPDATES }}/${{ needs.build-package.outputs.packageUploadVersion }}/"
# Extract the deployed package on the server
- name: Extract the deployed package
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
passphrase: ${{ secrets.SSH_PASS }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
cd ${{ secrets.SSH_PATH_UPDATES }}/${{ needs.build-package.outputs.packageUploadVersion }}
tar -xzvf ${{ secrets.SSH_PATH_UPDATES }}/${{ needs.build-package.outputs.packageUploadVersion }}/package.tar.gz
rm ${{ secrets.SSH_PATH_UPDATES }}/${{ needs.build-package.outputs.packageUploadVersion }}/package.tar.gz
chmod 777 --recursive ${{ secrets.SSH_PATH_UPDATES }}/${{ needs.build-package.outputs.packageUploadVersion }}/*
# Create/update a mirror link for client update purposes, using the GitVersion pre release label as the link name.
# See the file "GitVersion.yml" for more details on the name that will be used for a given branch.
# Ex: if the branch name is "develop", it will create a link of "dev" to point to the directory "updates/X.Y.Z-dev".
# Then, client users can use the path "/updates/games/yr/develop/" for their UpdaterConfig.ini file.
# This will keep develop and feature branch update mirror links up to date as soon as the deploy has occurred.
- name: Update mirror link
uses: appleboy/[email protected]
# RUN ON NON-RELEASES ONLY. RELEASE VERSION LINKS SHOULD CONTINUE TO BE UPDATED MANUALLY, FOR NOW.
if: github.event_name != 'release'
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
passphrase: ${{ secrets.SSH_PASS }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
cd ${{ secrets.SSH_PATH_GAMES_YR }}
ln -sfn updates/${{ needs.build-package.outputs.packageUploadVersion }} ${{ needs.build-package.outputs.mirrorLinkName }}