Merge branch 'develop' into feature/blitz-2v2 #978
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/setup@v0.9.15 | |
with: | |
versionSpec: '5.x' | |
# Run Gitversion - https://gitversion.net/docs/ | |
- name: Run GitVersion | |
uses: gittools/actions/gitversion/execute@v0.9.15 | |
# 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: 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/ssh-action@v0.1.7 | |
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/ssh-action@v0.1.7 | |
# 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 }} | |