-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
378f30c
commit 65def71
Showing
7 changed files
with
216 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
[ | ||
import_deps: [:phoenix], | ||
inputs: ["*.{ex,exs}", "{config,lib,test}/**/*.{ex,exs}"] | ||
inputs: ["*.{ex,exs}", "{.github,config,lib,test}/**/*.{ex,exs}"] | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
defmodule GithubWorkflows do | ||
def get do | ||
%{ | ||
"main.yml" => main_workflow() | ||
} | ||
end | ||
|
||
defp main_workflow do | ||
[ | ||
[ | ||
name: "Test Elixir release", | ||
on: "push", | ||
jobs: [ | ||
test_release: [ | ||
name: "Build and test release", | ||
"runs-on": "ubuntu-latest", | ||
env: [ | ||
FLY_APP_NAME: "testing_release", | ||
FLY_PRIVATE_IP: "0:0:0:0:0:0:0:1", | ||
PHX_HOST: "localhost", | ||
SECRET_KEY_BASE: "8qdSYkvbFbYhUIKIPGsQOoOVdGUIzR+Sh56BJ0E+SU1xD4EsQMV5zCOSgRC5U8Rf" | ||
], | ||
steps: [ | ||
[ | ||
name: "Checkout", | ||
uses: "actions/checkout@v3" | ||
], | ||
[ | ||
name: "Set up Docker Buildx", | ||
uses: "docker/setup-buildx-action@v1" | ||
], | ||
[ | ||
name: "Cache Docker layers", | ||
uses: "actions/cache@v3", | ||
with: [ | ||
path: "/tmp/.buildx-cache", | ||
key: "${{ runner.os }}-buildx-${{ github.sha }}", | ||
"restore-keys": "${{ runner.os }}-buildx" | ||
] | ||
], | ||
[ | ||
name: "Build image", | ||
uses: "docker/build-push-action@v2", | ||
with: [ | ||
context: ".", | ||
builder: "${{ steps.buildx.outputs.name }}", | ||
tags: "testing_release:latest", | ||
load: true, | ||
"build-args": "target=testing_release", | ||
"cache-from": "type=local,src=/tmp/.buildx-cache", | ||
"cache-to": "type=local,dest=/tmp/.buildx-cache-new,mode=max" | ||
] | ||
], | ||
[ | ||
# Temp fix | ||
# https://github.com/docker/build-push-action/issues/252 | ||
# https://github.com/moby/buildkit/issues/1896 | ||
name: "Move cache", | ||
run: "rm -rf /tmp/.buildx-cache\nmv /tmp/.buildx-cache-new /tmp/.buildx-cache" | ||
], | ||
[ | ||
name: "Create the container", | ||
id: "create_container", | ||
run: | ||
"echo ::set-output name=container_id::$(docker create -p 4000:4000 -e FLY_APP_NAME=${{ env.FLY_APP_NAME }} -e FLY_PRIVATE_IP=${{ env.FLY_PRIVATE_IP }} -e PHX_HOST=${{ env.PHX_HOST }} -e SECRET_KEY_BASE=${{ env.SECRET_KEY_BASE }} testing_release | tail -1)" | ||
], | ||
[ | ||
name: "Start the container", | ||
run: "docker start ${{ steps.create_container.outputs.container_id }}" | ||
], | ||
[ | ||
name: "Check HTTP status code", | ||
uses: "nick-fields/retry@v2", | ||
with: [ | ||
command: | ||
"INPUT_SITES='[\"http://localhost:4000/api\"]' INPUT_EXPECTED='[200]' ./scripts/check_status_code.sh", | ||
max_attempts: 3, | ||
retry_wait_seconds: 5, | ||
timeout_seconds: 1 | ||
] | ||
], | ||
[ | ||
name: "Write Docker logs to a file", | ||
if: "failure() && steps.create_container.outcome == 'success'", | ||
run: | ||
"docker logs ${{ steps.create_container.outputs.container_id }} >> docker.log" | ||
], | ||
[ | ||
name: "Upload Docker log file", | ||
if: "failure()", | ||
uses: "actions/upload-artifact@v3", | ||
with: [ | ||
name: "docker.log", | ||
path: "docker.log" | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: Test Elixir release | ||
on: push | ||
jobs: | ||
test_release: | ||
name: Build and test release | ||
runs-on: ubuntu-latest | ||
env: | ||
FLY_APP_NAME: testing_release | ||
FLY_PRIVATE_IP: 0:0:0:0:0:0:0:1 | ||
PHX_HOST: localhost | ||
SECRET_KEY_BASE: "8qdSYkvbFbYhUIKIPGsQOoOVdGUIzR+Sh56BJ0E+SU1xD4EsQMV5zCOSgRC5U8Rf" | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
- name: Cache Docker layers | ||
uses: actions/cache@v3 | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: ${{ runner.os }}-buildx-${{ github.sha }} | ||
restore-keys: ${{ runner.os }}-buildx | ||
- name: Build image | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
builder: ${{ steps.buildx.outputs.name }} | ||
tags: testing_release:latest | ||
load: true | ||
build-args: target=testing_release | ||
cache-from: type=local,src=/tmp/.buildx-cache | ||
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max | ||
- name: Move cache | ||
run: "rm -rf /tmp/.buildx-cache\nmv /tmp/.buildx-cache-new /tmp/.buildx-cache" | ||
- name: Create the container | ||
id: create_container | ||
run: "echo ::set-output name=container_id::$(docker create -p 4000:4000 -e FLY_APP_NAME=${{ env.FLY_APP_NAME }} -e FLY_PRIVATE_IP=${{ env.FLY_PRIVATE_IP }} -e PHX_HOST=${{ env.PHX_HOST }} -e SECRET_KEY_BASE=${{ env.SECRET_KEY_BASE }} testing_release | tail -1)" | ||
- name: Start the container | ||
run: docker start ${{ steps.create_container.outputs.container_id }} | ||
- name: Check HTTP status code | ||
uses: nick-fields/retry@v2 | ||
with: | ||
command: "INPUT_SITES='[\"http://localhost:4000/api\"]' INPUT_EXPECTED='[200]' ./scripts/check_status_code.sh" | ||
max_attempts: 3 | ||
retry_wait_seconds: 5 | ||
timeout_seconds: 1 | ||
- name: Write Docker logs to a file | ||
if: failure() && steps.create_container.outcome == 'success' | ||
run: docker logs ${{ steps.create_container.outputs.container_id }} >> docker.log | ||
- name: Upload Docker log file | ||
if: failure() | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: docker.log | ||
path: docker.log |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/bash | ||
|
||
# export INPUT_SITES='["http://github.com", "https://education.github.com"]' | ||
# export INPUT_EXPECTED='[301, 200]' | ||
# https://github.com/lakuapik/gh-actions-http-status | ||
|
||
LRED="\033[1;31m" # Light Red | ||
LGREEN="\033[1;32m" # Light Green | ||
NC='\033[0m' # No Color | ||
|
||
text_success="(${LGREEN}Success${NC})" | ||
text_failed="(${LRED}Failed${NC}) " | ||
|
||
http_status() { | ||
site_url=$1 | ||
expected_status=$2 | ||
|
||
actual_status=$(curl -o /dev/null -s -w "%{http_code}" $site_url) | ||
|
||
if [ "${actual_status}" == "${expected_status}" ]; then | ||
result=${text_success} | ||
else | ||
result=${text_failed} | ||
final_result=${text_failed} | ||
final_result_code=127 | ||
|
||
fi | ||
|
||
echo -e "${result} HTTP Status for ${site_url} is ${actual_status}, expected ${expected_status}" | ||
} | ||
|
||
echo -e "\n\n==Starting gh-actions HTTP Status==\n" | ||
|
||
final_result="${LGREEN}Success${NC}" | ||
final_result_code=0 | ||
|
||
len=$(printenv INPUT_SITES | jq -r '. | length') | ||
|
||
for ((i=0; i<len; i++)) | ||
do | ||
site=$(printenv INPUT_SITES | jq -r '.['${i}']') | ||
expected=$(printenv INPUT_EXPECTED | jq -r '.['${i}']') | ||
http_status $site $expected | ||
done | ||
|
||
echo -e "\nHTTP Status result: ${final_result}" | ||
echo -e "\n==END==\n\n" | ||
|
||
exit ${final_result_code} |