piston/.github/workflows/package-pr.yaml

77 lines
2.8 KiB
YAML
Raw Normal View History

2021-02-28 03:58:02 +01:00
name: 'Package Pull Requests'
on:
2021-02-28 04:07:16 +01:00
pull_request:
2021-02-28 03:58:02 +01:00
types:
- opened
- edited
- reopened
- synchronize
paths:
- 'packages/**'
jobs:
2021-02-28 07:30:35 +01:00
check-build:
name: Check that package builds
2021-02-28 03:58:02 +01:00
runs-on: ubuntu-latest
steps:
- name: Get PR Commits
id: 'get-pr-commits'
uses: tim-actions/get-pr-commits@master
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Check subsystem
uses: tim-actions/commit-message-checker-with-regex@v0.3.1
with:
commits: ${{ steps.get-pr-commits.outputs.commits }}
2021-02-28 04:07:16 +01:00
pattern: '^[\s]*(pkg\([^:\s\n]+\))[\s]*:'
2021-02-28 03:58:02 +01:00
error: 'Your commit message must start with pkg([package])'
- name: Get packages
id: 'get-packages'
shell: bash
run: |
COMMITS='${{ steps.get-pr-commits.outputs.commits }}'
2021-02-28 07:30:35 +01:00
PACKAGES=$(echo $COMMITS | jq .[].commit.message -r | grep -oP '^pkg\(\K[^:\h\n]+(?=\))' | sort -u)
2021-02-28 03:58:02 +01:00
echo "::set-output name=packages::$PACKAGES"
2021-02-28 07:30:35 +01:00
- name: Checkout
uses: actions/checkout@v2
- name: Build docker containers
run: |
docker build -t piston_fs_repo repo
docker build -t piston_api api
- name: Build Packages
run: |
docker run -v $(pwd)'/repo:/repo' -v $(pwd)'/packages:/packages' piston_fs_repo ${{ steps.get-packages.outputs.packages }}
2021-02-28 07:30:35 +01:00
- name: Run tests
run: |
2021-02-28 10:25:23 +01:00
docker run -p 6969:6969 -v $(pwd)'/repo:/repo' --privileged --name api piston_api &
2021-02-28 07:30:35 +01:00
echo Waiting for API to start..
2021-02-28 10:25:23 +01:00
while [[ "$(curl -s -w '%{http_code}' http://127.0.0.1:6969/runtimes)" != "200" ]]; do sleep 5; done
2021-02-28 07:30:35 +01:00
echo Adding local repo
curl -s http://127.0.0.1:6969/repos -XPOST -d "slug=local&url=file:///repo/index.yaml"
echo Testing packages
for pkg in "$(curl -s http://127.0.0.1:6969/repos/local/packages/ | jq '.data.packages[] | "\(.language)/\(.language_version)"' -r)"
do
PKG_SLUG=${pkg/\//-}
PKG_NAME=$(echo $pkg | cut -d'/' -f 1)
PKG_VERSION=$(echo $pkg | cut -d'/' -f 2)
echo Installing ${PKG_SLUG}
curl -sXPOST http://127.0.0.1:6969/repos/local/packages/${pkg} | jq '.language' -r || exit 1
echo Testing ${PKG_SLUG} (using ${PKG_SLUG}.tf)
TEST_FILE=$(cat ${PKG_SLUG}.tf)
TEST_JSON=`jq -C '.language = "${PKG_NAME}" | .version = "${PKG_VERSION}" | .files=[] | .files[0]={} | .files[0].name="test" | .files[0].name.content="${TEST_FILE}" | .main = "test" | .args = [] | .stdin = "" | .compile_timeout = 10000 | .run_timeout = 3000' <<< '{}'`
curl -sXPOST http://127.0.0.1:6969/jobs -H 'Content-Type: application/json' -d "$TEST_JSON" > ${PKG_SLUG}.tr
jq '.run.stdout' ${PKG_SLUG}.tr | grep "OK" || exit 1
2021-02-28 07:30:35 +01:00
done