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

test conditional tests #1052

Merged
merged 10 commits into from
Jun 1, 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
85 changes: 85 additions & 0 deletions .github/workflows/manual_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: On-demand deploy

# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows
on:
issue_comment:
types: [created]

jobs:
deploy:
runs-on: ubuntu-latest
# Only run if it is a PR and the comment contains /deploy
if: github.event.issue.pull_request && contains(github.event.comment.body, '/deploy')

steps:
- name: Get branch of PR
uses: xt0rted/pull-request-comment-branch@v1
id: comment-branch
- name: Set latest commit status as pending
uses: myrotvorets/set-commit-status-action@master
with:
sha: ${{ steps.comment-branch.outputs.head_sha }}
token: ${{ secrets.GITHUB_TOKEN }}
status: pending
- uses: actions/checkout@v3
with:
submodules: recursive
ref: ${{ steps.comment-branch.outputs.head_ref }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ env.USERNAME }}
password: ${{ env.PASSWORD }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4.4.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

# see https://github.com/docker/build-push-action/issues/513#issuecomment-987951050
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# it seems that cache is not giving any benefit in speed, lets keep it disabled for now
# cache-from: type=gha
# cache-to: type=gha,mode=max
build-args: |
BUILDKIT_CONTEXT_KEEP_GIT_DIR=true

- name: Add workflow result as comment on PR
uses: actions/github-script@v6
if: always()
with:
script: |
const workflow_name = '${{ github.workflow }}';
const job_name = '${{ github. }}';
const url = '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}';
const success = '${{ job.status }}' === 'success';
const body = `${workflow_name}: ${success ? 'succeeded ✅' : 'failed ❌'}\n${url}`;

await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
})

- name: Set latest commit status as ${{ job.status }}
uses: myrotvorets/set-commit-status-action@master
if: always()
with:
sha: ${{ steps.comment-branch.outputs.head_sha }}
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
83 changes: 83 additions & 0 deletions .github/workflows/manual_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: On-demand tests

# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows
on:
issue_comment:
types: [created]

# see https://github.community/t/treating-warnings-as-errors-because-process-env-ci-true/18032
env:
CI: false

jobs:
build_and_test:
runs-on: ubuntu-latest
# Only run if it is a PR and the comment contains /test
if: github.event.issue.pull_request && contains(github.event.comment.body, '/test')
strategy:
matrix:
node-version: [18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- name: Get branch of PR
uses: xt0rted/pull-request-comment-branch@v1
id: comment-branch
- name: Set latest commit status as pending
uses: myrotvorets/set-commit-status-action@master
with:
sha: ${{ steps.comment-branch.outputs.head_sha }}
token: ${{ secrets.GITHUB_TOKEN }}
status: pending
- uses: actions/checkout@v3
with:
submodules: recursive
ref: ${{ steps.comment-branch.outputs.head_ref }}
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- run: npm run start &
- name: Wait for the app to start
uses: iFaxity/wait-on-action@v1.1.0
with:
resource: http://localhost:3000
- name: Run tests
uses: nick-fields/retry@v2
with:
max_attempts: 2
retry_on: error
timeout_seconds: 120
command: npm test

- name: Add workflow result as comment on PR
uses: actions/github-script@v6
if: always()
with:
script: |
const workflow_name = '${{ github.workflow }}';
const job_name = '${{ github. }}';
const url = '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}';
const success = '${{ job.status }}' === 'success';
const body = `${workflow_name}: ${success ? 'succeeded ✅' : 'failed ❌'}\n${url}`;

await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
})

- name: Set latest commit status as ${{ job.status }}
uses: myrotvorets/set-commit-status-action@master
if: always()
with:
sha: ${{ steps.comment-branch.outputs.head_sha }}
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}