Nightly #284
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Nightly | |
on: | |
schedule: | |
# Times in UTC (PST+8), this translates to running Mon-Fri at midnight/1am (depending on DST) | |
- cron: 0 8 * * 1-5 | |
# Only enable on pull requests for testing | |
# pull_request: | |
# paths: [.github/workflows/nightly.yaml] | |
workflow_dispatch: {} | |
permissions: read-all | |
jobs: | |
# Run tests against all linters for snapshots and latest version as they exist on main | |
# This job is used to diagnose plugin config health in advance of a release | |
linter_tests_main: | |
name: Plugin Tests Main | |
runs-on: ${{ matrix.os }} | |
timeout-minutes: 60 | |
strategy: | |
fail-fast: false | |
matrix: | |
linter-version: [Snapshots, Latest] | |
os: [ubuntu-latest, macos-latest] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 | |
- name: Cache tool downloads | |
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1 | |
with: | |
path: /tmp/plugins_testing_download_cache | |
# No need to key on trunk version unless we change how we store downloads. | |
key: trunk-${{ runner.os }} | |
- name: Delete cache | |
# For now, avoid deleting cache on pull request changes to nightly. This improves PR experience. | |
if: env.TRIGGER != 'pull_request' | |
run: | | |
if [ -d "/tmp/plugins_testing_download_cache" ] | |
then | |
tmp_dir=/tmp/${GITHUB_RUN_ID}-${GITHUB_RUN_NUMBER}-${GITHUB_RUN_ATTEMPT} | |
mv "/tmp/plugins_testing_download_cache" ${tmp_dir} | |
chmod -R u+w ${tmp_dir} | |
rm -rf ${tmp_dir} | |
fi | |
shell: bash | |
- name: Linter Tests | |
uses: ./.github/actions/linter_tests | |
with: | |
linter-version: ${{ matrix.linter-version }} | |
sourcery-token: ${{ secrets.TRUNK_SOURCERY_TOKEN }} | |
# Run tests against all linters for snapshots and latest version as they exist in latest release | |
# This job is used to update the list of validated versions | |
linter_tests_release: | |
name: Plugin Tests Release | |
runs-on: ${{ matrix.os }} | |
timeout-minutes: 60 | |
strategy: | |
fail-fast: false | |
matrix: | |
linter-version: [Snapshots, Latest] | |
os: [ubuntu-latest, macos-latest] | |
outputs: | |
plugin-version: ${{ steps.get-release.outputs.tag }} | |
steps: | |
- name: Retrieve git history | |
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 | |
with: | |
fetch-depth: 0 | |
# This assumes that any changes on main since the last release are backwards compatible | |
# in terms of allowing existing linter tests to run. | |
- name: Preserve test runner latest behavior | |
run: | | |
cp -r tests tests.bak | |
cp package.json package.json.bak | |
cp package-lock.json package-lock.json.bak | |
cp -r .github/actions .github/actions.bak | |
# Include any newly generated snapshots that have been marked release-ready | |
grep "// trunk-upgrade-validation:RELEASE" -r --include=*.shot -l | xargs -I {} cp {}{,.bak} | |
continue-on-error: true | |
- name: Get Latest Release | |
id: get-release | |
uses: WyriHaximus/github-action-get-previous-tag@385a2a0b6abf6c2efeb95adfac83d96d6f968e0c # v1.3.0 | |
with: | |
# only use releases tagged v<semver> | |
prefix: v | |
- name: Checkout | |
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 | |
with: | |
ref: ${{ steps.get-release.outputs.tag }} | |
clean: false | |
- name: Overwrite test runners with latest behavior | |
run: | | |
mv tests.bak tests | |
mv package.json.bak package.json | |
mv package-lock.json.bak package-lock.json | |
mv .github/actions.bak .github/actions | |
# Include any newly generated snapshots that have been marked release-ready, but don't replace if present | |
grep "// trunk-upgrade-validation:RELEASE" -r --include=*.shot.bak -l | sed -e 's/.bak//' | xargs -I {} mv {}{.bak,} | |
continue-on-error: true | |
- name: Cache tool downloads | |
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1 | |
with: | |
path: /tmp/plugins_testing_download_cache | |
# No need to key on trunk version unless we change how we store downloads. | |
key: trunk-${{ runner.os }} | |
- name: Delete cache | |
# For now, avoid deleting cache on pull request changes to nightly. This improves PR experience. | |
if: env.TRIGGER != 'pull_request' | |
run: | | |
if [ -d "/tmp/plugins_testing_download_cache" ] | |
then | |
tmp_dir=/tmp/${GITHUB_RUN_ID}-${GITHUB_RUN_NUMBER}-${GITHUB_RUN_ATTEMPT} | |
mv "/tmp/plugins_testing_download_cache" ${tmp_dir} | |
chmod -R u+w ${tmp_dir} | |
rm -rf ${tmp_dir} | |
fi | |
shell: bash | |
- name: Linter Tests | |
# Use overwritten dependency action, rather than released version | |
uses: ./.github/actions/linter_tests | |
with: | |
linter-version: ${{ matrix.linter-version }} | |
append-args: linters -- --json --outputFile=${{ matrix.os }}-res.json | |
sourcery-token: ${{ secrets.TRUNK_SOURCERY_TOKEN }} | |
# TODO(lauri): For now this just runs on the hardcoded versions. We should configure this | |
# akin to the linter_tests job. | |
- name: Tool Tests | |
uses: ./.github/actions/tool_tests | |
- name: Upload Test Outputs for Upload Job | |
# Only upload results from latest. Always run, except when cancelled. | |
if: (failure() || success()) && matrix.linter-version == 'Latest' | |
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 | |
with: | |
name: ${{ matrix.os }}-test-results | |
path: ${{ matrix.os }}-res.json | |
upload_test_results: | |
name: Upload Test Results | |
needs: linter_tests_release | |
runs-on: ubuntu-latest | |
# Still run on test failure | |
if: always() | |
timeout-minutes: 10 | |
env: | |
SLACK_CHANNEL_ID: plugins-notifications | |
steps: | |
- name: Checkout | |
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 | |
- name: Retrieve Test Outputs ubuntu | |
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 | |
with: | |
name: ubuntu-latest-test-results | |
- name: Retrieve Test Outputs macOS | |
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 | |
with: | |
name: macos-latest-test-results | |
- name: Setup Node | |
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0 | |
with: | |
node-version: 18 | |
- name: Sync lfs | |
run: git lfs pull | |
- name: Install Dependencies | |
run: npm ci | |
- name: Add npm bin to path | |
run: echo "$PWD/node_modules/.bin" >> "$GITHUB_PATH" | |
- name: Parse Test Results | |
id: parse | |
run: | | |
npm run parse | |
echo "failures=$([[ -f failures.json ]] && echo "true" || echo "false")" >> "$GITHUB_OUTPUT" | |
echo "failures-payload=$(cat failures.json)" >> "$GITHUB_OUTPUT" | |
env: | |
PLUGIN_VERSION: ${{needs.linter_tests_release.outputs.plugin-version}} | |
# Used to format Slack notification for failures | |
RUN_ID: ${{ github.run_id }} | |
TEST_REF: Release | |
- name: Upload Test Results Staging | |
continue-on-error: true | |
id: upload-staging | |
env: | |
TRUNK_API_TOKEN: ${{ secrets.TRUNK_STAGING_API_TOKEN }} | |
TRUNK_API_ADDRESS: api.trunk-staging.io:8443 | |
# upload-linter-versions is a hidden command reserved exclusively for uploading | |
# validated results from the plugins repo. | |
# daemon must be restarted in order to propagate environment variable | |
run: | | |
trunk daemon shutdown | |
trunk upload-linter-versions --token="$TRUNK_API_TOKEN" results.json | |
- name: Upload Test Results Prod | |
continue-on-error: true | |
id: upload-prod | |
env: | |
TRUNK_API_TOKEN: ${{ secrets.TRUNK_API_TOKEN }} | |
TRUNK_API_ADDRESS: api.trunk.io:8443 | |
# upload-linter-versions is a hidden command reserved exclusively for uploading | |
# validated results from the plugins repo. | |
# daemon must be restarted in order to propagate environment variable | |
run: | | |
trunk daemon shutdown | |
trunk upload-linter-versions --token="$TRUNK_API_TOKEN" results.json | |
# Slack notifications | |
- name: Slack Notification For Failures | |
uses: slackapi/slack-github-action@e28cf165c92ffef168d23c5c9000cffc8a25e117 # v1.24.0 | |
if: always() && steps.parse.outputs.failures == 'true' | |
with: | |
channel-id: ${{ env.SLACK_CHANNEL_ID }} | |
payload: ${{ steps.parse.outputs.failures-payload }} | |
env: | |
SLACK_BOT_TOKEN: ${{ secrets.TRUNKBOT_SLACK_BOT_TOKEN }} | |
- name: Slack Notification For Staging Upload Failure | |
uses: slackapi/slack-github-action@e28cf165c92ffef168d23c5c9000cffc8a25e117 # v1.24.0 | |
if: steps.upload-staging.outcome == 'failure' | |
with: | |
channel-id: ${{ env.SLACK_CHANNEL_ID }} | |
payload: | | |
{ | |
"text": "Upload Failure", | |
"blocks": [ | |
{ | |
"type": "section", | |
"text": { | |
"type": "mrkdwn", | |
"text": "Failure: <https://github.com/trunk-io/plugins/actions/runs/${{ github.run_id }}| Upload Test Results to Staging >" | |
} | |
} | |
] | |
} | |
env: | |
SLACK_BOT_TOKEN: ${{ secrets.TRUNKBOT_SLACK_BOT_TOKEN }} | |
- name: Slack Notification For Prod Upload Failure | |
uses: slackapi/slack-github-action@e28cf165c92ffef168d23c5c9000cffc8a25e117 # v1.24.0 | |
if: steps.upload-prod.outcome == 'failure' | |
with: | |
channel-id: ${{ env.SLACK_CHANNEL_ID }} | |
payload: | | |
{ | |
"text": "Upload Failure", | |
"blocks": [ | |
{ | |
"type": "section", | |
"text": { | |
"type": "mrkdwn", | |
"text": "Failure: <https://github.com/trunk-io/plugins/actions/runs/${{ github.run_id }}| Upload Test Results to Prod >" | |
} | |
} | |
] | |
} | |
env: | |
SLACK_BOT_TOKEN: ${{ secrets.TRUNKBOT_SLACK_BOT_TOKEN }} | |
# Run repo healthcheck tests | |
repo_tests: | |
name: Repo Tests | |
uses: ./.github/workflows/repo_tests.reusable.yaml |