From 140992e1e0c5ff845aeaeecaf3c27dfb0584c7f5 Mon Sep 17 00:00:00 2001 From: Paul Happy Hutchinson Date: Wed, 9 Apr 2025 11:28:02 +0000 Subject: [PATCH 1/2] Improve local dev --- .devcontainer/devcontainer.json | 53 +++++------ .github/workflows/branch_build.yml | 138 +++++++++++------------------ .github/workflows/pr_build.yml | 97 ++++++++++---------- .vscode/launch.json | 14 +++ .vscode/tasks.json | 15 ++++ 5 files changed, 153 insertions(+), 164 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 3e53f27..17898af 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,26 +1,29 @@ { - "name": "App Container", - "image": "mcr.microsoft.com/devcontainers/javascript-node:latest", - "features": { - "ghcr.io/devcontainers/features/node:1": { - "version": "lts", - "pnpm": "latest" - } - }, - "customizations": { - "vscode": { - "settings": { - "terminal.integrated.defaultProfile.linux": "bash", - "editor.tabSize": 2 - }, - "extensions": [ - "dbaeumer.vscode-eslint" - ] - } - }, - "mounts": [ - "source=${localEnv:HOME}/.gitconfig,target=/home/node/.gitconfig,type=bind,consistency=cached", - "source=${localEnv:HOME}/.ssh,target=/home/node/.ssh,type=bind,consistency=cached" - ], - "postCreateCommand": "pnpm install" - } \ No newline at end of file + "name": "App Container", + "image": "mcr.microsoft.com/devcontainers/javascript-node:latest", + "features": { + "ghcr.io/devcontainers/features/node:1": { + "version": "lts", + "pnpm": "latest" + } + }, + "customizations": { + "vscode": { + "settings": { + "terminal.integrated.defaultProfile.linux": "bash", + "editor.tabSize": 2 + }, + "extensions": [ + "dbaeumer.vscode-eslint" + ] + } + }, + "mounts": [ + "source=${localEnv:HOME}/.gitconfig,target=/home/node/.gitconfig,type=bind,consistency=cached", + "source=${localEnv:HOME}/.ssh,target=/home/node/.ssh,type=bind,consistency=cached" + ], + "postCreateCommand": "pnpm install", + "containerEnv": { + "npm_config_store_dir": "/home/node/.local/share/pnpm/store" + } +} \ No newline at end of file diff --git a/.github/workflows/branch_build.yml b/.github/workflows/branch_build.yml index 8a8188d..e876b73 100644 --- a/.github/workflows/branch_build.yml +++ b/.github/workflows/branch_build.yml @@ -11,110 +11,73 @@ jobs: contents: write name: Test / Build timeout-minutes: 30 - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - run: git fetch --no-tags --depth=1 origin master - - uses: actions/setup-node@v4 - with: - node-version: "22" - - name: Clone repo uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: pnpm/action-setup@v4 - name: Install pnpm - id: pnpm-install - with: - version: 9 - run_install: false - - - name: Get pnpm store directory - id: pnpm-cache - shell: bash - run: | - echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT - - uses: actions/cache@v4 - name: Setup pnpm cache - with: - path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} - key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} - restore-keys: | - ${{ runner.os }}-pnpm-store- - - name: Install dependencies - run: pnpm install --frozen-lockfile --strict-peer-dependencies - - - name: Lint - run: pnpm run lint - - - name: Type check - run: pnpm tsc --noemit - - - name: Run tests - run: pnpm test:coverage - - - name: Get previous commit hash - run: | - PREV_COMMIT=$(git log -1 --pretty=format:%H -- manifest.json) - echo "Previous commit hash is $PREV_COMMIT" - id: get-commit-hash - - - name: Get version number - run: | - VERSION=$(git show ${{ steps.get-commit-hash.outputs.PREV_COMMIT }}:manifest.json | grep version | awk -F'"' '{print $4}') - echo "Version number is $VERSION" - id: get-version - - - name: Get version labels - id: labels - run: | - commit_sha=$(git rev-parse HEAD) - - pull_request_number=$(git log --format='%s' -n 1 | grep -oP '(?<=Merge pull request #)\d+' || true) - - milestone="" - - if [[ -n "$pull_request_number" ]]; then - pull_request_info=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ - "https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls/${pull_request_number}") - - milestone=$(echo "$pull_request_info" | jq -r '.labels[].name' | grep -E 'major-version|minor-version' | head -1) - fi - - echo "milestone=${milestone}" >> $GITHUB_OUTPUT - - - name: Bump Version + - name: Prep local dev run: | - git config --global user.name "git log -1 --pretty=format:%an" + touch ~/.gitconfig + mkdir ~/.ssh + git config --global user.name "$(git log -1 --pretty=format:%an)" git config --global user.email "$(git log -1 --pretty=format:%ae)" - if [ "$(git log -1 --pretty=format:%ae)" = "noreply@github.com" ]; then - echo "Skipping workflow run because previous commit was not made by workflow." - exit 0 - fi - - if [[ "${{ steps.labels.outputs.milestone }}" == "major-version" ]]; then - pnpm run bumpManifestVer major ${{ steps.get-version.outputs.VERSION }} - elif [[ "${{ steps.labels.outputs.milestone }}" == "minor-version" ]]; then - pnpm run bumpManifestVer minor ${{ steps.get-version.outputs.VERSION }} - else - pnpm run bumpManifestVer patch ${{ steps.get-version.outputs.VERSION }} - fi - - pnpm prettier --write manifest.json + - name: Export PR Labels + id: extract_labels + run: echo "labels=$(jq -r '[.[] | .name] | join(",")' <<< '${{ toJson(github.event.pull_request.labels) }}')" >> $GITHUB_OUTPUT + - name: Lint, Test, Build, and Tag + uses: devcontainers/ci@v0.3 + env: + LABELS: "${{ steps.extract_labels.outputs.labels }}" + with: + env: LABELS + runCmd: | + # Lint + pnpm run lint + pnpm tsc --noemit + + # Test + pnpm test:coverage + + # Build + pnpm run build + + # Tag + if [ "$(git log -1 --pretty=format:%ae)" = "noreply@github.com" ]; then + echo "Skipping workflow run because previous commit was made by workflow." + exit 0 + fi + + ## Get current version number + PREV_COMMIT=$(git log -1 --pretty=format:%H -- manifest.json) + VERSION=$(git show $PREV_COMMIT:manifest.json | grep version | head -n 1 | awk -F'"' '{print $4}') + ## Get the commit message + MILESTONE=$(echo "$LABELS" | grep -E 'major-version|minor-version' | head -1) + + echo "Current Version is $VERSION and the milestone is $MILESTONE" + if [[ "$MILESTONE" == "major-version" ]]; then + pnpm run bumpManifestVer major $VERSION + elif [[ "$MILESTONE" == "minor-version" ]]; then + pnpm run bumpManifestVer minor $VERSION + else + pnpm run bumpManifestVer patch $VERSION + fi + + pnpm prettier --write manifest.json + + - name: Update the Manifest in git + run: | git add manifest.json - git commit -m "Updated Manifest" - git push origin master - - name: Build - run: pnpm run build - - name: Package app zip working-directory: dist run: | @@ -154,4 +117,3 @@ jobs: uses: DeskproApps/app-template-vite/.github/workflows/subworkflow-release.yml@master secrets: inherit needs: [deskpro_app_test_and_build] - diff --git a/.github/workflows/pr_build.yml b/.github/workflows/pr_build.yml index 85c3357..1e6d2c6 100644 --- a/.github/workflows/pr_build.yml +++ b/.github/workflows/pr_build.yml @@ -9,73 +9,68 @@ jobs: deskpro_app_test_and_build: name: Test / Build timeout-minutes: 30 - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - run: git fetch --no-tags --depth=1 origin master - - uses: actions/setup-node@v4 - with: - node-version: "22" - - name: Clone repo uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: pnpm/action-setup@v4 - name: Install pnpm - id: pnpm-install - with: - version: 9 - run_install: false - - - name: Get pnpm store directory - id: pnpm-cache - shell: bash + - name: Prep local dev run: | - echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT - - uses: actions/cache@v4 - name: Setup pnpm cache + touch ~/.gitconfig + mkdir ~/.ssh + git config --global user.name "$(git log -1 --pretty=format:%an)" + git config --global user.email "$(git log -1 --pretty=format:%ae)" + + - name: Export PR Labels + id: extract_labels + run: echo "labels=$(jq -r '[.[] | .name] | join(",")' <<< '${{ toJson(github.event.pull_request.labels) }}')" >> $GITHUB_OUTPUT + + - name: Lint, Test, Build, and Tag + uses: devcontainers/ci@v0.3 + env: + LABELS: "${{ steps.extract_labels.outputs.labels }}" with: - path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} - key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} - restore-keys: | - ${{ runner.os }}-pnpm-store- - - name: Install dependencies - run: pnpm install --frozen-lockfile --strict-peer-dependencies + env: LABELS + runCmd: | + # Lint + pnpm run lint + pnpm tsc --noemit - - name: Lint - run: pnpm run lint + # Test + pnpm test:coverage - - name: Type check - run: pnpm tsc --noemit + # Build + pnpm run build - - name: Run tests - run: pnpm test:coverage + # Tag + if [ "$(git log -1 --pretty=format:%ae)" = "noreply@github.com" ]; then + echo "Skipping workflow run because previous commit was made by workflow." + exit 0 + fi - - name: Get labels from pull request - id: labels - run: echo "milestone=$(jq --raw-output '.pull_request.labels[].name' $GITHUB_EVENT_PATH | grep -E 'major-version|minor-version' | head -1)" >> $GITHUB_OUTPUT + ## Get current version number + PREV_COMMIT=$(git log -1 --pretty=format:%H -- manifest.json) + VERSION=$(git show $PREV_COMMIT:manifest.json | grep version | head -n 1 | awk -F'"' '{print $4}') - - name: Bump Version - run: | - git config --global user.name "git log -1 --pretty=format:%an" - git config --global user.email "$(git log -1 --pretty=format:%ae)" - if [ "$(git log -1 --pretty=format:%ae)" = "noreply@github.com" ]; then - echo "Skipping workflow run because previous commit was not made by workflow." - exit 0 - fi - if [[ "${{ steps.labels.outputs.milestone }}" == "major-version" ]]; then - pnpm run bumpManifestVer major - elif [[ "${{ steps.labels.outputs.milestone }}" == "minor-version" ]]; then - pnpm run bumpManifestVer minor - else - pnpm run bumpManifestVer - fi + ## Get the commit message + MILESTONE=$(echo "$LABELS" | grep -E 'major-version|minor-version' | head -1) + + echo "Current Version is $VERSION and the milestone is $MILESTONE" + if [[ "$MILESTONE" == "major-version" ]]; then + pnpm run bumpManifestVer major $VERSION + elif [[ "$MILESTONE" == "minor-version" ]]; then + pnpm run bumpManifestVer minor $VERSION + else + pnpm run bumpManifestVer patch $VERSION + fi + + pnpm prettier --write manifest.json - - name: Build - run: pnpm run build - name: Package app zip working-directory: dist run: | @@ -88,7 +83,7 @@ jobs: path: | dist/app.zip dist/manifest.json - retention-days: 1 + retention-days: 7 deploy: uses: DeskproApps/app-template-vite/.github/workflows/subworkflow-deploy.yml@master diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..de9abe3 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Server", + "runtimeExecutable": "pnpm", + "runtimeArgs": ["start"], + "skipFiles": ["/**"], + "console": "integratedTerminal" + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..d9d647a --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,15 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "shell", + "command": "pnpm build:package", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [], + "label": "pnpm: build:package" + } + ] +} \ No newline at end of file From 1409923519d1c58ee637fc42c31859f642f543e3 Mon Sep 17 00:00:00 2001 From: Paul Happy Hutchinson Date: Wed, 9 Apr 2025 14:59:09 +0100 Subject: [PATCH 2/2] Improve local dev --- .github/workflows/branch_build.yml | 2 ++ .github/workflows/pr_build.yml | 2 ++ .vscode/tasks.json | 14 ++++++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.github/workflows/branch_build.yml b/.github/workflows/branch_build.yml index e876b73..8ef7d4b 100644 --- a/.github/workflows/branch_build.yml +++ b/.github/workflows/branch_build.yml @@ -39,6 +39,8 @@ jobs: with: env: LABELS runCmd: | + set -e + # Lint pnpm run lint pnpm tsc --noemit diff --git a/.github/workflows/pr_build.yml b/.github/workflows/pr_build.yml index 1e6d2c6..4d723c8 100644 --- a/.github/workflows/pr_build.yml +++ b/.github/workflows/pr_build.yml @@ -37,6 +37,8 @@ jobs: with: env: LABELS runCmd: | + set -e + # Lint pnpm run lint pnpm tsc --noemit diff --git a/.vscode/tasks.json b/.vscode/tasks.json index d9d647a..e062e99 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,6 +1,6 @@ { - "version": "2.0.0", - "tasks": [ + "version": "2.0.0", + "tasks": [ { "type": "shell", "command": "pnpm build:package", @@ -10,6 +10,16 @@ }, "problemMatcher": [], "label": "pnpm: build:package" + }, + { + "type": "shell", + "command": "pnpm test", + "group": { + "kind": "test", + "isDefault": true + }, + "problemMatcher": [], + "label": "pnpm: test" } ] } \ No newline at end of file