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

chore(ci): Better local running #17432

Merged
merged 58 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
f8c3b4d
Fixed import-merge syntax
AndesKrrrrrrrrrrr Jan 6, 2025
2e95836
Add conditional publishing steps
AndesKrrrrrrrrrrr Jan 6, 2025
8ed2b6f
Set runner image by env
AndesKrrrrrrrrrrr Jan 6, 2025
1a5c98d
Merge branch 'main' into fix/codemagic-publish
AndesKrrrrrrrrrrr Jan 6, 2025
24d9f46
Only check existence of relevant branches
AndesKrrrrrrrrrrr Jan 6, 2025
9fc122c
Don't run locally
AndesKrrrrrrrrrrr Jan 6, 2025
daa6e55
Names and debug
AndesKrrrrrrrrrrr Jan 6, 2025
fd15e54
Improve get-cache
AndesKrrrrrrrrrrr Jan 6, 2025
4362cdc
Revert "Improve get-cache"
AndesKrrrrrrrrrrr Jan 6, 2025
fbcc75c
Add cache-url input and only set when not local
AndesKrrrrrrrrrrr Jan 6, 2025
6063198
pipefail by default
AndesKrrrrrrrrrrr Jan 6, 2025
5d879c2
Install java if missing (for codegen
AndesKrrrrrrrrrrr Jan 6, 2025
1c050bd
Only home paths, and quoting
AndesKrrrrrrrrrrr Jan 7, 2025
9a0bfd4
// For local development
AndesKrrrrrrrrrrr Jan 7, 2025
44f07d7
Home debug
AndesKrrrrrrrrrrr Jan 7, 2025
bb851f7
Only override cypress cache when no env variable is set
AndesKrrrrrrrrrrr Jan 7, 2025
54b28fb
Fall back to all affected if stickman fails
AndesKrrrrrrrrrrr Jan 7, 2025
71e6d8e
Allow and handle failure in permission check
AndesKrrrrrrrrrrr Jan 7, 2025
0788e37
Don't collect failures
AndesKrrrrrrrrrrr Jan 7, 2025
0057399
Merge branch 'main' into chore/local-ci
AndesKrrrrrrrrrrr Jan 7, 2025
6276434
Revert codemagic.yaml to main
AndesKrrrrrrrrrrr Jan 7, 2025
751e93a
Comment, and improve readability
AndesKrrrrrrrrrrr Jan 7, 2025
f7c76f2
Revert image config
AndesKrrrrrrrrrrr Jan 7, 2025
2f92aa9
Revert default shell
AndesKrrrrrrrrrrr Jan 7, 2025
be1ec58
Subshell node list
AndesKrrrrrrrrrrr Jan 7, 2025
08d1c8e
debug checking out branches
AndesKrrrrrrrrrrr Jan 7, 2025
368f0d8
Fetch branch and comment
AndesKrrrrrrrrrrr Jan 7, 2025
32df32f
Create main branches as well
AndesKrrrrrrrrrrr Jan 7, 2025
aa3c059
Remove duplicate branch creation
AndesKrrrrrrrrrrr Jan 7, 2025
7d823f3
Remove java install step
AndesKrrrrrrrrrrr Jan 7, 2025
7d7c8a3
Refactor 'Preparing HEAD and BASE tags'
AndesKrrrrrrrrrrr Jan 7, 2025
c0b1146
Only try to create branches if they don't exist
AndesKrrrrrrrrrrr Jan 7, 2025
8704c2a
Revert "Only try to create branches if they don't exist"
AndesKrrrrrrrrrrr Jan 7, 2025
b533d8e
Spacing
AndesKrrrrrrrrrrr Jan 7, 2025
a564127
Verify or create branches
AndesKrrrrrrrrrrr Jan 7, 2025
c133164
Remove // For local development
AndesKrrrrrrrrrrr Jan 7, 2025
4e30406
Comment on Cypress override
AndesKrrrrrrrrrrr Jan 7, 2025
562a943
Reduce diff for 00_prepare-base-tags.sh
AndesKrrrrrrrrrrr Jan 7, 2025
df9b760
pullrequest.yml cleanup
AndesKrrrrrrrrrrr Jan 7, 2025
7a71e8d
Always wait for collector (revert to main)
AndesKrrrrrrrrrrr Jan 7, 2025
4211c40
Support localrun & less diff
AndesKrrrrrrrrrrr Jan 7, 2025
46b5ca3
Re-add octokit auth
AndesKrrrrrrrrrrr Jan 8, 2025
65e3182
Debug and pipefail get-cache exporting
AndesKrrrrrrrrrrr Jan 8, 2025
6734c9c
Revert actions/ to main
AndesKrrrrrrrrrrr Jan 8, 2025
2a5493f
Remove pipefail for export
AndesKrrrrrrrrrrr Jan 8, 2025
38d24b6
Rabbit review
AndesKrrrrrrrrrrr Jan 8, 2025
ace662d
Merge branch 'main' into chore/local-ci
AndesKrrrrrrrrrrr Jan 9, 2025
4d338fd
Move get-cache required env vars back to github-script
AndesKrrrrrrrrrrr Jan 9, 2025
3c83eff
Revert checking out relevant branches to main, but with force
AndesKrrrrrrrrrrr Jan 9, 2025
9121da3
checkout, but preserve local changes
AndesKrrrrrrrrrrr Jan 9, 2025
dda61a1
Merge branch 'main' into chore/local-ci
AndesKrrrrrrrrrrr Jan 9, 2025
ca50017
Merge branch 'main' into chore/local-ci
AndesKrrrrrrrrrrr Jan 16, 2025
cf0e1f6
localrun cleanup
AndesKrrrrrrrrrrr Jan 9, 2025
68cbf73
Only use github.event.localrun for local condition
AndesKrrrrrrrrrrr Jan 17, 2025
92eb5ae
Use if for permission, not continue-on-error (reviewfix)
AndesKrrrrrrrrrrr Jan 17, 2025
b57361f
Merge branch 'main' into chore/local-ci
AndesKrrrrrrrrrrr Jan 17, 2025
a3311ce
Don't run permission check locally
AndesKrrrrrrrrrrr Jan 20, 2025
cf6173d
Merge branch 'main' into chore/local-ci
AndesKrrrrrrrrrrr Jan 20, 2025
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
12 changes: 9 additions & 3 deletions .github/actions/get-cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ inputs:
github-token:
description: 'GitHub token'
required: true
cache-url:
description: 'Cache URL'
default: 'https://cache.dev01.devland.is/'
enable-cache:
description: 'Enable cache'
default: ''
Expand All @@ -18,12 +21,15 @@ runs:
using: 'composite'
steps:
- name: Adding required env vars
# Skip when running locally
if: ${{ !github.event.localrun }}
uses: actions/github-script@v7
env:
cache-url: ${{ inputs.cache-url }}
github-token: ${{ inputs.GITHUB_TOKEN }}
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', 'https://cache.dev01.devland.is/')
core.exportVariable('ACTIONS_CACHE_URL', process.env['cache-url'])
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env['ACTIONS_RUNTIME_TOKEN'])
core.exportVariable('ACTIONS_RUNTIME_URL', process.env['ACTIONS_RUNTIME_URL'])
- name: Get cache
Expand All @@ -35,8 +41,8 @@ runs:
NODE_OPTIONS: --max-old-space-size=8192
run: |
# This is because of a weird bug where Github would write as root to .cache
export COREPACK_HOME=/github/home/.corepack-cache
export CYPRESS_CACHE_FOLDER=/github/home/.cypress-cache
export COREPACK_HOME="$HOME/.corepack-cache"
export CYPRESS_CACHE_FOLDER="$HOME/.cypress-cache"
echo "COREPACK_HOME=$COREPACK_HOME" >> $GITHUB_ENV
echo "CYPRESS_CACHE_FOLDER=$CYPRESS_CACHE_FOLDER" >> $GITHUB_ENV
cd scripts/ci/cache
Expand Down
43 changes: 30 additions & 13 deletions .github/workflows/pullrequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,17 @@ jobs:
BUILD_CHUNKS: ${{ steps.build_projects.outputs.CHUNKS }}
CACHE_KEYS: ${{ steps.get-cache.outputs.keys }}
steps:
# Creates homedir if missing (e.g. when set to /tmp/runner/ when running locally with act)
- name: Debug home etc.
run: |
echo "User: HOME=$HOME, PWD=$PWD, id=$(id)"
mkdir -p "$HOME"
ls -lah "$HOME"

- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-node@v4
with:
node-version-file: 'package.json'
Expand All @@ -54,13 +62,17 @@ jobs:
run: |
set -euo pipefail
node -v
ls -l `which node`
yarn --version
ls -l "$(which node)"

- name: Checking out relevant branches
run: |
set -euo pipefail
git checkout "$GITHUB_HEAD_REF"
git checkout "$GITHUB_BASE_REF"
git checkout "$GITHUB_SHA"
set -x

git checkout -m "$GITHUB_HEAD_REF"
git checkout -m "$GITHUB_BASE_REF"
git checkout -m "$GITHUB_SHA"
AndesKrrrrrrrrrrr marked this conversation as resolved.
Show resolved Hide resolved
git config --global user.email "ci@island.is"
git config --global user.name "CI Bot"

Expand All @@ -74,6 +86,8 @@ jobs:
# https://github.blog/changelog/2020-10-08-github-actions-ability-to-change-retention-days-for-artifacts-and-logs/
- name: Keep PR run event
uses: actions/upload-artifact@b18b1d32f3f31abcdc29dee3f2484801fe7822f4
# Don't run this step locally
if: ${{ !github.event.localrun }}
with:
name: pr-event
path: event.json
Expand All @@ -88,7 +102,12 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
enable-cache: 'node_modules,cypress,generated-files'

- run: |
- name: Preparing HEAD and BASE tags
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HTML_URL: ${{ github.event.pull_request.html_url }}
ISSUE_REPORTING_SLACK_WEBHOOK_URL: ${{ secrets.SLACK_BUILD_ISSUES_REPORTING_WEBHOOK_URL }}
run: |
set -euo pipefail
echo "HEAD=$GITHUB_SHA" >> "$GITHUB_ENV"
export HEAD_REF="$GITHUB_HEAD_REF"
Expand All @@ -99,26 +118,23 @@ jobs:
source ./scripts/ci/00_prepare-base-tags.sh "$(git merge-base HEAD "$GITHUB_BASE_REF")"
git checkout "$GITHUB_SHA"
echo "BASE=$BASE" >> "$GITHUB_ENV"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HTML_URL: ${{ github.event.pull_request.html_url }}
ISSUE_REPORTING_SLACK_WEBHOOK_URL: ${{ secrets.SLACK_BUILD_ISSUES_REPORTING_WEBHOOK_URL }}
name: Preparing HEAD and BASE tags

- name: License audit Node modules
run: ./scripts/ci/20_license-audit.sh

- name: Check user permissions
uses: actions-cool/check-user-permission@v2
id: check-permission
# This fails locally without a token, and only prevents "admin" label usage
if: ${{ !github.event.localrun }}

- name: Set magic env if test-everything label is set
if: ${{ contains(github.event.pull_request.labels.*.name, 'test everything') && steps.check-permission.outputs['user-permission'] == 'admin' }}
if: ${{ contains(github.event.pull_request.labels.*.name, 'test everything') && steps.check-permission.outcome == 'success' && steps.check-permission.outputs['user-permission'] == 'admin' }}
run: |
echo "AFFECTED_ALL=7913-$GITHUB_HEAD_REF" >> "$GITHUB_ENV"

- name: Warn if user does not have the required permissions
if: ${{ contains(github.event.pull_request.labels.*.name, 'test everything') && steps.check-permission.outputs['user-permission'] != 'admin' }}
if: ${{ contains(github.event.pull_request.labels.*.name, 'test everything') && steps.check-permission.outcome == 'success'&& steps.check-permission.outputs['user-permission'] != 'admin' }}
run: |
echo "## WARN permissions" >> "$GITHUB_STEP_SUMMARY"
echo "User '$GITHUB_ACTOR' does not have the required permissions to apply the 'test everything' label" >> "$GITHUB_STEP_SUMMARY"
Expand Down Expand Up @@ -205,7 +221,8 @@ jobs:
keys: ${{ needs.prepare.outputs.CACHE_KEYS }}
enable-cache: 'node_modules,cypress,generated-files'

- uses: ./.github/actions/unit-test
- name: Run unit tests
uses: ./.github/actions/unit-test
with:
dd-api-key: '${{ secrets.DD_API_KEY }}'
codecov-token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
26 changes: 21 additions & 5 deletions scripts/ci/00_prepare-base-tags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,48 @@ set -euxo pipefail
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
ROOT="$DIR/../.."

# Copy the built action to a temp directory
tempRepo=$(mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir')
cp -r "$ROOT/.github/actions/dist/." "$tempRepo"

LAST_GOOD_BUILD=$(DEBUG="*,-simple-git" REPO_ROOT="$ROOT" node "$tempRepo/main.js")
# Get last good build via GitHub API, forcing full rebuild if it fails
if ! LAST_GOOD_BUILD=$(DEBUG="*,-simple-git" REPO_ROOT="$ROOT" node "$tempRepo/main.js"); then
>&2 echo "Stickman failed 😢, continuing with full rebuild"
LAST_GOOD_BUILD="full_rebuild_needed"
fi
>&2 echo "Stickman done"

# Check if the script failed or if a full rebuild is needed
if echo "$LAST_GOOD_BUILD" | grep -q 'full_rebuild_needed'; then
>&2 echo "No last good build found"
export NX_AFFECTED_ALL=true
echo "NX_AFFECTED_ALL=$NX_AFFECTED_ALL" >>"$GITHUB_ENV"
exit 0
fi
echo "Stickman done"

# Extract details from the last good build
LAST_GOOD_BUILD_SHA=$(echo "$LAST_GOOD_BUILD" | jq -r '.sha')
LAST_GOOD_BUILD_BRANCH=$(echo "$LAST_GOOD_BUILD" | jq -r '.branch')
LAST_GOOD_BUILD_RUN_NUMBER=$(echo "$LAST_GOOD_BUILD" | jq -r '.run_number')
BUILD_REF=$(echo "$LAST_GOOD_BUILD" | jq -r '.ref')
>&2 echo "Last successful build is with SHA '$LAST_GOOD_BUILD_SHA', branch '$LAST_GOOD_BUILD_BRANCH' and number '$LAST_GOOD_BUILD_RUN_NUMBER'"

# Log commits between the last good build and the current build
if [[ "$BUILD_REF" != "$LAST_GOOD_BUILD_SHA" ]]; then
echo "This will be an incremental build from a previous successful run in this PR. See parents of the commit below."
git log -1 "$BUILD_REF"
fi

# Generate a Docker tag based on the last good build details
LAST_GOOD_BUILD_DOCKER_BRANCH_TAG=$(echo "${LAST_GOOD_BUILD_BRANCH}" | tr "/." "-")
export LAST_GOOD_BUILD_DOCKER_TAG=${LAST_GOOD_BUILD_DOCKER_BRANCH_TAG:0:45}_${LAST_GOOD_BUILD_SHA:0:10}_${LAST_GOOD_BUILD_RUN_NUMBER}

# If the build reference is invalid, report an error to Slack
if [[ "$BUILD_REF" == "null" || "$BUILD_REF" == "" ]]; then
curl -X POST -H 'Content-type: application/json' --data "{\"text\":\"Change detection failed for $HTML_URL\"}" "$ISSUE_REPORTING_SLACK_WEBHOOK_URL"
exit 1
else
BASE="$BUILD_REF"
fi
export BASE
export BASE="$BUILD_REF"

# Log the Docker tag of the last successful build
>&2 echo "Last successful docker tag '$LAST_GOOD_BUILD_DOCKER_TAG'"
4 changes: 3 additions & 1 deletion scripts/ci/cache/__config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export const ENABLED_MODULES = (process.env[ENV_ENABLED_CACHE] || '')
return a
}, {})

export const cypressPath = '/github/home/.cypress-cache'
// Override default Cypress cache; the default (~/.cache) could be unwritable
export const cypressPath =
process.env.CYPRESS_CACHE_FOLDER || `${process.env.HOME}/.cypress-cache`
export const cacheSuccess = JSON.parse(process.env[ENV_CACHE_SUCCESS] ?? '{}')
export const initCache = process.env[ENV_INIT_CACHE] === 'true'

Expand Down
Loading