Skip to content

Merge pull request #1609 from gitgitgadget/dependabot/npm_and_yarn/ty… #2560

Merge pull request #1609 from gitgitgadget/dependabot/npm_and_yarn/ty…

Merge pull request #1609 from gitgitgadget/dependabot/npm_and_yarn/ty… #2560

# Run tests against developer push
# Runs jobs on linux and windows to maintain compatibility.
# The main repo is checked out into a sub-directory because an optional
# second repo may be checked out for testing.
# Optional GitHub secrets
# See ci-helper.test.ts for information on the following
# GGG_IMAP_HOST = <email_imap_hostname>
# GGG_SMTP_USER = <email_userid>
# GGG_SMTP_PASS = <email_password>
# GGG_SMTP_HOST = <email_hostname>
# GGG_SMTP_OPTS = <email_smtp_options> This is a json object.
# See github-glue.test.ts for information on the following
# GGG_TOKEN = token to access the test repo
# GGG_REPOSITORY = name of test repo to update in tests. Tests will
# open a PR, create comments, etc. This can be a private or public
# repo.
name: Build & run tests
on:
push:
branches-ignore:
- dependabot/**
pull_request:
jobs:
build-test:
name: Node v${{ matrix.node-version }} on ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
node-version: [20.x]
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
# job level env vars used for a couple of steps
env:
GGG_TOKEN: ${{ secrets.GGG_TOKEN }}
GGG_REPOSITORY: ${{ secrets.GGG_REPOSITORY }}
GGG_SMTP_USER: ${{ secrets.GGG_SMTP_USER }}
GGG_SMTP_PASS: ${{ secrets.GGG_SMTP_PASS }}
GGG_SMTP_HOST: ${{ secrets.GGG_SMTP_HOST }}
GGG_IMAP_HOST: ${{ secrets.GGG_IMAP_HOST }}
steps:
# Check out repo under sub-dir so other repo can be checked out
- uses: actions/checkout@v4
with:
path: gitgitgadget
- name: Set git test repo config
shell: bash
run: |
if [ -n "$GGG_TOKEN" ] && [ -n "$GGG_REPOSITORY" ];
then
echo "GGG_REPO='gitgitgadget.CIGitHubTestUser=$GITHUB_REPOSITORY_OWNER' 'gitgitgadget.$GITHUB_REPOSITORY_OWNER.githubrepo=$GGG_REPOSITORY' 'gitgitgadget.$GITHUB_REPOSITORY_OWNER.githubtoken=$GGG_TOKEN'" >> $GITHUB_ENV
else
echo "::error::Both GGG_TOKEN and GGG_REPOSITORY secrets must be set"
exit 1
fi
if: env.GGG_TOKEN || env.GGG_REPOSITORY
- name: Set smtp config
env:
GGG_SMTP_OPTS: ${{ secrets.GGG_SMTP_OPTS }}
shell: bash
run: |
if [ -n "$GGG_SMTP_USER" ] && [ -n "$GGG_SMTP_PASS" ] && [ -n "$GGG_SMTP_HOST" ] && [ -n "$GGG_IMAP_HOST" ];
then
m="'gitgitgadget.cismtpuser=$GGG_SMTP_USER' 'gitgitgadget.cismtppass=$GGG_SMTP_PASS' 'gitgitgadget.cismtphost=$GGG_SMTP_HOST' 'gitgitgadget.ciimaphost=$GGG_IMAP_HOST'";
if [ -n "$GGG_SMTP_OPTS" ];
then
m+=" 'gitgitgadget.cismtpopts=$GGG_SMTP_OPTS'"
fi
# trailing space is required if repo set
if [ -n "$GGG_REPO" ];
then
m+=" "
fi
echo "GGG_SMTP=$m" >> $GITHUB_ENV
else
echo "::error::All of GGG_SMTP_USER, GGG_SMTP_PASS and GGG_SMTP_HOST secrets must be set"
exit 1
fi
if: env.GGG_SMTP_USER || env.GGG_SMTP_PASS || env.GGG_SMTP_HOST
# Check out github-glue.test.ts repo if configured for it
- uses: actions/checkout@v4
with:
repository: ${{ github.repository_owner }}/${{ env.GGG_REPOSITORY }}
token: ${{ env.GGG_TOKEN }}
path: ${{ env.GGG_REPOSITORY }}
if: env.GGG_TOKEN
- uses: actions/setup-node@v4
with:
node-version: '${{ matrix.node-version }}'
- name: Install packages
run: npm ci
working-directory: gitgitgadget
- name: Run linter
run: npm run lint
working-directory: gitgitgadget
- name: Run build
run: npm run build
working-directory: gitgitgadget
- name: Run tests
env:
GIT_CONFIG_PARAMETERS: ${{ env.GGG_SMTP }}${{ env.GGG_REPO }}
run: npm run test
working-directory: gitgitgadget
- name: Clean up two day old branches and PRs
uses: actions/github-script@v7
id: clean-up
with:
github-token: ${{ env.GGG_TOKEN }}
script: |
const exports = require(`${process.env.GITHUB_WORKSPACE}/gitgitgadget/build/lib/delete-ci-test-branches.js`)
await exports.deleteBranches(github, process.env.GITHUB_REPOSITORY_OWNER, process.env.GGG_REPOSITORY);
if: env.GGG_REPOSITORY