From d951b230a720423efff8f3740d828745032dc065 Mon Sep 17 00:00:00 2001 From: Nate Coraor Date: Thu, 6 Oct 2022 15:29:56 +0200 Subject: [PATCH] Check and deploy workflows --- .ci/tapview | 195 ++++++++++++++++++++++++++++++++++ .github/workflows/check.yaml | 40 +++++++ .github/workflows/deploy.yaml | 26 +++++ group_vars/all.yaml | 1 + lambda.yaml | 7 +- 5 files changed, 268 insertions(+), 1 deletion(-) create mode 100755 .ci/tapview create mode 100644 .github/workflows/check.yaml create mode 100644 .github/workflows/deploy.yaml diff --git a/.ci/tapview b/.ci/tapview new file mode 100755 index 0000000..eb5c68c --- /dev/null +++ b/.ci/tapview @@ -0,0 +1,195 @@ +#! /bin/sh +# tapview - a TAP (Test Anything Protocol) viewer in pure POSIX shell +# +# Copyright by Eric S. Raymond +# +# This code is intended to be embedded in your project. The author +# grants permission for it to be distributed under the prevailing +# license of your project if you choose, provided that license is +# OSD-compliant; otherwise the following SPDX tag incorporates a +# license by reference. +# +# SPDX-License-Identifier: BSD-2-Clause +# +# This is version 1.3 +# A newer version may be available at https://gitlab.com/esr/tapview +# +# POSIX allows but does not mandate that -n suppresses emission of a +# trailing newline in echo. Thus, some shell builtin echos don't do +# that. Cope gracefully. +# shellcheck disable=SC2039 +if [ "$(echo -n "a"; echo "b")" = "ab" ] +then + ECHO="echo" +elif [ "$(/bin/echo -n "a"; /bin/echo "b")" = "ab" ] +then + ECHO="/bin/echo" +else + echo "tapview: bailing out, your echo lacks -n support." + exit 3 +fi + +OK="." +FAIL="F" +SKIP="s" +TODO_NOT_OK="x" +TODO_OK="u" + +ship_char() { + # shellcheck disable=SC2039 + "${ECHO}" -n "$1" +} + +ship_line() { + report="${report}${1}\n" +} + +testcount=0 +failcount=0 +skipcount=0 +todocount=0 +test_before_plan=no +test_after_plan=no +expect="" +status=0 + +report="" +IFS="" +state=start +while read -r line +do + if expr "$line" : "Bail out!" >/dev/null + then + ship_line "$line" + status=2 + break + fi + # Process a plan line + if expr "$line" : '1\.\.[0-9][0-9]*' >/dev/null + then + if [ "$expect" != "" ] + then + if [ "${testcount}" -gt 0 ] + then + echo "" + fi + ship_line "tapview: cannot have more than one plan line." + echo "${report}" + exit 1 + fi + if expr "$line" : ".* *SKIP" >/dev/null || expr "$line" : ".* *skip" >/dev/null + then + ship_line "$line" + echo "${report}" + exit 1 # Not specified in the standard whether this should exit 1 or 0 + fi + expect=$(expr "$line" : '1\.\.\([0-9][0-9]*\)') + continue + fi + # Process an ok line + if expr "$line" : "ok" >/dev/null + then + testcount=$((testcount + 1)) + if [ "$expect" = "" ] + then + test_before_plan=yes + else + test_after_plan=yes + fi + if expr "$line" : ".*# *TODO" >/dev/null || expr "$line" : ".*# *todo" >/dev/null + then + ship_char ${TODO_OK} + ship_line "$line" + todocount=$((todocount + 1)) + elif expr "$line" : ".*# *SKIP" >/dev/null || expr "$line" : ".*# *skip" >/dev/null + then + ship_char ${SKIP} + ship_line "$line" + skipcount=$((skipcount + 1)) + else + ship_char ${OK} + fi + state=ok + continue + fi + # Process a not-ok line + if expr "$line" : "not ok" >/dev/null + then + testcount=$((testcount + 1)) + if [ "$expect" = "" ] + then + test_before_plan=yes + else + test_after_plan=yes + fi + if expr "$line" : ".*# *SKIP" >/dev/null || expr "$line" : ".*# *skip" >/dev/null + then + ship_char "${SKIP}" + state=ok + skipcount=$((skipcount + 1)) + continue + fi + if expr "$line" : ".*# *TODO" >/dev/null || expr "$line" : ".*# *todo" >/dev/null + then + ship_char ${TODO_NOT_OK} + state=ok + todocount=$((todocount + 1)) + continue + fi + ship_char "${FAIL}" + ship_line "$line" + state=not_ok + failcount=$((failcount + 1)) + status=1 + continue + fi + # shellcheck disable=SC2166 + if [ "${state}" = "yaml" ] + then + ship_line "$line" + if expr "$line" : '[ ]*\.\.\.' >/dev/null + then + state=ok + fi + elif expr "$line" : "[ ]*---" >/dev/null + then + ship_line "$line" + state=yaml + fi +done + +/bin/echo "" + +if [ -z "$expect" ] +then + ship_line "Missing a plan." + status=1 +elif [ "$test_before_plan" = "yes" ] && [ "$test_after_plan" = "yes" ] +then + ship_line "A plan line may only be placed before or after all tests." + status=1 +elif [ "${expect}" -gt "${testcount}" ] +then + ship_line "Expected ${expect} tests but only ${testcount} ran." + status=1 +elif [ "${expect}" -lt "${testcount}" ] +then + ship_line "Expected ${expect} tests but ${testcount} ran." + status=1 +fi + +report="${report}${testcount} tests, ${failcount} failures" +if [ "$todocount" != 0 ] +then + report="${report}, ${todocount} TODOs" +fi +if [ "$skipcount" != 0 ] +then + report="${report}, ${skipcount} SKIPs" +fi + +echo "${report}." + +exit "${status}" + +# end diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml new file mode 100644 index 0000000..e79b959 --- /dev/null +++ b/.github/workflows/check.yaml @@ -0,0 +1,40 @@ +name: Check +on: [pull_request] +jobs: + + check: + name: Check rewrite function + runs-on: ubuntu-latest + steps: + + - uses: actions/checkout@v2 + + - uses: actions/setup-python@v4 + with: + python-version: '3.9' + + - name: Run check + run: ansible-playbook -i hosts check.yaml + + - name: Run tapview + if: success() || failure() + run: cat test-results.tap | ./.ci/tapview | tee test-results.txt + + - name: Collect tapview output + if: (success() || failure()) && github.event_name == 'pull_request' + run: | + echo 'TEST_RESULTS<> $GITHUB_ENV + cat test-results.txt >> $GITHUB_ENV + echo 'EOF' >> $GITHUB_ENV + + - uses: actions/github-script@v1 + if: (success() || failure()) && github.event_name == 'pull_request' + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + github.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: `${{ env.TEST_RESULTS }}` + }) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..bd6b548 --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -0,0 +1,26 @@ +name: Deploy +on: + pull_request: + types: + - closed + paths: + - 'group_vars/**' + - 'templates/lambda_function.py.j2' + +jobs: + deploy: + if: github.event.pull_request.merged == true && github.ref == 'main' && github.repository_owner == 'galaxyproject' + name: Deploy rewrite function + runs-on: ubuntu-latest + steps: + + - uses: actions/checkout@v2 + + - name: Install boto3 + run: pip install boto3 + + - name: Run deploy + run: ansible-playbook -i hosts lambda.yaml + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} diff --git a/group_vars/all.yaml b/group_vars/all.yaml index 97b7bb5..dec7e7f 100644 --- a/group_vars/all.yaml +++ b/group_vars/all.yaml @@ -5,6 +5,7 @@ gxy_io_rewrites: - src: /toolshed dest: https://toolshed.g2.bx.psu.edu/ +__hold: # Conferences and meetings - src: /bcc dest: https://live.remo.co/e/bcc-2020 diff --git a/lambda.yaml b/lambda.yaml index 37cc97c..0452374 100644 --- a/lambda.yaml +++ b/lambda.yaml @@ -51,7 +51,12 @@ lambda_function_associations: - event_type: viewer-request lambda_function_arn: "{{ gxy_io_lambda_arn }}" - tags: cloudfront + # this can fail for a bit due to: + # The function must be in an Active state. The current state for function arn:...:function:gxy-io-redirect: is Pending + register: __gxy_io_cloudfront_deploy + until: __gxy_io_cloudfront_deploy is success + retries: 18 + delay: 10 always: