Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A reusable workflow for running e2e tests #144

Merged
merged 7 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 2 additions & 97 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,6 @@ jobs:
config: "markdownlint-config.json"
args: "README.md"

build:
runs-on: ubuntu-latest
steps:
- name: Remove unnecessary files
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
- uses: actions/checkout@v3
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: zulu
java-version: 17
- name: Build Plugin
env:
CI_BUILD_PLUGIN: true
run: |
chmod +x ./gradlew
./gradlew buildPlugin
- name: Upload build folder
uses: actions/upload-artifact@v3
with:
name: mirrord-build
path: build/

lint:
runs-on: ubuntu-latest
steps:
Expand All @@ -73,75 +48,7 @@ jobs:
run: ./gradlew ktlintCheck

e2e:
needs: [ build ]
runs-on: ubuntu-latest
env:
CI_BUILD_PLUGIN: "true"
steps:
- name: Public IP
id: ip
uses: haythem/[email protected]
- name: Print Public IP
run: |
echo ${{ steps.ip.outputs.ipv4 }}
echo ${{ steps.ip.outputs.ipv6 }}
- name: Remove unnecessary files
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
- uses: actions/checkout@v3
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: zulu
java-version: 17
- uses: actions/setup-python@v4
with:
python-version: 3.11
- uses: abatilo/actions-poetry@v2
- run: poetry --version
- name: get mirrord latest
run: |
curl -fsSL https://raw.githubusercontent.com/metalbear-co/mirrord/main/scripts/install.sh | bash
- name: Start minikube
uses: medyagh/setup-minikube@master
with:
container-runtime: docker
- run: |
minikube image load /tmp/test.tar
kubectl apply -f sample/kubernetes/app.yaml
echo "POD_TO_SELECT=$(kubectl get pods -o=name | head -n 1)" >> "$GITHUB_ENV"
kubectl wait --for=condition=ready --timeout=30s $(kubectl get pods -o=name | head -n 1)
KUBE_SERVICE=$(minikube service list --output=json | jq -r '.[] | select(.Name == "py-serv") | .URLs[0]')
echo "$KUBE_SERVICE"
echo "KUBE_SERVICE=$KUBE_SERVICE" >> "$GITHUB_ENV"
- name: Setup FFmpeg
uses: FedericoCarboni/setup-ffmpeg@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Download build folder
uses: actions/download-artifact@v3
with:
name: mirrord-build
path: build/
- name: Run intellij e2e in headless state
uses: coactions/setup-xvfb@v1
env:
POD_TO_SELECT: ${{ env.POD_TO_SELECT }}
KUBE_SERVICE: ${{ env.KUBE_SERVICE }}
with:
run: ./gradlew test
- name: Move video
if: ${{ failure() }}
run: |
mv video build/reports
- name: Save fails report
if: ${{ failure() }}
uses: actions/upload-artifact@v3
with:
name: mirrord-plugin-fail-report
path: |
build/reports
uses: ./.github/workflows/reusable_e2e.yaml

ci-success:
name: ci
Expand All @@ -150,7 +57,6 @@ jobs:
needs:
[
towncrier_check,
build,
e2e,
lint_markdown,
]
Expand All @@ -160,8 +66,7 @@ jobs:
# We have to do it in the shell since if it's in the if condition
# then skipping is considered success by branch protection rules
env:
CI_SUCCESS: ${{ (needs.towncrier_check.result == 'success') &&
(needs.build.result == 'success' || needs.build.result == 'skipped') &&
CI_SUCCESS: ${{ (needs.towncrier_check.result == 'success') &&
(needs.e2e.result == 'success' || needs.e2e.result == 'skipped') &&
(needs.lint_markdown.result == 'success' || needs.lint_markdown.result == 'skipped') }}
run: echo $CI_SUCCESS && if [ "$CI_SUCCESS" == "true" ]; then echo "SUCCESS" && exit 0; else echo "Failure" && exit 1; fi
124 changes: 124 additions & 0 deletions .github/workflows/reusable_e2e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# This is a reusable workflow that can be run based on `mirrord_release_branch` boolean input
# in the `mirrord` or `mirrord-intellij` repository and hence is maintained in a single place.
# The difference in the workflow when `mirrord_release_branch` is set is as follows:
# - we checkout into the latest released tag of `mirrord-intellij` from the perspective of binary
# that has to be released on `mirrord` side. if not set, we checkout into the current branch.
# - we rely on downloading the mirrord binary from `mirrord-artifacts` using `actions/download-artifact`
# and adding it to the path. if not set, the latest version is downloaded.

name: reusable_e2e
on:
workflow_call:
inputs:
mirrord_release_branch:
required: false
type: boolean
default: false

jobs:
intellij-e2e:
runs-on: ubuntu-latest
env:
CI_BUILD_PLUGIN: "true"
steps:
- name: Public IP
id: ip
uses: haythem/[email protected]
- name: Print Public IP
run: |
echo ${{ steps.ip.outputs.ipv4 }}
echo ${{ steps.ip.outputs.ipv6 }}

- name: Remove unnecessary files
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf "$AGENT_TOOLSDIRECTORY"

- name: checkout repository
if: ${{ !github.event.inputs.mirrord_release_branch }}
uses: actions/checkout@v3

# mirrord_release_branch boolean when set, means we are on a release branch
# and hence we need to checkout into the last released tag of mirrord-intellij
- name: checkout into mirrord-intellij if mirrord_release_branch
eyalb181 marked this conversation as resolved.
Show resolved Hide resolved
if: ${{ github.event.inputs.mirrord_release_branch }}
uses: actions/checkout@v3
with:
repository: "metalbear-co/mirrord-intellij"

- name: checkout into the last released tag if mirrord_release_branch
if: ${{ github.event.inputs.mirrord_release_branch }}
run: |
git fetch --all --tags
git checkout tags/$(grep 'pluginVersion =' gradle.properties | cut -d '=' -f 2 | xargs)

- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: zulu
java-version: 17

- uses: actions/setup-python@v4
with:
python-version: 3.11
- uses: abatilo/actions-poetry@v2

# we are on a release branch, so we need to download the mirrord binary from
# mirrord-artifacts and add it to the path
- name: download mirrord binary
if: ${{ github.event.inputs.mirrord_release_branch }}
uses: actions/download-artifact@v3
with:
name: mirrord-artifacts
- name: add downloaded mirrord to path
if: ${{ github.event.inputs.mirrord_release_branch }}
run: |
chmod u+x mirrord
echo "${GITHUB_WORKSPACE}" >> "$GITHUB_PATH"

- name: get the latest mirrord binary
if: ${{ !github.event.inputs.mirrord_release_branch }}
run: |
curl -fsSL https://raw.githubusercontent.com/metalbear-co/mirrord/main/scripts/install.sh | bash

- name: Start minikube
uses: medyagh/setup-minikube@master
with:
container-runtime: docker
- run: |
kubectl apply -f sample/kubernetes/app.yaml
echo "POD_TO_SELECT=$(kubectl get pods -o=name | head -n 1)" >> "$GITHUB_ENV"
kubectl wait --for=condition=ready --timeout=30s $(kubectl get pods -o=name | head -n 1)
KUBE_SERVICE=$(minikube service list --output=json | jq -r '.[] | select(.Name == "py-serv") | .URLs[0]')
echo "$KUBE_SERVICE"
echo "KUBE_SERVICE=$KUBE_SERVICE" >> "$GITHUB_ENV"

- name: Setup FFmpeg
uses: FedericoCarboni/setup-ffmpeg@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: build plugin
run: |
./gradlew buildPlugin

- name: Run intellij e2e in headless state
uses: coactions/setup-xvfb@v1
env:
POD_TO_SELECT: ${{ env.POD_TO_SELECT }}
KUBE_SERVICE: ${{ env.KUBE_SERVICE }}
with:
run: |
./gradlew test

- name: Save the failure video
if: ${{ failure() }}
run: |
mv video build/reports
- name: Save fails report
if: ${{ failure() }}
uses: actions/upload-artifact@v3
with:
name: mirrord-plugin-fail-report
path: |
build/reports
1 change: 1 addition & 0 deletions changelog.d/+reusable-e2e.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Create a reusable worflow for running e2e tests such that we maintain e2e in one place and can run tests on mirrord's release branch