From ff17e524b60799299cd4965703b15d52e6f7fc81 Mon Sep 17 00:00:00 2001 From: Hiroyuki Okada Date: Sun, 18 Aug 2024 18:07:06 +0900 Subject: [PATCH] refactor: update devcontainer (#129) * refactor: update devcontainer * fix: shellcheck error * ci: add timeout --- .devcontainer/Dockerfile | 7 ++-- .devcontainer/commands/post-attach.sh | 8 ++-- .devcontainer/devcontainer.json | 6 +-- .github/workflows/nodejs.yml | 31 +++++++------- .github/workflows/npm-publish.yml | 42 +++++++++---------- .github/workflows/pre-commit.yml | 15 ++++--- dprint.json | 2 +- install/sample-project/copy-sample-project.sh | 2 +- 8 files changed, 59 insertions(+), 54 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 44789a95..44dee33a 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -3,11 +3,10 @@ FROM koalaman/shellcheck:v0.10.0 AS shellcheck FROM mcr.microsoft.com/devcontainers/typescript-node:1-18 +COPY --from=dockerfile-lint /bin/hadolint /usr/bin/hadolint +COPY --from=shellcheck /bin/shellcheck /usr/bin/ + # hadolint ignore=DL3008 RUN apt-get update && apt-get install -y --no-install-recommends \ pre-commit \ && apt-get clean && rm -rf /var/lib/apt/lists/* - -COPY --from=dockerfile-lint /bin/hadolint /usr/bin/hadolint - -COPY --from=shellcheck /bin/shellcheck /usr/bin/ diff --git a/.devcontainer/commands/post-attach.sh b/.devcontainer/commands/post-attach.sh index ffa6437c..d65070d0 100644 --- a/.devcontainer/commands/post-attach.sh +++ b/.devcontainer/commands/post-attach.sh @@ -1,11 +1,11 @@ #!/bin/bash -if [ ! \( -f .git/hooks/pre-commit \) ]; then - pre-commit install -fi - sudo chown "$USER" .pre-commit-cache sudo chown "$USER" .npm sudo chown "$USER" node_modules +if [ ! \( -f .git/hooks/pre-commit \) ]; then + pre-commit install +fi + npm ci diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 1d4820ac..fe67ebab 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -7,10 +7,10 @@ "ghcr.io/devcontainers/features/java:1": { "version": "17", "installGradle": true + }, + "ghcr.io/akhildevelops/devcontainer-features/android-cli:0.0.2": { + "PACKAGES": "platform-tools,platforms;android-34,build-tools;34.0.0,ndk-bundle,ndk;24.0.8215888,cmake;3.22.1" } - // "ghcr.io/akhildevelops/devcontainer-features/android-cli:0": { - // "PACKAGES": "platform-tools,platforms;android-33,build-tools;33.0.2,ndk-bundle,ndk;24.0.8215888,cmake;3.22.1" - // } }, "mounts": [ "source=node_modules_${devcontainerId},target=${containerWorkspaceFolder}/node_modules,type=volume", diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 55f738b8..e17a44b5 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -12,29 +12,33 @@ env: jobs: test: runs-on: ubuntu-latest + timeout-minutes: 1 steps: - - name: Clone repo - uses: actions/checkout@v4 - - name: Use Node.js - uses: actions/setup-node@v4 + - uses: actions/checkout@v4 with: - node-version: "18" + fetch-depth: 0 + - uses: actions/checkout@v4 + with: + repository: okhiroyuki/composite-actions + path: ./.github/actions/composite-actions + - uses: ./.github/actions/composite-actions/setup-node - name: npm test - run: | - npm ci - npm test --if-present + run: npm test --if-present env: CI: true build: runs-on: ubuntu-latest + timeout-minutes: 5 needs: test steps: - - name: Clone repo - uses: actions/checkout@v4 - - name: Use Node.js - uses: actions/setup-node@v4 + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: actions/checkout@v4 with: - node-version: "18" + repository: okhiroyuki/composite-actions + path: ./.github/actions/composite-actions + - uses: ./.github/actions/composite-actions/setup-node - name: set up JDK uses: actions/setup-java@v4 with: @@ -42,7 +46,6 @@ jobs: java-version: ${{env.JAVA_VERSION}} - name: npm run build run: | - npm ci npm run build --if-present env: CI: true diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 3759258d..831b4da7 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -1,34 +1,32 @@ --- name: npm publish -"on": +# yamllint disable-line rule:truthy +on: workflow_run: - workflows: [Node.js] - branches: [main] - types: [completed] + workflows: + - Node.js + branches: + - main + types: + - completed jobs: publish: - runs-on: ubuntu-latest if: ${{ github.event.workflow_run.conclusion == 'success' }} + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + contents: write steps: - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version: "20" - - uses: JS-DevTools/npm-publish@v3 - id: publish + - uses: actions/checkout@v4 with: - token: ${{ secrets.NPM_TOKEN }} - - name: Create Release - if: ${{ steps.publish.outputs.type }} - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + repository: okhiroyuki/composite-actions + path: ./.github/actions/composite-actions + - uses: ./.github/actions/composite-actions/setup-node + - name: build + run: npm run build + - uses: ./.github/actions/composite-actions/npm-publish with: - tag_name: ${{ steps.publish.outputs.version }} - release_name: Release ${{ steps.publish.outputs.version }} - body: ${{ steps.publish.outputs.version }} - draft: false - prerelease: false + npm-token: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 937abb45..2fad972d 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -1,17 +1,22 @@ --- name: pre-commit -"on": +# yamllint disable-line rule:truthy +on: pull_request: push: - branches: [main] + branches: + - main jobs: pre-commit: runs-on: ubuntu-latest + timeout-minutes: 5 steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 with: - python-version: "3.12" - - uses: pre-commit/action@v3.0.1 + repository: okhiroyuki/composite-actions + path: ./.github/actions/composite-actions + - uses: ./.github/actions/composite-actions/setup-node + - uses: ./.github/actions/composite-actions/pre-commit diff --git a/dprint.json b/dprint.json index 4fbaf489..3a398973 100644 --- a/dprint.json +++ b/dprint.json @@ -8,7 +8,7 @@ "lineEnding": "lf" }, "yaml": {}, - "excludes": ["**/*-lock.json", "**/node_modules"], + "excludes": ["**/*-lock.json"], "plugins": [ "https://plugins.dprint.dev/markdown-0.17.4.wasm", "https://plugins.dprint.dev/toml-0.6.2.wasm", diff --git a/install/sample-project/copy-sample-project.sh b/install/sample-project/copy-sample-project.sh index 2e447932..1118c6ed 100755 --- a/install/sample-project/copy-sample-project.sh +++ b/install/sample-project/copy-sample-project.sh @@ -2,7 +2,7 @@ SRC_PATH="plugins/@red-mobile/nodejs-mobile-cordova/install/sample-project" copySampleFile () { - cp -i "$SRC_PATH/$1" $1 + cp -i "$SRC_PATH/$1" "$1" } mkdir -p "www/nodejs-project"