From a5e80690a36755295fcbe6d3c24e88eaa8d5664c Mon Sep 17 00:00:00 2001 From: AeonLucid Date: Mon, 21 Sep 2020 03:36:32 +0200 Subject: [PATCH] CI (#1) --- .github/workflows/deploy.yml | 68 ++++++++++++++++++++++ .github/workflows/docker.yml | 64 ++++++++++++++++++++ .github/workflows/main.yml | 39 +++++++++++++ src/Impostor.Server/Impostor.Server.csproj | 1 + 4 files changed, 172 insertions(+) create mode 100644 .github/workflows/deploy.yml create mode 100644 .github/workflows/docker.yml create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..5a7571d --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,68 @@ +name: Deploy + +on: + push: + tags: + - 'v*' + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + submodules: true + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 3.1.301 + - name: Install dependencies + run: dotnet restore ./src + - name: Build Impostor.Client + run: dotnet build --no-restore -c Release -f netcoreapp3.1 ./src/Impostor.Client/Impostor.Client.csproj + - name: Build Impostor.Server + run: dotnet build --no-restore -c Release -f netcoreapp3.1 ./src/Impostor.Server/Impostor.Server.csproj + - name: Test + run: dotnet test --no-restore -v normal -f netcoreapp3.1 ./src + - name: Publish Impostor.Server (win-x64) + run: dotnet publish -c release -o ./build/win-x64 -f netcoreapp3.1 -r win-x64 --self-contained --no-restore ./src/Impostor.Server/Impostor.Server.csproj + - name: Zip Impostor.Server (win-x64) + run: cd ./build/win-x64; zip -r ../win-x64.zip .; cd ./../../ + - name: Publish Impostor.Server (linux-x64) + run: dotnet publish -c release -o ./build/linux-x64 -f netcoreapp3.1 -r linux-x64 --self-contained --no-restore ./src/Impostor.Server/Impostor.Server.csproj + - name: Zip Impostor.Server (linux-x64) + run: cd ./build/linux-x64; zip -r ../linux-x64.zip .; cd ./../../ + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + body: | + Changes in this Release + - First Change + - Second Change + draft: true + prerelease: false + - name: Upload Release Asset (win-x64) + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./build/win-x64.zip + asset_name: Impostor-Server-win-x64.zip + asset_content_type: application/zip + - name: Upload Release Asset (linux-x64) + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./build/linux-x64.zip + asset_name: Impostor-Server-linux-x64.zip + asset_content_type: application/zip \ No newline at end of file diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..68208c3 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,64 @@ +name: Docker + +on: + schedule: + - cron: '0 10 * * *' + push: + branches: [ master, dev ] + tags: + - 'v*.*.*' + pull_request: + +jobs: + push_to_registry: + name: Push Docker image + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + submodules: true + - name: Prepare + id: prep + run: | + DOCKER_IMAGE=aeonlucid/impostor + VERSION=noop + if [ "${{ github.event_name }}" = "schedule" ]; then + VERSION=nightly + elif [[ $GITHUB_REF == refs/tags/* ]]; then + VERSION=${GITHUB_REF#refs/tags/} + elif [[ $GITHUB_REF == refs/heads/* ]]; then + VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g') + if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then + VERSION=edge + fi + elif [[ $GITHUB_REF == refs/pull/* ]]; then + VERSION=pr-${{ github.event.number }} + fi + TAGS="${DOCKER_IMAGE}:${VERSION}" + if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then + MINOR=${VERSION%.*} + MAJOR=${MINOR%.*} + TAGS="$TAGS,${DOCKER_IMAGE}:${MINOR},${DOCKER_IMAGE}:${MAJOR},${DOCKER_IMAGE}:latest" + fi + echo ::set-output name=version::${VERSION} + echo ::set-output name=tags::${TAGS} + echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ') + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Login to DockerHub + if: github.event_name != 'pull_request' + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.prep.outputs.tags }} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..ad319c2 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,39 @@ +name: Build + +on: + push: + branches: [ master, dev ] + pull_request: + branches: [ master, dev ] + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + submodules: true + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 3.1.301 + - name: Install dependencies + run: dotnet restore ./src + - name: Build Impostor.Client + run: dotnet build --no-restore -c Release -f netcoreapp3.1 ./src/Impostor.Client/Impostor.Client.csproj + - name: Build Impostor.Server + run: dotnet build --no-restore -c Release -f netcoreapp3.1 ./src/Impostor.Server/Impostor.Server.csproj + - name: Test + run: dotnet test --no-restore -v normal -f netcoreapp3.1 ./src + deploy: + name: Deploy + runs-on: ubuntu-latest + needs: build + if: github.event_name == 'release' + steps: + - name: Publish Impostor.Server (win-x64) + run: dotnet publish -c release -o /build/linux-x64 -f netcoreapp3.1 -r win-x64 --self-contained --no-restore ./src/Impostor.Server/Impostor.Server.csproj + - name: Publish Impostor.Server (linux-x64) + run: dotnet publish -c release -o /build/linux-x64 -f netcoreapp3.1 -r linux-x64 --self-contained --no-restore ./src/Impostor.Server/Impostor.Server.csproj \ No newline at end of file diff --git a/src/Impostor.Server/Impostor.Server.csproj b/src/Impostor.Server/Impostor.Server.csproj index 46ef7fa..d03494b 100644 --- a/src/Impostor.Server/Impostor.Server.csproj +++ b/src/Impostor.Server/Impostor.Server.csproj @@ -3,6 +3,7 @@ Exe netcoreapp3.1 + win-x64;linux-x64;linux-musl-x64 -- 2.39.5