From 33076330d1ddfc92326f952e843133dc63a89cef Mon Sep 17 00:00:00 2001 From: Leszek Grzanka Date: Wed, 31 May 2023 09:53:18 +0000 Subject: [PATCH 01/10] test conditional tests --- .github/workflows/node.js.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index f5d540a3f..962ca2876 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -5,6 +5,8 @@ on: branches: [master] pull_request: branches: [master] + issue_comment: + types: [created] # see https://github.community/t/treating-warnings-as-errors-because-process-env-ci-true/18032 env: @@ -47,9 +49,8 @@ jobs: command: npm test deploy-to-github-registry: - # needs: build_and_test - # this is a lengthy process, lets run it in parallel to build_and_test runs-on: ubuntu-latest + if: ${{ github.event.issue.pull_request }} env: USERNAME: ${{ github.actor }} PASSWORD: ${{ secrets.GITHUB_TOKEN }} From a8a41011a1eb9ad53278044952289c103f52b685 Mon Sep 17 00:00:00 2001 From: Leszek Grzanka Date: Wed, 31 May 2023 09:55:28 +0000 Subject: [PATCH 02/10] faster --- .github/workflows/node.js.yml | 44 +++++++++++++++++------------------ 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 962ca2876..ebe9d5d8a 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -25,28 +25,28 @@ jobs: - uses: actions/checkout@v3 with: submodules: recursive - - uses: actions/setup-python@v4 - with: - python-version: '3.10' - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - cache: 'npm' - - run: npm ci - - run: npm run build --if-present - - run: npm run start & - - name: Wait for the app to start - uses: iFaxity/wait-on-action@v1.1.0 - with: - resource: http://localhost:3000 - - name: Run tests - uses: nick-fields/retry@v2 - with: - max_attempts: 2 - retry_on: error - timeout_seconds: 120 - command: npm test + # - uses: actions/setup-python@v4 + # with: + # python-version: '3.10' + # - name: Use Node.js ${{ matrix.node-version }} + # uses: actions/setup-node@v3 + # with: + # node-version: ${{ matrix.node-version }} + # cache: 'npm' + # - run: npm ci + # - run: npm run build --if-present + # - run: npm run start & + # - name: Wait for the app to start + # uses: iFaxity/wait-on-action@v1.1.0 + # with: + # resource: http://localhost:3000 + # - name: Run tests + # uses: nick-fields/retry@v2 + # with: + # max_attempts: 2 + # retry_on: error + # timeout_seconds: 120 + # command: npm test deploy-to-github-registry: runs-on: ubuntu-latest From 9ea8122e7a2c2cd48c3f8813602ae8f14b3f80a1 Mon Sep 17 00:00:00 2001 From: Leszek Grzanka Date: Wed, 31 May 2023 09:57:43 +0000 Subject: [PATCH 03/10] test --- .github/workflows/node.js.yml | 57 ++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index ebe9d5d8a..f6a196a6b 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -61,36 +61,39 @@ jobs: uses: actions/checkout@v2 with: submodules: true - - - name: Login to GitHub Container Registry - uses: docker/login-action@v1 - with: - registry: ${{ env.REGISTRY }} - username: ${{ env.USERNAME }} - password: ${{ env.PASSWORD }} - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + - name: Deploy + run: | + echo "Deploying..." + # - name: Login to GitHub Container Registry + # uses: docker/login-action@v1 + # with: + # registry: ${{ env.REGISTRY }} + # username: ${{ env.USERNAME }} + # password: ${{ env.PASSWORD }} + + # - name: Set up Docker Buildx + # uses: docker/setup-buildx-action@v2 - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v4.4.0 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + # - name: Extract metadata (tags, labels) for Docker + # id: meta + # uses: docker/metadata-action@v4.4.0 + # with: + # images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - # see https://github.com/docker/build-push-action/issues/513#issuecomment-987951050 - - name: Build and push Docker image - uses: docker/build-push-action@v2 - with: - context: . - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - # it seems that cache is not giving any benefit in speed, lets keep it disabled for now - # cache-from: type=gha - # cache-to: type=gha,mode=max - build-args: | - BUILDKIT_CONTEXT_KEEP_GIT_DIR=true + # # see https://github.com/docker/build-push-action/issues/513#issuecomment-987951050 + # - name: Build and push Docker image + # uses: docker/build-push-action@v2 + # with: + # context: . + # push: true + # tags: ${{ steps.meta.outputs.tags }} + # labels: ${{ steps.meta.outputs.labels }} + # # it seems that cache is not giving any benefit in speed, lets keep it disabled for now + # # cache-from: type=gha + # # cache-to: type=gha,mode=max + # build-args: | + # BUILDKIT_CONTEXT_KEEP_GIT_DIR=true deploy_gh_pages: runs-on: ubuntu-latest From b31dc0fbde7ffc36e3c9330e3056a1bc9e3b4ee2 Mon Sep 17 00:00:00 2001 From: Leszek Grzanka Date: Wed, 31 May 2023 10:01:18 +0000 Subject: [PATCH 04/10] test --- .github/workflows/node.js.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index f6a196a6b..dd3344ade 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -57,11 +57,15 @@ jobs: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }}-web steps: - - name: Checkout - uses: actions/checkout@v2 + - name: Get PR branch + uses: xt0rted/pull-request-comment-branch@v1 + id: comment-branch + + - name: Checkout PR branch + uses: actions/checkout@v3 with: - submodules: true - + ref: ${{ steps.comment-branch.outputs.head_ref }} + - name: Deploy run: | echo "Deploying..." From 9ac27a82fa8fe83bac2ab2c5043843a56b73b450 Mon Sep 17 00:00:00 2001 From: Leszek Grzanka Date: Wed, 31 May 2023 10:04:02 +0000 Subject: [PATCH 05/10] test --- .github/workflows/node.js.yml | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index dd3344ade..7f5f51a72 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -60,15 +60,35 @@ jobs: - name: Get PR branch uses: xt0rted/pull-request-comment-branch@v1 id: comment-branch + + - name: Set latest commit status as pending + uses: myrotvorets/set-commit-status-action@master + with: + sha: ${{ steps.comment-branch.outputs.head_sha }} + token: ${{ secrets.GITHUB_TOKEN }} + status: pending - name: Checkout PR branch uses: actions/checkout@v3 with: ref: ${{ steps.comment-branch.outputs.head_ref }} - + + - name: Setup Node.js 16 + uses: actions/setup-node@v3 + with: + node-version: 16 + - name: Deploy run: | - echo "Deploying..." + echo "Deploying..." + + - name: Set latest commit status as ${{ job.status }} + uses: myrotvorets/set-commit-status-action@master + if: always() + with: + sha: ${{ steps.comment-branch.outputs.head_sha }} + token: ${{ secrets.GITHUB_TOKEN }} + status: ${{ job.status }} # - name: Login to GitHub Container Registry # uses: docker/login-action@v1 # with: From 0093a6e9b27c6ca60ca052281e7e305a06e1b25e Mon Sep 17 00:00:00 2001 From: Leszek Grzanka Date: Wed, 31 May 2023 10:06:14 +0000 Subject: [PATCH 06/10] a --- .github/workflows/node.js.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 7f5f51a72..c8812b548 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -89,6 +89,23 @@ jobs: sha: ${{ steps.comment-branch.outputs.head_sha }} token: ${{ secrets.GITHUB_TOKEN }} status: ${{ job.status }} + + - name: Add comment to PR + uses: actions/github-script@v6 + if: always() + with: + script: | + const name = '${{ github.workflow }}'; + const url = '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}'; + const success = '${{ job.status }}' === 'success'; + const body = `${name}: ${success ? 'succeeded ✅' : 'failed ❌'}\n${url}`; + + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: body + }) # - name: Login to GitHub Container Registry # uses: docker/login-action@v1 # with: From 6b0940a613f5032a62687581e7a76e0a0ffcf83a Mon Sep 17 00:00:00 2001 From: Leszek Grzanka Date: Wed, 31 May 2023 10:07:38 +0000 Subject: [PATCH 07/10] new --- .github/workflows/node.js.yml | 214 +++++++++------------------------- 1 file changed, 54 insertions(+), 160 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index c8812b548..c25171895 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -1,172 +1,66 @@ -name: Node.js CI +name: "Deploy on Comment" +# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows on: - push: - branches: [master] - pull_request: - branches: [master] - issue_comment: - types: [created] - -# see https://github.community/t/treating-warnings-as-errors-because-process-env-ci-true/18032 -env: - CI: false + issue_comment: + types: [created] jobs: - build_and_test: - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [18.x] - # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ - - steps: - - uses: actions/checkout@v3 - with: - submodules: recursive - # - uses: actions/setup-python@v4 - # with: - # python-version: '3.10' - # - name: Use Node.js ${{ matrix.node-version }} - # uses: actions/setup-node@v3 - # with: - # node-version: ${{ matrix.node-version }} - # cache: 'npm' - # - run: npm ci - # - run: npm run build --if-present - # - run: npm run start & - # - name: Wait for the app to start - # uses: iFaxity/wait-on-action@v1.1.0 - # with: - # resource: http://localhost:3000 - # - name: Run tests - # uses: nick-fields/retry@v2 - # with: - # max_attempts: 2 - # retry_on: error - # timeout_seconds: 120 - # command: npm test - - deploy-to-github-registry: - runs-on: ubuntu-latest - if: ${{ github.event.issue.pull_request }} - env: - USERNAME: ${{ github.actor }} - PASSWORD: ${{ secrets.GITHUB_TOKEN }} - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }}-web - steps: - - name: Get PR branch - uses: xt0rted/pull-request-comment-branch@v1 - id: comment-branch - - - name: Set latest commit status as pending - uses: myrotvorets/set-commit-status-action@master - with: - sha: ${{ steps.comment-branch.outputs.head_sha }} - token: ${{ secrets.GITHUB_TOKEN }} - status: pending + deploy: + name: Deploy + # Only run if it#s a PR and the comment contains /deploy + if: github.event.issue.pull_request && contains(github.event.comment.body, '/deploy') + runs-on: ubuntu-latest - - name: Checkout PR branch - uses: actions/checkout@v3 - with: - ref: ${{ steps.comment-branch.outputs.head_ref }} - - - name: Setup Node.js 16 - uses: actions/setup-node@v3 - with: - node-version: 16 - - - name: Deploy - run: | - echo "Deploying..." - - - name: Set latest commit status as ${{ job.status }} - uses: myrotvorets/set-commit-status-action@master - if: always() - with: - sha: ${{ steps.comment-branch.outputs.head_sha }} - token: ${{ secrets.GITHUB_TOKEN }} - status: ${{ job.status }} + steps: + - name: Get branch of PR + uses: xt0rted/pull-request-comment-branch@v1 + id: comment-branch - - name: Add comment to PR - uses: actions/github-script@v6 - if: always() - with: - script: | - const name = '${{ github.workflow }}'; - const url = '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}'; - const success = '${{ job.status }}' === 'success'; - const body = `${name}: ${success ? 'succeeded ✅' : 'failed ❌'}\n${url}`; - - await github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: body - }) - # - name: Login to GitHub Container Registry - # uses: docker/login-action@v1 - # with: - # registry: ${{ env.REGISTRY }} - # username: ${{ env.USERNAME }} - # password: ${{ env.PASSWORD }} - - # - name: Set up Docker Buildx - # uses: docker/setup-buildx-action@v2 - - # - name: Extract metadata (tags, labels) for Docker - # id: meta - # uses: docker/metadata-action@v4.4.0 - # with: - # images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - - # # see https://github.com/docker/build-push-action/issues/513#issuecomment-987951050 - # - name: Build and push Docker image - # uses: docker/build-push-action@v2 - # with: - # context: . - # push: true - # tags: ${{ steps.meta.outputs.tags }} - # labels: ${{ steps.meta.outputs.labels }} - # # it seems that cache is not giving any benefit in speed, lets keep it disabled for now - # # cache-from: type=gha - # # cache-to: type=gha,mode=max - # build-args: | - # BUILDKIT_CONTEXT_KEEP_GIT_DIR=true + - name: Set latest commit status as pending + uses: myrotvorets/set-commit-status-action@master + with: + sha: ${{ steps.comment-branch.outputs.head_sha }} + token: ${{ secrets.GITHUB_TOKEN }} + status: pending - deploy_gh_pages: - runs-on: ubuntu-latest - needs: [build_and_test] - if: github.ref == 'refs/heads/master' + - name: Checkout PR branch ${{ steps.comment-branch.outputs.head_ref }} + uses: actions/checkout@v3 + with: + ref: ${{ steps.comment-branch.outputs.head_ref }} - steps: - - name: Checkout 🛎️ - uses: actions/checkout@v3 - with: - submodules: recursive - - - uses: actions/setup-python@v4 - with: - python-version: '3.10' + - name: Setup Node.js 16 + uses: actions/setup-node@v3 + with: + node-version: 16 - - name: Install 🔧 - run: npm install + # Do the actual deployment (exit randomly with 0 or 1) + - name: Deploy + run: | + echo "Deploying..." + exit $(($RANDOM%2)) - - name: Use Node.js 18.x - uses: actions/setup-node@v3 - with: - node-version: '18.x' - cache: 'npm' + - name: Add workflow result as comment on PR + uses: actions/github-script@v6 + if: always() + with: + script: | + const name = '${{ github.workflow }}'; + const url = '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}'; + const success = '${{ job.status }}' === 'success'; + const body = `${name}: ${success ? 'succeeded ✅' : 'failed ❌'}\n${url}`; - - name: webfactory/ssh-agent 🖥️ - uses: webfactory/ssh-agent@v0.8.0 - with: - # Private SSH key to register in the SSH agent - ssh-private-key: ${{ secrets.WEBDEV }} + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: body + }) - - name: Deploy 🚀 - run: | - git remote set-url origin git@github.com:yaptide/web_dev.git - npm run deploy -- -u "github-actions-bot " -r "git@github.com:yaptide/web_dev.git" + - name: Set latest commit status as ${{ job.status }} + uses: myrotvorets/set-commit-status-action@master + if: always() + with: + sha: ${{ steps.comment-branch.outputs.head_sha }} + token: ${{ secrets.GITHUB_TOKEN }} + status: ${{ job.status }} \ No newline at end of file From 49cfa57f4b36f7bb7c435320ed94b51150d235a1 Mon Sep 17 00:00:00 2001 From: Leszek Grzanka Date: Wed, 31 May 2023 13:26:23 +0000 Subject: [PATCH 08/10] reverting --- .github/workflows/manual.yml | 127 +++++++++++++++++++++++++ .github/workflows/node.js.yml | 169 +++++++++++++++++++++++----------- 2 files changed, 242 insertions(+), 54 deletions(-) create mode 100644 .github/workflows/manual.yml diff --git a/.github/workflows/manual.yml b/.github/workflows/manual.yml new file mode 100644 index 000000000..3eeca6e1f --- /dev/null +++ b/.github/workflows/manual.yml @@ -0,0 +1,127 @@ +name: Node.js CI + +on: + push: + branches: [master] + pull_request: + branches: [master] + +# see https://github.community/t/treating-warnings-as-errors-because-process-env-ci-true/18032 +env: + CI: false + +jobs: + build_and_test: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [18.x] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + - run: npm ci + - run: npm run build --if-present + - run: npm run start & + - name: Wait for the app to start + uses: iFaxity/wait-on-action@v1.1.0 + with: + resource: http://localhost:3000 + - name: Run tests + uses: nick-fields/retry@v2 + with: + max_attempts: 2 + retry_on: error + timeout_seconds: 120 + command: npm test + + deploy-to-github-registry: + # needs: build_and_test + # this is a lengthy process, lets run it in parallel to build_and_test + runs-on: ubuntu-latest + env: + USERNAME: ${{ github.actor }} + PASSWORD: ${{ secrets.GITHUB_TOKEN }} + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }}-web + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + submodules: true + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ env.USERNAME }} + password: ${{ env.PASSWORD }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4.4.0 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + # see https://github.com/docker/build-push-action/issues/513#issuecomment-987951050 + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + # it seems that cache is not giving any benefit in speed, lets keep it disabled for now + # cache-from: type=gha + # cache-to: type=gha,mode=max + build-args: | + BUILDKIT_CONTEXT_KEEP_GIT_DIR=true + + deploy_gh_pages: + runs-on: ubuntu-latest + needs: [build_and_test] + if: github.ref == 'refs/heads/master' + + steps: + - name: Checkout 🛎️ + uses: actions/checkout@v3 + with: + submodules: recursive + + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + + - name: Install 🔧 + run: npm install + + - name: Use Node.js 18.x + uses: actions/setup-node@v3 + with: + node-version: '18.x' + cache: 'npm' + + - name: webfactory/ssh-agent 🖥️ + uses: webfactory/ssh-agent@v0.8.0 + with: + # Private SSH key to register in the SSH agent + ssh-private-key: ${{ secrets.WEBDEV }} + + - name: Deploy 🚀 + run: | + git remote set-url origin git@github.com:yaptide/web_dev.git + npm run deploy -- -u "github-actions-bot " -r "git@github.com:yaptide/web_dev.git" \ No newline at end of file diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index c25171895..3eeca6e1f 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -1,66 +1,127 @@ -name: "Deploy on Comment" +name: Node.js CI -# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows on: - issue_comment: - types: [created] + push: + branches: [master] + pull_request: + branches: [master] + +# see https://github.community/t/treating-warnings-as-errors-because-process-env-ci-true/18032 +env: + CI: false jobs: - deploy: - name: Deploy - # Only run if it#s a PR and the comment contains /deploy - if: github.event.issue.pull_request && contains(github.event.comment.body, '/deploy') - runs-on: ubuntu-latest + build_and_test: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [18.x] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ - steps: - - name: Get branch of PR - uses: xt0rted/pull-request-comment-branch@v1 - id: comment-branch + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + - run: npm ci + - run: npm run build --if-present + - run: npm run start & + - name: Wait for the app to start + uses: iFaxity/wait-on-action@v1.1.0 + with: + resource: http://localhost:3000 + - name: Run tests + uses: nick-fields/retry@v2 + with: + max_attempts: 2 + retry_on: error + timeout_seconds: 120 + command: npm test - - name: Set latest commit status as pending - uses: myrotvorets/set-commit-status-action@master - with: - sha: ${{ steps.comment-branch.outputs.head_sha }} - token: ${{ secrets.GITHUB_TOKEN }} - status: pending + deploy-to-github-registry: + # needs: build_and_test + # this is a lengthy process, lets run it in parallel to build_and_test + runs-on: ubuntu-latest + env: + USERNAME: ${{ github.actor }} + PASSWORD: ${{ secrets.GITHUB_TOKEN }} + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }}-web + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + submodules: true + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ env.USERNAME }} + password: ${{ env.PASSWORD }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4.4.0 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + # see https://github.com/docker/build-push-action/issues/513#issuecomment-987951050 + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + # it seems that cache is not giving any benefit in speed, lets keep it disabled for now + # cache-from: type=gha + # cache-to: type=gha,mode=max + build-args: | + BUILDKIT_CONTEXT_KEEP_GIT_DIR=true - - name: Checkout PR branch ${{ steps.comment-branch.outputs.head_ref }} - uses: actions/checkout@v3 - with: - ref: ${{ steps.comment-branch.outputs.head_ref }} + deploy_gh_pages: + runs-on: ubuntu-latest + needs: [build_and_test] + if: github.ref == 'refs/heads/master' - - name: Setup Node.js 16 - uses: actions/setup-node@v3 - with: - node-version: 16 + steps: + - name: Checkout 🛎️ + uses: actions/checkout@v3 + with: + submodules: recursive + + - uses: actions/setup-python@v4 + with: + python-version: '3.10' - # Do the actual deployment (exit randomly with 0 or 1) - - name: Deploy - run: | - echo "Deploying..." - exit $(($RANDOM%2)) + - name: Install 🔧 + run: npm install - - name: Add workflow result as comment on PR - uses: actions/github-script@v6 - if: always() - with: - script: | - const name = '${{ github.workflow }}'; - const url = '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}'; - const success = '${{ job.status }}' === 'success'; - const body = `${name}: ${success ? 'succeeded ✅' : 'failed ❌'}\n${url}`; + - name: Use Node.js 18.x + uses: actions/setup-node@v3 + with: + node-version: '18.x' + cache: 'npm' - await github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: body - }) + - name: webfactory/ssh-agent 🖥️ + uses: webfactory/ssh-agent@v0.8.0 + with: + # Private SSH key to register in the SSH agent + ssh-private-key: ${{ secrets.WEBDEV }} - - name: Set latest commit status as ${{ job.status }} - uses: myrotvorets/set-commit-status-action@master - if: always() - with: - sha: ${{ steps.comment-branch.outputs.head_sha }} - token: ${{ secrets.GITHUB_TOKEN }} - status: ${{ job.status }} \ No newline at end of file + - name: Deploy 🚀 + run: | + git remote set-url origin git@github.com:yaptide/web_dev.git + npm run deploy -- -u "github-actions-bot " -r "git@github.com:yaptide/web_dev.git" \ No newline at end of file From 7ab6129c31614faaedda03547a395e5a81e81822 Mon Sep 17 00:00:00 2001 From: Leszek Grzanka Date: Wed, 31 May 2023 14:10:42 +0000 Subject: [PATCH 09/10] new files --- .github/workflows/manual.yml | 127 ------------------------------ .github/workflows/manual_test.yml | 83 +++++++++++++++++++ .github/workflows/node.js.yml | 2 +- 3 files changed, 84 insertions(+), 128 deletions(-) delete mode 100644 .github/workflows/manual.yml create mode 100644 .github/workflows/manual_test.yml diff --git a/.github/workflows/manual.yml b/.github/workflows/manual.yml deleted file mode 100644 index 3eeca6e1f..000000000 --- a/.github/workflows/manual.yml +++ /dev/null @@ -1,127 +0,0 @@ -name: Node.js CI - -on: - push: - branches: [master] - pull_request: - branches: [master] - -# see https://github.community/t/treating-warnings-as-errors-because-process-env-ci-true/18032 -env: - CI: false - -jobs: - build_and_test: - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [18.x] - # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ - - steps: - - uses: actions/checkout@v3 - with: - submodules: recursive - - uses: actions/setup-python@v4 - with: - python-version: '3.10' - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - cache: 'npm' - - run: npm ci - - run: npm run build --if-present - - run: npm run start & - - name: Wait for the app to start - uses: iFaxity/wait-on-action@v1.1.0 - with: - resource: http://localhost:3000 - - name: Run tests - uses: nick-fields/retry@v2 - with: - max_attempts: 2 - retry_on: error - timeout_seconds: 120 - command: npm test - - deploy-to-github-registry: - # needs: build_and_test - # this is a lengthy process, lets run it in parallel to build_and_test - runs-on: ubuntu-latest - env: - USERNAME: ${{ github.actor }} - PASSWORD: ${{ secrets.GITHUB_TOKEN }} - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }}-web - steps: - - name: Checkout - uses: actions/checkout@v2 - with: - submodules: true - - - name: Login to GitHub Container Registry - uses: docker/login-action@v1 - with: - registry: ${{ env.REGISTRY }} - username: ${{ env.USERNAME }} - password: ${{ env.PASSWORD }} - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v4.4.0 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - - # see https://github.com/docker/build-push-action/issues/513#issuecomment-987951050 - - name: Build and push Docker image - uses: docker/build-push-action@v2 - with: - context: . - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - # it seems that cache is not giving any benefit in speed, lets keep it disabled for now - # cache-from: type=gha - # cache-to: type=gha,mode=max - build-args: | - BUILDKIT_CONTEXT_KEEP_GIT_DIR=true - - deploy_gh_pages: - runs-on: ubuntu-latest - needs: [build_and_test] - if: github.ref == 'refs/heads/master' - - steps: - - name: Checkout 🛎️ - uses: actions/checkout@v3 - with: - submodules: recursive - - - uses: actions/setup-python@v4 - with: - python-version: '3.10' - - - name: Install 🔧 - run: npm install - - - name: Use Node.js 18.x - uses: actions/setup-node@v3 - with: - node-version: '18.x' - cache: 'npm' - - - name: webfactory/ssh-agent 🖥️ - uses: webfactory/ssh-agent@v0.8.0 - with: - # Private SSH key to register in the SSH agent - ssh-private-key: ${{ secrets.WEBDEV }} - - - name: Deploy 🚀 - run: | - git remote set-url origin git@github.com:yaptide/web_dev.git - npm run deploy -- -u "github-actions-bot " -r "git@github.com:yaptide/web_dev.git" \ No newline at end of file diff --git a/.github/workflows/manual_test.yml b/.github/workflows/manual_test.yml new file mode 100644 index 000000000..5e32c172e --- /dev/null +++ b/.github/workflows/manual_test.yml @@ -0,0 +1,83 @@ +name: On-demand tests + +# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows +on: + issue_comment: + types: [created] + +# see https://github.community/t/treating-warnings-as-errors-because-process-env-ci-true/18032 +env: + CI: false + +jobs: + build_and_test: + runs-on: ubuntu-latest + # Only run if it is a PR and the comment contains /test + if: github.event.issue.pull_request && contains(github.event.comment.body, '/test') + strategy: + matrix: + node-version: [18.x] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + + steps: + - name: Get branch of PR + uses: xt0rted/pull-request-comment-branch@v1 + id: comment-branch + - name: Set latest commit status as pending + uses: myrotvorets/set-commit-status-action@master + with: + sha: ${{ steps.comment-branch.outputs.head_sha }} + token: ${{ secrets.GITHUB_TOKEN }} + status: pending + - uses: actions/checkout@v3 + with: + submodules: recursive + ref: ${{ steps.comment-branch.outputs.head_ref }} + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + - run: npm ci + - run: npm run build --if-present + - run: npm run start & + - name: Wait for the app to start + uses: iFaxity/wait-on-action@v1.1.0 + with: + resource: http://localhost:3000 + - name: Run tests + uses: nick-fields/retry@v2 + with: + max_attempts: 2 + retry_on: error + timeout_seconds: 120 + command: npm test + + - name: Add workflow result as comment on PR + uses: actions/github-script@v6 + if: always() + with: + script: | + const workflow_name = '${{ github.workflow }}'; + const job_name = '${{ github. }}'; + const url = '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}'; + const success = '${{ job.status }}' === 'success'; + const body = `${workflow_name}: ${success ? 'succeeded ✅' : 'failed ❌'}\n${url}`; + + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: body + }) + + - name: Set latest commit status as ${{ job.status }} + uses: myrotvorets/set-commit-status-action@master + if: always() + with: + sha: ${{ steps.comment-branch.outputs.head_sha }} + token: ${{ secrets.GITHUB_TOKEN }} + status: ${{ job.status }} diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 3eeca6e1f..f5d540a3f 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -124,4 +124,4 @@ jobs: - name: Deploy 🚀 run: | git remote set-url origin git@github.com:yaptide/web_dev.git - npm run deploy -- -u "github-actions-bot " -r "git@github.com:yaptide/web_dev.git" \ No newline at end of file + npm run deploy -- -u "github-actions-bot " -r "git@github.com:yaptide/web_dev.git" From 9b77352d0a59ee16f0d54754bfd755308a708e89 Mon Sep 17 00:00:00 2001 From: Leszek Grzanka Date: Wed, 31 May 2023 14:14:40 +0000 Subject: [PATCH 10/10] Manual deploy --- .github/workflows/manual_deploy.yml | 85 +++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 .github/workflows/manual_deploy.yml diff --git a/.github/workflows/manual_deploy.yml b/.github/workflows/manual_deploy.yml new file mode 100644 index 000000000..51aca63b8 --- /dev/null +++ b/.github/workflows/manual_deploy.yml @@ -0,0 +1,85 @@ +name: On-demand deploy + +# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows +on: + issue_comment: + types: [created] + +jobs: + deploy: + runs-on: ubuntu-latest + # Only run if it is a PR and the comment contains /deploy + if: github.event.issue.pull_request && contains(github.event.comment.body, '/deploy') + + steps: + - name: Get branch of PR + uses: xt0rted/pull-request-comment-branch@v1 + id: comment-branch + - name: Set latest commit status as pending + uses: myrotvorets/set-commit-status-action@master + with: + sha: ${{ steps.comment-branch.outputs.head_sha }} + token: ${{ secrets.GITHUB_TOKEN }} + status: pending + - uses: actions/checkout@v3 + with: + submodules: recursive + ref: ${{ steps.comment-branch.outputs.head_ref }} + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ env.USERNAME }} + password: ${{ env.PASSWORD }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4.4.0 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + # see https://github.com/docker/build-push-action/issues/513#issuecomment-987951050 + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + # it seems that cache is not giving any benefit in speed, lets keep it disabled for now + # cache-from: type=gha + # cache-to: type=gha,mode=max + build-args: | + BUILDKIT_CONTEXT_KEEP_GIT_DIR=true + + - name: Add workflow result as comment on PR + uses: actions/github-script@v6 + if: always() + with: + script: | + const workflow_name = '${{ github.workflow }}'; + const job_name = '${{ github. }}'; + const url = '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}'; + const success = '${{ job.status }}' === 'success'; + const body = `${workflow_name}: ${success ? 'succeeded ✅' : 'failed ❌'}\n${url}`; + + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: body + }) + + - name: Set latest commit status as ${{ job.status }} + uses: myrotvorets/set-commit-status-action@master + if: always() + with: + sha: ${{ steps.comment-branch.outputs.head_sha }} + token: ${{ secrets.GITHUB_TOKEN }} + status: ${{ job.status }}