Skip to content

Commit

Permalink
Test build on github actions
Browse files Browse the repository at this point in the history
Merge in CI/github-actions-runner from feature/AG-32057 to master

* commit 'dc1fc14c0ee20fd2c3126f554824825f55a2cb95':
  test if disappear
  add test
  fail if workflow run was broken or if no artifacts found
  use real start time
  fail test
  fix eslint error
  show action
  set gh token
  fix path
  test build on github actions
  • Loading branch information
maximtop committed Apr 23, 2024
2 parents 33bea3f + dc1fc14 commit 1dd1189
Show file tree
Hide file tree
Showing 10 changed files with 304 additions and 83 deletions.
76 changes: 76 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Builds project
name: Build

env:
NODE_VERSION: 20

on:
workflow_dispatch:
inputs:
id:
type: 'string'
description: 'Unique identifier for the workflow run. Needed for github-actions-runner'

## Required for github-actions-runner
run-name: ${{github.workflow}} [ID:${{ inputs.id }}]

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# Number of commits to fetch. 0 indicates all history.
fetch-depth: 0
- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
version: 8
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: pnpm
- name: Run bash commands
shell: bash
run: |
ls -alt
# Install deps
pnpm install
pnpm lint
pnpm test
pnpm pack && mv adguard-github-actions-runner-*.tgz github-actions-runner.tgz
- name: Save dist artifact
uses: actions/upload-artifact@v4
with:
name: github-actions-runner.tgz
path: ./github-actions-runner.tgz
notify:
needs: test
# Run this job only if the previous job failed and the event was triggered by the 'AdguardTeam/GithubActionsRunner' repository
# Note: 'always()' is needed to run the notify job even if the test job was failed
if:
${{
always() &&
needs.test.result == 'failure' &&
github.repository == 'AdguardTeam/GithubActionsRunner' &&
(
github.event_name == 'push' ||
github.event.pull_request.head.repo.full_name == github.repository
)
}}
runs-on: ubuntu-latest
steps:
- name: Send Slack notification
uses: 8398a7/action-slack@v3
with:
status: failure
fields: workflow, repo, message, commit, author, eventName, ref, job
job_name: test
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
6 changes: 0 additions & 6 deletions __tests__/index.test.ts

This file was deleted.

17 changes: 17 additions & 0 deletions __tests__/lib/github/GithubApiManager.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { GithubApiManager } from '../../../src/lib/github/GithubApiManager';
import { GithubApiClient } from '../../../src/lib/github/GithubApiClient';

// Silence logger output
jest.mock('../../../src/lib/utils/logger');

describe('GithubApiManager', () => {
describe('downloadArtifacts', () => {
it('throws error if no artifacts found', async () => {
const githubApiClient = new GithubApiClient('test', 'test', 'test');
githubApiClient.listWorkflowArtifacts = jest.fn().mockResolvedValue({ data: { artifacts: [] } });

const githubApiManager = new GithubApiManager(githubApiClient);
await expect(githubApiManager.downloadArtifacts({ id: 1 }, 'test')).rejects.toThrow('No artifacts found');
});
});
});
4 changes: 2 additions & 2 deletions bamboo-specs/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ Build:
shared: true
required: true
requirements:
- adg-docker: 'true'
- adg-docker: true

triggers: []

branches:
create: manually
delete: never
link-to-jira: 'true'
link-to-jira: true

notifications:
- events:
Expand Down
19 changes: 15 additions & 4 deletions bamboo-specs/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Test:
docker:
image: ${bamboo.dockerNode}
volumes:
${system.PNPM_DIR}: "${bamboo.cachePnpm}"
${system.PNPM_DIR}: ${bamboo.cachePnpm}
tasks:
- checkout:
force-clean-build: true
Expand All @@ -40,9 +40,15 @@ Test:
# Set cache directory
pnpm config set store-dir ${bamboo.cachePnpm}
# FIXME Remove after github-actions-runner will be in the docker image
pnpm install
pnpm lint
pnpm test
pnpm build
branch="${bamboo_planRepository_branchName}"
revision="${bamboo_planRepository_revision}"
# FIXME use github-actions-runner binary after it will be exposed in the docker
GITHUB_TOKEN=${bamboo.githubActionsRunnerPassword} node dist/bin/index.js run-action --repo AdguardTeam/GithubActionsRunner --branch "$branch" --rev "$revision" --workflow build.yml --artifacts-path .
final-tasks:
- script:
interpreter: SHELL
Expand All @@ -59,8 +65,13 @@ Test:
echo "Size before cleanup:" && du -h | tail -n 1
rm -rf node_modules
echo "Size after cleanup:" && du -h | tail -n 1
artifacts:
- name: github-actions-runner.tgz
pattern: github-actions-runner.tgz
shared: true
required: true
requirements:
- adg-docker: true
- adg-docker: 'true'

branches:
create: for-pull-request
Expand Down
6 changes: 5 additions & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module.exports = {
preset: 'ts-jest',
transform: {
'^.+\\.(t|j)sx?$': '@swc/jest',
},
testEnvironment: 'node',
modulePathIgnorePatterns: ['smoke'],
transformIgnorePatterns: ['node_modules/(?!(.*(nanoid))/)'], // since pnpm uses symlinks, we add `.*` to the path
};
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"prepack": "pnpm build",
"watch": "rollup -c rollup.config.ts --configPlugin typescript --watch",
"build": "rimraf dist && rollup -c rollup.config.ts --configPlugin typescript && pnpm build:types",
"test": "pnpm run test:smoke",
"test": "jest",
"lint": "eslint --cache . && tsc -p tsconfig.eslint.json --noEmit",
"build:types": "tsc --project tsconfig.json --declaration --emitDeclarationOnly --outdir dist/types --rootDir src",
"build:txt": "ts-node scripts/build-txt",
Expand Down Expand Up @@ -65,6 +65,8 @@
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-typescript": "^11.1.6",
"@swc/core": "^1.4.17",
"@swc/jest": "^0.2.36",
"@types/fs-extra": "^11.0.4",
"@types/jest": "^29.5.12",
"@types/node": "^20.12.7",
Expand All @@ -79,7 +81,6 @@
"jest": "^29.7.0",
"rimraf": "^5.0.5",
"rollup": "^4.14.3",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"tslib": "^2.6.2",
"typescript": "^5.4.5"
Expand Down
Loading

0 comments on commit 1dd1189

Please sign in to comment.