move building/publishing to tags only

This commit is contained in:
Jamil Bou Kheir
2020-11-03 11:06:21 -06:00
parent c61f92a493
commit 660ca126df
3 changed files with 112 additions and 123 deletions

53
.github/workflows/build_and_publish.yml vendored Normal file
View File

@@ -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

View File

@@ -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

59
.github/workflows/test.yml vendored Normal file
View File

@@ -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!'