Generic semver with -dev -beta -prod etc (#5) #36
Workflow file for this run
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: .NET Core Build and Release | |
on: | |
push: | |
workflow_dispatch: | |
jobs: | |
build_and_test: | |
runs-on: ubuntu-latest | |
permissions: | |
packages: read | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: "8.0.x" | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
#region jq | |
- name: Restore JQ cache | |
id: cache-jq | |
uses: actions/cache@v4 | |
with: | |
path: /usr/bin/jq | |
key: jq-${{ runner.os }}-${{ hashFiles('**/*.yml') }} | |
- name: Setup JQ | |
if: steps.cache-jq.outputs.cache-hit != 'true' | |
run: sudo apt-get install -y jq | |
#endregion | |
#region FFMpeg | |
- name: Restore FFmpeg cache | |
id: cache-ffmpeg | |
uses: actions/cache@v4 | |
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 | |
#endregion | |
- name: Compile LESS files | |
run: | | |
npm install -g less | |
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 NuGet cache | |
uses: actions/cache@v4 | |
with: | |
path: ~/.nuget/packages | |
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/*.fsproj', '**/*.vbproj') }} | |
restore-keys: | | |
${{ runner.os }}-nuget- | |
- 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 | |
ffmpeg -version | |
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@v4 | |
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@v4 | |
- uses: actions/download-artifact@v4 | |
with: | |
name: swpserver | |
#region jq | |
- name: Restore JQ cache | |
id: cache-jq | |
uses: actions/cache@v4 | |
with: | |
path: /usr/bin/jq | |
key: jq-${{ runner.os }}-${{ hashFiles('**/*.yml') }} | |
- name: Setup JQ | |
if: steps.cache-jq.outputs.cache-hit != 'true' | |
run: sudo apt-get install -y jq | |
#endregion | |
- name: Set next version | |
run: | | |
latest_release=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest) | |
current_version=$(echo "$latest_release" | jq -r .tag_name) | |
current_version=${current_version#v} # Remove the 'v' from the version if present | |
current_version=${current_version%-[a-zA-Z0-9]*} # Remove '-[a-zA-Z0-9]*' suffix if present | |
IFS='.' read -r major minor patch <<< "$current_version" | |
# Increment the patch version | |
next_version="$major.$minor.$((patch + 1))" | |
# Set the next version in the environment | |
echo "next_version=$next_version" | |
echo "next_version=$next_version" >> $GITHUB_ENV | |
- name: Create GitHub Release | |
run: | | |
mv swpserver.tar.gz swpserver-$next_version.tar.gz | |
COMMIT_MSG=$(git log -1 --pretty=%B) | |
gh release create "v$next_version-dev" swpserver-$next_version.tar.gz\ | |
--title "Release v$next_version-dev" \ | |
--notes "$COMMIT_MSG" | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
deploy: | |
runs-on: ubuntu-latest | |
needs: release | |
if: github.ref == 'refs/heads/main' | |
environment: demo | |
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" |