From e719228c837faf3ababce97af1e48a67af2ac58d Mon Sep 17 00:00:00 2001 From: Diego Calero Date: Sat, 21 Dec 2019 00:23:18 -0300 Subject: [PATCH] [#14] Use github actions for AWS deployment (#29) Created new workflow "CI - Build release asset" at build.yml. --- .github/workflows/build.yml | 94 ++++++++++++++++++++++ .github/workflows/{elixir.yml => test.yml} | 12 +-- 2 files changed, 100 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/build.yml rename .github/workflows/{elixir.yml => test.yml} (73%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..eb27366 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,94 @@ +name: CI - Build release asset + +on: + release: + types: [published] + +jobs: + build: + name: Build OTP ${{ matrix.otp }} | Elixir ${{ matrix.elixir }} | Node ${{ matrix.node }} | OS ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-18.04] + otp: [22.0.7] + elixir: [1.9.1] + node: [12.8.0] + + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-elixir@v1.1.0 + with: + otp-version: ${{ matrix.otp }} + elixir-version: ${{ matrix.elixir }} + - uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node }} + + - name: Install dependencies + run: | + mix local.rebar --force + mix local.hex --force + mix archive.install --force https://raw.githubusercontent.com/phoenixframework/archives/master/phx_new.ez + mix deps.get + npm install + + - name: Check code format + run: mix format --check-formatted + - name: Run tests + run: mix test + + - name: Build release + run: | + export SECRET_KEY_BASE=$(MIX_ENV=test mix phx.gen.secret) + mix compile + npm run deploy + mix phx.digest + mix release + env: + MIX_ENV: prod + + - name: Build package + id: build_package + run: | + timestamp="`date '+%Y%m%d-%H%M%S'`" + version="$timestamp-`echo $REVISION | cut -c1-8 `" + apppath="$RELEASE_PATH/$APPLICATION" + archive="$APPLICATION-$version.tar.gz" + cp cooperatives.yml $apppath/ + echo $REVISION > $apppath/REVISION + echo $version > $apppath/VERSION + tar -zcf $archive -C $RELEASE_PATH $APPLICATION + echo "::set-output name=timestamp::$timestamp" + echo "::set-output name=version::$version" + echo "::set-output name=archive::$archive" + echo "Release package built at $archive" + env: + REVISION: ${{ github.sha }} + RELEASE_PATH: _build/prod/rel + APPLICATION: coophub + + - name: Upload package artifact + uses: actions/upload-artifact@v1 + with: + name: coophub-release + path: ${{ steps.build_package.outputs.archive }} + + - name: Upload release asset + id: upload_release + uses: actions/upload-release-asset@v1.0.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ${{ steps.build_package.outputs.archive }} + asset_name: ${{ steps.build_package.outputs.archive }} + asset_content_type: application/tar+gzip + + - name: Dispatch release + uses: peter-evans/repository-dispatch@v1 + with: + token: ${{ secrets.REPO_DISPATCH_TOKEN }} + repository: ${{ secrets.REPO_DISPATCH_PATH }} + event-type: coophub-release + client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}' \ No newline at end of file diff --git a/.github/workflows/elixir.yml b/.github/workflows/test.yml similarity index 73% rename from .github/workflows/elixir.yml rename to .github/workflows/test.yml index c8c08d5..5c7fde7 100644 --- a/.github/workflows/elixir.yml +++ b/.github/workflows/test.yml @@ -1,10 +1,10 @@ -name: Elixir CI +name: CI - Test -on: [pull_request, push] +on: push jobs: - build: - + test: + name: Run elixir tests runs-on: ubuntu-latest container: @@ -12,12 +12,12 @@ jobs: steps: - uses: actions/checkout@v1 - - name: Install Dependencies + - name: Install dependencies run: | mix local.rebar --force mix local.hex --force mix deps.get - name: Check code format run: mix format --check-formatted - - name: Run Tests + - name: Run tests run: mix test