From 660ca126dfe1e4d2a6863fd2d6da986ebc53f30c Mon Sep 17 00:00:00 2001 From: Jamil Bou Kheir Date: Tue, 3 Nov 2020 11:06:21 -0600 Subject: [PATCH] move building/publishing to tags only --- .github/workflows/build_and_publish.yml | 53 ++++++++++ .github/workflows/main.yml | 123 ------------------------ .github/workflows/test.yml | 59 ++++++++++++ 3 files changed, 112 insertions(+), 123 deletions(-) create mode 100644 .github/workflows/build_and_publish.yml delete mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/build_and_publish.yml b/.github/workflows/build_and_publish.yml new file mode 100644 index 000000000..a1494f38a --- /dev/null +++ b/.github/workflows/build_and_publish.yml @@ -0,0 +1,53 @@ +name: Build and Publish +on: + push: + tags: + - "*" +defaults: + run: + shell: bash + +jobs: + build_and_publish: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - name: Build packages + run: | + docker build -t fireguard:latest -f pkg/Dockerfile . + - name: Extract the Tag Name + id: tag_name + run: | + ref=${{ github.ref }} + tag_name=${ref#"refs/tags/"} + echo "::set-output name=tag_name::${tag_name}" + - name: Rename Built Artifacts + run: | + # This won't always be the case, but for now it is + version=${{ steps.tag_name.outputs.tag_name }} + + cid=$(docker create fireguard:latest) + filename=fireguard_${tag_name}-1_amd64.deb + echo "Extracting built debian package from container ${cid} to filename ${filename}" + + docker cp ${cid}:/build/pkg/debian.deb ./${filename} + - 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 }} + draft: false + prerelease: false + - name: Upload Release Asset + id: upload-release-asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./fireguard_${{ steps.tag_name.outputs.tag_name }}-1_amd64.deb + asset_name: fireguard_${{ steps.tag_name.outputs.tag_name }}-1_amd64.deb + asset_content_type: application/vnd.debian.binary-package diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 24597975d..000000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,123 +0,0 @@ -# Steps: -# 1. Unit/Integration Tests -# 2. Build and Push App Image -# 3. Functional Test -name: Test -on: - - push -defaults: - run: - shell: bash -jobs: - # 1. Unit/Integration Test - unit-integration-test: - runs-on: ubuntu-18.04 - env: - MIX_ENV: test - POSTGRES_HOST: localhost - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - services: - postgres: - image: postgres:12 - ports: - - 5432:5432 - env: - POSTGRES_USER: fireguard - POSTGRES_PASSWORD: postgres - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 - steps: - - uses: actions/checkout@v2 - - name: Install Runtimes - uses: actions/setup-elixir@v1 - with: - elixir-version: "1.11.1" - otp-version: "23.1.1" - - name: Install Dependencies - run: mix deps.get --only test - - name: Setup Database - run: | - mix ecto.create - mix ecto.migrate - - - name: Run Tests and Upload Coverage Report - run: mix coveralls.github --umbrella - - # 2. Functional Test - functional-test: - needs: unit-integration-test - runs-on: ubuntu-18.04 - steps: - - uses: actions/checkout@v2 - - name: Functional Test - run: | - echo 'Tests completed!' - build-deb: - needs: functional-test - runs-on: ubuntu-18.04 - steps: - - uses: actions/checkout@v2 - - name: Build packages - run: | - docker build -t fireguard:latest -f pkg/Dockerfile . - - name: Set the tag name - id: tag_name - run: | - ref=${{ github.ref }} - tag_name=${ref#"refs/tags/"} - echo "::set-output name=tag_name::${tag_name}" - - name: rename package - if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') - run: | - # This won't always be the case, but for now it is - version=${{ steps.tag_name.outputs.tag_name }} - - cid=$(docker create fireguard:latest) - filename=fireguard_${tag_name}-1_amd64.deb - echo "Extracting built debian package from container ${cid} to filename ${filename}" - - docker cp ${cid}:/build/pkg/debian.deb ./${filename} - - name: upload package - if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') - uses: actions/upload-artifact@v2 - with: - name: fireguard_deb - path: fireguard_${{ steps.tag_name.outputs.tag_name }}-1_amd64.deb - publish: - runs-on: ubuntu-18.04 - needs: build-deb - if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') - steps: - - name: Download Built Packages - uses: actions/download-artifact@v2 - with: - name: fireguard_deb - - 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 }} - draft: false - prerelease: false - - name: Set the tag name - id: tag_name - run: | - ref=${{ github.ref }} - tag_name=${ref#"refs/tags/"} - echo "::set-output name=tag_name::${tag_name}" - - name: Upload Release Asset - id: upload-release-asset - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./fireguard_${{ steps.tag_name.outputs.tag_name }}-1_amd64.deb - asset_name: fireguard_${{ steps.tag_name.outputs.tag_name }}-1_amd64.deb - asset_content_type: application/vnd.debian.binary-package diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 000000000..c63f2f925 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,59 @@ +# Steps: +# 1. Unit/Integration Tests +# 2. Build and Push App Image +# 3. Functional Test +name: Test +on: + - push +defaults: + run: + shell: bash + +jobs: + # 1. Unit/Integration Test + unit-integration-test: + runs-on: ubuntu-18.04 + env: + MIX_ENV: test + POSTGRES_HOST: localhost + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + services: + postgres: + image: postgres:13 + ports: + - 5432:5432 + env: + POSTGRES_USER: fireguard + POSTGRES_PASSWORD: postgres + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: + - uses: actions/checkout@v2 + - name: Install Runtimes + uses: actions/setup-elixir@v1 + with: + elixir-version: "1.11.1" + otp-version: "23.1.1" + - name: Install Dependencies + run: mix deps.get --only test + - name: Setup Database + run: | + mix ecto.create + mix ecto.migrate + + - name: Run Tests and Upload Coverage Report + run: mix coveralls.github --umbrella + + # 2. Functional Test + functional-test: + needs: unit-integration-test + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - name: Functional Test + run: | + # Dummy for now + echo 'Tests completed!'