From d5047b47aab77231b7b28c506c22b99b09868d55 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Mon, 20 Apr 2020 15:55:28 -0300 Subject: [PATCH 01/18] Do not create Docker image for PRs --- .github/workflows/build_and_test.yml | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 6d0c06c5f360b..03cac6d576a9f 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -34,7 +34,15 @@ jobs: with: node-version: "12.16.1" - - uses: actions/checkout@v1 + - uses: actions/checkout@v2 + + - name: Free disk space + run: | + sudo swapoff -a + sudo rm -f /swapfile + sudo apt clean + docker rmi $(docker image ls -aq) + df -h - name: check package-lock run: | @@ -199,7 +207,7 @@ jobs: docker exec mongo mongo --eval 'rs.initiate({_id:"rs0", members: [{"_id":1, "host":"localhost:27017"}]})' docker exec mongo mongo --eval 'rs.status()' - - uses: actions/checkout@v1 + - uses: actions/checkout@v2 - name: Cache cypress id: cache-cypress @@ -248,7 +256,7 @@ jobs: if: github.event_name == 'pull_request' steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v2 - name: Cache node modules id: cache-nodemodules @@ -323,6 +331,7 @@ jobs: meteor build --server-only --directory /tmp/build-pr - name: Build Docker image for PRs + if: Null(env.GITHUB_HEAD_REF) == '' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} VERSION: pr-${{ github.event.number }} @@ -348,7 +357,7 @@ jobs: needs: test steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v2 - name: Restore build uses: actions/download-artifact@v1 @@ -400,7 +409,7 @@ jobs: IMAGE: "rocketchat/rocket.chat" steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v2 - name: Restore build uses: actions/download-artifact@v1 From 18816368e5ebff54179ca739ddaa6fd40b670c44 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Mon, 20 Apr 2020 16:04:44 -0300 Subject: [PATCH 02/18] remove null --- .github/workflows/build_and_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 03cac6d576a9f..24df98b2f796d 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -331,7 +331,7 @@ jobs: meteor build --server-only --directory /tmp/build-pr - name: Build Docker image for PRs - if: Null(env.GITHUB_HEAD_REF) == '' + if: env.GITHUB_HEAD_REF == '' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} VERSION: pr-${{ github.event.number }} From 2f0a5123b30b952c0f303b7bc621a593387e6207 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Mon, 20 Apr 2020 16:35:06 -0300 Subject: [PATCH 03/18] Move if to job --- .github/workflows/build_and_test.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 24df98b2f796d..77ccc82ccc243 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -253,9 +253,16 @@ jobs: build-image-pr: runs-on: ubuntu-latest - if: github.event_name == 'pull_request' + if: github.event_name == 'pull_request' && env.GITHUB_HEAD_REF == '' steps: + - name: DEBUG + run: | + echo "env" + echo $GITHUB_HEAD_REF + echo "expression" + echo ${{ github.head_ref }} + - uses: actions/checkout@v2 - name: Cache node modules @@ -331,7 +338,6 @@ jobs: meteor build --server-only --directory /tmp/build-pr - name: Build Docker image for PRs - if: env.GITHUB_HEAD_REF == '' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} VERSION: pr-${{ github.event.number }} From da671a6b7f65583480687a898ca412f4629bece6 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Tue, 16 Jun 2020 18:37:10 -0300 Subject: [PATCH 04/18] More debug --- .github/workflows/build_and_test.yml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 6c62abc14bfc2..3c4ff3ae1b64c 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -19,6 +19,17 @@ jobs: runs-on: ubuntu-latest steps: + + - name: DEBUG + run: | + echo "env" + echo $GITHUB_HEAD_REF + echo "expression" + echo ${{ github.head_ref }} + echo "github.repository: ${{ github.repository }}" + echo "github.repository_owner: ${{ github.repository_owner }}" + echo "github.event_name: ${{ github.event_name }}" + - name: Github Info run: | echo "GITHUB_ACTION: $GITHUB_ACTION" @@ -255,14 +266,6 @@ jobs: runs-on: ubuntu-latest if: github.event_name == 'pull_request' && env.GITHUB_HEAD_REF == '' - steps: - - name: DEBUG - run: | - echo "env" - echo $GITHUB_HEAD_REF - echo "expression" - echo ${{ github.head_ref }} - - uses: actions/checkout@v2 - name: Free disk space From 279682480192e1a9c114f1cc98c706c82b15de07 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Tue, 16 Jun 2020 18:40:03 -0300 Subject: [PATCH 05/18] Fix padding --- .github/workflows/build_and_test.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 3c4ff3ae1b64c..18bda6b0dc6fe 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -20,15 +20,15 @@ jobs: steps: - - name: DEBUG - run: | - echo "env" - echo $GITHUB_HEAD_REF - echo "expression" - echo ${{ github.head_ref }} - echo "github.repository: ${{ github.repository }}" - echo "github.repository_owner: ${{ github.repository_owner }}" - echo "github.event_name: ${{ github.event_name }}" + - name: DEBUG + run: | + echo "env" + echo $GITHUB_HEAD_REF + echo "expression" + echo ${{ github.head_ref }} + echo "github.repository: ${{ github.repository }}" + echo "github.repository_owner: ${{ github.repository_owner }}" + echo "github.event_name: ${{ github.event_name }}" - name: Github Info run: | From d489d948934cc95d15044ce98ea3e4c7fda73d02 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Tue, 16 Jun 2020 18:43:04 -0300 Subject: [PATCH 06/18] remove test --- .github/workflows/build_and_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 18bda6b0dc6fe..35e8156853477 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -264,7 +264,7 @@ jobs: build-image-pr: runs-on: ubuntu-latest - if: github.event_name == 'pull_request' && env.GITHUB_HEAD_REF == '' + if: github.event_name == 'pull_request' - uses: actions/checkout@v2 From 958497eb340d2f7dc60eeb12b921784d70ff5b9e Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Tue, 16 Jun 2020 18:46:18 -0300 Subject: [PATCH 07/18] add steps --- .github/workflows/build_and_test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 35e8156853477..8557816943529 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -266,6 +266,7 @@ jobs: runs-on: ubuntu-latest if: github.event_name == 'pull_request' + steps: - uses: actions/checkout@v2 - name: Free disk space From 8411068e47e549d191d281bf65bea3eae8186fc6 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Tue, 16 Jun 2020 18:58:23 -0300 Subject: [PATCH 08/18] Try using secrets --- .github/workflows/build_and_test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 8557816943529..5d85e67c53d0f 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -29,6 +29,7 @@ jobs: echo "github.repository: ${{ github.repository }}" echo "github.repository_owner: ${{ github.repository_owner }}" echo "github.event_name: ${{ github.event_name }}" + echo "super secret ${{ secrets.DOCKER_USER }}" - name: Github Info run: | @@ -264,7 +265,7 @@ jobs: build-image-pr: runs-on: ubuntu-latest - if: github.event_name == 'pull_request' + if: github.event_name == 'pull_request' && '${{ secrets.DOCKER_USER }}' != '' steps: - uses: actions/checkout@v2 From c8ed3640521dd341459b2487c47a335982d51cc9 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Tue, 16 Jun 2020 19:00:47 -0300 Subject: [PATCH 09/18] omit ${{}} --- .github/workflows/build_and_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 5d85e67c53d0f..5285c2485a766 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -265,7 +265,7 @@ jobs: build-image-pr: runs-on: ubuntu-latest - if: github.event_name == 'pull_request' && '${{ secrets.DOCKER_USER }}' != '' + if: github.event_name == 'pull_request' && secrets.DOCKER_USER != '' steps: - uses: actions/checkout@v2 From 840f156411fec5ca53e8acd661cfe97b8f5f7eb5 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Wed, 17 Jun 2020 00:02:38 -0300 Subject: [PATCH 10/18] try with env var --- .github/workflows/build_and_test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 5285c2485a766..59957af2aeb53 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -265,7 +265,9 @@ jobs: build-image-pr: runs-on: ubuntu-latest - if: github.event_name == 'pull_request' && secrets.DOCKER_USER != '' + env: + DOCKER_USER: ${{ secrets.DOCKER_USER }} + if: github.event_name == 'pull_request' && $DOCKER_USER != '' steps: - uses: actions/checkout@v2 From 5772ab7ecda90dba7e5e325e19988d3223d6e8eb Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Wed, 17 Jun 2020 00:03:57 -0300 Subject: [PATCH 11/18] try expression --- .github/workflows/build_and_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 59957af2aeb53..95a50d5fc5849 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -267,7 +267,7 @@ jobs: runs-on: ubuntu-latest env: DOCKER_USER: ${{ secrets.DOCKER_USER }} - if: github.event_name == 'pull_request' && $DOCKER_USER != '' + if: ${{ github.event_name == 'pull_request' && $DOCKER_USER != '' }} steps: - uses: actions/checkout@v2 From e004100430f93bc02e8513290e1bfe4b6d9462f1 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Wed, 17 Jun 2020 00:05:49 -0300 Subject: [PATCH 12/18] without env var --- .github/workflows/build_and_test.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 95a50d5fc5849..d149737550404 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -265,9 +265,7 @@ jobs: build-image-pr: runs-on: ubuntu-latest - env: - DOCKER_USER: ${{ secrets.DOCKER_USER }} - if: ${{ github.event_name == 'pull_request' && $DOCKER_USER != '' }} + if: ${{ github.event_name == 'pull_request' && secrets.DOCKER_USER != '' }} steps: - uses: actions/checkout@v2 From b714207a5de79c1362b02cf038d17b02d8d7e2eb Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Wed, 17 Jun 2020 00:11:24 -0300 Subject: [PATCH 13/18] test env var on steps --- .github/workflows/build_and_test.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index d149737550404..bacb3c1bc92e5 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -265,7 +265,8 @@ jobs: build-image-pr: runs-on: ubuntu-latest - if: ${{ github.event_name == 'pull_request' && secrets.DOCKER_USER != '' }} + env: + DOCKER_USER: ${{ secrets.DOCKER_USER }} steps: - uses: actions/checkout@v2 @@ -348,6 +349,7 @@ jobs: - name: Build Rocket.Chat run: | + [ -z "$DOCKER_USER" ] && exit 0; meteor build --server-only --directory /tmp/build-pr - name: Build Docker image for PRs @@ -355,6 +357,8 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} VERSION: pr-${{ github.event.number }} run: | + [ -z "$DOCKER_USER" ] && exit 0; + cd /tmp/build-pr docker login docker.pkg.github.com -u "${GITHUB_ACTOR}" -p "${GITHUB_TOKEN}" From 44b80ffff52a7af52aff2f235be4e4e9c6c3b561 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Wed, 17 Jun 2020 00:18:49 -0300 Subject: [PATCH 14/18] final version prevent running --- .github/workflows/build_and_test.yml | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index bacb3c1bc92e5..5fdd8217af45e 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -20,17 +20,6 @@ jobs: steps: - - name: DEBUG - run: | - echo "env" - echo $GITHUB_HEAD_REF - echo "expression" - echo ${{ github.head_ref }} - echo "github.repository: ${{ github.repository }}" - echo "github.repository_owner: ${{ github.repository_owner }}" - echo "github.event_name: ${{ github.event_name }}" - echo "super secret ${{ secrets.DOCKER_USER }}" - - name: Github Info run: | echo "GITHUB_ACTION: $GITHUB_ACTION" @@ -335,6 +324,8 @@ jobs: - name: npm install if: steps.cache-nodemodules.outputs.cache-hit != 'true' run: | + [ -z "$DOCKER_USER" ] && exit 0; # prevent running from forks + meteor npm install # To reduce memory need during actual build, build the packages solely first @@ -349,7 +340,8 @@ jobs: - name: Build Rocket.Chat run: | - [ -z "$DOCKER_USER" ] && exit 0; + [ -z "$DOCKER_USER" ] && exit 0; # prevent running from forks + meteor build --server-only --directory /tmp/build-pr - name: Build Docker image for PRs @@ -357,7 +349,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} VERSION: pr-${{ github.event.number }} run: | - [ -z "$DOCKER_USER" ] && exit 0; + [ -z "$DOCKER_USER" ] && exit 0; # prevent running from forks cd /tmp/build-pr From f4957e8141a3c9ec23e3bf4e2f9c74eb87cfd3e5 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Wed, 17 Jun 2020 00:33:59 -0300 Subject: [PATCH 15/18] Move Docker build different workflow to run only on label --- .github/workflows/build_and_test.yml | 114 ------------------------ .github/workflows/build_test_docker.yml | 109 ++++++++++++++++++++++ 2 files changed, 109 insertions(+), 114 deletions(-) create mode 100644 .github/workflows/build_test_docker.yml diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 5fdd8217af45e..0857149ef3320 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -252,120 +252,6 @@ jobs: # commit: true # token: ${{ secrets.GITHUB_TOKEN }} - build-image-pr: - runs-on: ubuntu-latest - env: - DOCKER_USER: ${{ secrets.DOCKER_USER }} - - steps: - - uses: actions/checkout@v2 - - - name: Free disk space - run: | - sudo swapoff -a - sudo rm -f /swapfile - sudo apt clean - docker rmi $(docker image ls -aq) - df -h - - - name: Cache node modules - id: cache-nodemodules - uses: actions/cache@v1 - with: - path: node_modules - key: ${{ runner.OS }}-node_modules-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('.github/workflows/build_and_test.yml') }} - - - name: Cache meteor local - uses: actions/cache@v1 - with: - path: ./.meteor/local - key: ${{ runner.OS }}-meteor_cache-${{ hashFiles('.meteor/versions') }}-${{ hashFiles('.github/workflows/build_and_test.yml') }} - - - name: Cache meteor - uses: actions/cache@v1 - with: - path: ~/.meteor - key: ${{ runner.OS }}-meteor-${{ hashFiles('.meteor/release') }}-${{ hashFiles('.github/workflows/build_and_test.yml') }} - - - name: Use Node.js 12.16.1 - uses: actions/setup-node@v1 - with: - node-version: "12.16.1" - - - name: Install Meteor - run: | - # Restore bin from cache - set +e - METEOR_SYMLINK_TARGET=$(readlink ~/.meteor/meteor) - METEOR_TOOL_DIRECTORY=$(dirname "$METEOR_SYMLINK_TARGET") - set -e - LAUNCHER=$HOME/.meteor/$METEOR_TOOL_DIRECTORY/scripts/admin/launch-meteor - if [ -e $LAUNCHER ] - then - echo "Cached Meteor bin found, restoring it" - sudo cp "$LAUNCHER" "/usr/local/bin/meteor" - else - echo "No cached Meteor bin found." - fi - - # only install meteor if bin isn't found - command -v meteor >/dev/null 2>&1 || curl https://install.meteor.com | sed s/--progress-bar/-sL/g | /bin/sh - - - name: Versions - run: | - npm --versions - node -v - meteor --version - meteor npm --versions - meteor node -v - git version - echo $GITHUB_REF - - - name: npm install - if: steps.cache-nodemodules.outputs.cache-hit != 'true' - run: | - [ -z "$DOCKER_USER" ] && exit 0; # prevent running from forks - - meteor npm install - - # To reduce memory need during actual build, build the packages solely first - # - name: Build a Meteor cache - # run: | - # # to do this we can clear the main files and it build the rest - # echo "" > server/main.js - # echo "" > client/main.js - # sed -i.backup 's/rocketchat:livechat/#rocketchat:livechat/' .meteor/packages - # meteor build --server-only --debug --directory /tmp/build-temp - # git checkout -- server/main.js client/main.js .meteor/packages - - - name: Build Rocket.Chat - run: | - [ -z "$DOCKER_USER" ] && exit 0; # prevent running from forks - - meteor build --server-only --directory /tmp/build-pr - - - name: Build Docker image for PRs - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - VERSION: pr-${{ github.event.number }} - run: | - [ -z "$DOCKER_USER" ] && exit 0; # prevent running from forks - - cd /tmp/build-pr - - docker login docker.pkg.github.com -u "${GITHUB_ACTOR}" -p "${GITHUB_TOKEN}" - - cp $GITHUB_WORKSPACE/.docker/Dockerfile . - - export LOWERCASE_REPOSITORY=$(echo "$GITHUB_REPOSITORY" | tr "[:upper:]" "[:lower:]") - - export IMAGE_NAME="docker.pkg.github.com/${LOWERCASE_REPOSITORY}/rocket.chat:${VERSION}" - - echo "Build official Docker image ${IMAGE_NAME}" - - docker build -t $IMAGE_NAME . - docker push $IMAGE_NAME - deploy: runs-on: ubuntu-latest if: github.event_name == 'release' || github.ref == 'refs/heads/develop' diff --git a/.github/workflows/build_test_docker.yml b/.github/workflows/build_test_docker.yml new file mode 100644 index 0000000000000..f6433f06ca49e --- /dev/null +++ b/.github/workflows/build_test_docker.yml @@ -0,0 +1,109 @@ +name: Build Test Docker Image + +on: + pull_request: + branches: '**' + types: [labeled] + +env: + CI: true + MONGO_URL: mongodb://localhost:27017 + TOOL_NODE_FLAGS: --max_old_space_size=4096 + +jobs: + build-image-pr: + runs-on: ubuntu-latest + if: contains(github.event.issue.labels.*.name, 'docker image') + + steps: + - uses: actions/checkout@v2 + + - name: Free disk space + run: | + sudo swapoff -a + sudo rm -f /swapfile + sudo apt clean + docker rmi $(docker image ls -aq) + df -h + + - name: Cache node modules + id: cache-nodemodules + uses: actions/cache@v1 + with: + path: node_modules + key: ${{ runner.OS }}-node_modules-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('.github/workflows/build_and_test.yml') }} + + - name: Cache meteor local + uses: actions/cache@v1 + with: + path: ./.meteor/local + key: ${{ runner.OS }}-meteor_cache-${{ hashFiles('.meteor/versions') }}-${{ hashFiles('.github/workflows/build_and_test.yml') }} + + - name: Cache meteor + uses: actions/cache@v1 + with: + path: ~/.meteor + key: ${{ runner.OS }}-meteor-${{ hashFiles('.meteor/release') }}-${{ hashFiles('.github/workflows/build_and_test.yml') }} + + - name: Use Node.js 12.16.1 + uses: actions/setup-node@v1 + with: + node-version: "12.16.1" + + - name: Install Meteor + run: | + # Restore bin from cache + set +e + METEOR_SYMLINK_TARGET=$(readlink ~/.meteor/meteor) + METEOR_TOOL_DIRECTORY=$(dirname "$METEOR_SYMLINK_TARGET") + set -e + LAUNCHER=$HOME/.meteor/$METEOR_TOOL_DIRECTORY/scripts/admin/launch-meteor + if [ -e $LAUNCHER ] + then + echo "Cached Meteor bin found, restoring it" + sudo cp "$LAUNCHER" "/usr/local/bin/meteor" + else + echo "No cached Meteor bin found." + fi + + # only install meteor if bin isn't found + command -v meteor >/dev/null 2>&1 || curl https://install.meteor.com | sed s/--progress-bar/-sL/g | /bin/sh + + - name: Versions + run: | + npm --versions + node -v + meteor --version + meteor npm --versions + meteor node -v + git version + echo $GITHUB_REF + + - name: npm install + if: steps.cache-nodemodules.outputs.cache-hit != 'true' + run: | + meteor npm install + + - name: Build Rocket.Chat + run: | + meteor build --server-only --directory /tmp/build-pr + + - name: Build Docker image for PRs + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + VERSION: pr-${{ github.event.number }} + run: | + cd /tmp/build-pr + + docker login docker.pkg.github.com -u "${GITHUB_ACTOR}" -p "${GITHUB_TOKEN}" + + cp $GITHUB_WORKSPACE/.docker/Dockerfile . + + export LOWERCASE_REPOSITORY=$(echo "$GITHUB_REPOSITORY" | tr "[:upper:]" "[:lower:]") + + export IMAGE_NAME="docker.pkg.github.com/${LOWERCASE_REPOSITORY}/rocket.chat:${VERSION}" + + echo "Build official Docker image ${IMAGE_NAME}" + + docker build -t $IMAGE_NAME . + docker push $IMAGE_NAME From 10955fc8ae30f4e345604b748e1032bb3ca01ab3 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Wed, 17 Jun 2020 01:26:26 -0300 Subject: [PATCH 16/18] use correct event values --- .github/workflows/build_test_docker.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_test_docker.yml b/.github/workflows/build_test_docker.yml index f6433f06ca49e..18f5c59ecf1de 100644 --- a/.github/workflows/build_test_docker.yml +++ b/.github/workflows/build_test_docker.yml @@ -3,7 +3,7 @@ name: Build Test Docker Image on: pull_request: branches: '**' - types: [labeled] + types: [opened,synchronize,reopened,labeled] env: CI: true @@ -13,7 +13,7 @@ env: jobs: build-image-pr: runs-on: ubuntu-latest - if: contains(github.event.issue.labels.*.name, 'docker image') + if: contains(github.event.pull_request.labels.*.name, 'docker image') steps: - uses: actions/checkout@v2 From d6cf7b41fc5517f1048c0681e8b4949ab05cf7e1 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Wed, 17 Jun 2020 12:09:59 -0300 Subject: [PATCH 17/18] Add debug back --- .github/workflows/build_and_test.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 0857149ef3320..a55b9f0f41426 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -19,6 +19,16 @@ jobs: runs-on: ubuntu-latest steps: + - name: DEBUG + run: | + echo "env" + echo $GITHUB_HEAD_REF + echo "expression" + echo ${{ github.head_ref }} + echo "github.repository: ${{ github.repository }}" + echo "github.repository_owner: ${{ github.repository_owner }}" + echo "github.event_name: ${{ github.event_name }}" + echo "github.event.pull_request.head.repo.full_name: ${{ github.event.pull_request.head.repo.full_name }}" - name: Github Info run: | From 483807553a21e6442174ce943b90dca7e154c6ad Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Wed, 17 Jun 2020 12:14:42 -0300 Subject: [PATCH 18/18] Skip image build --- .github/workflows/build_and_test.yml | 117 ++++++++++++++++++++++-- .github/workflows/build_test_docker.yml | 109 ---------------------- 2 files changed, 107 insertions(+), 119 deletions(-) delete mode 100644 .github/workflows/build_test_docker.yml diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index a55b9f0f41426..9d9d5a21fbdc9 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -19,16 +19,6 @@ jobs: runs-on: ubuntu-latest steps: - - name: DEBUG - run: | - echo "env" - echo $GITHUB_HEAD_REF - echo "expression" - echo ${{ github.head_ref }} - echo "github.repository: ${{ github.repository }}" - echo "github.repository_owner: ${{ github.repository_owner }}" - echo "github.event_name: ${{ github.event_name }}" - echo "github.event.pull_request.head.repo.full_name: ${{ github.event.pull_request.head.repo.full_name }}" - name: Github Info run: | @@ -262,6 +252,113 @@ jobs: # commit: true # token: ${{ secrets.GITHUB_TOKEN }} + build-image-pr: + runs-on: ubuntu-latest + if: github.event.pull_request.head.repo.full_name == github.repository + + steps: + - uses: actions/checkout@v2 + + - name: Free disk space + run: | + sudo swapoff -a + sudo rm -f /swapfile + sudo apt clean + docker rmi $(docker image ls -aq) + df -h + + - name: Cache node modules + id: cache-nodemodules + uses: actions/cache@v1 + with: + path: node_modules + key: ${{ runner.OS }}-node_modules-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('.github/workflows/build_and_test.yml') }} + + - name: Cache meteor local + uses: actions/cache@v1 + with: + path: ./.meteor/local + key: ${{ runner.OS }}-meteor_cache-${{ hashFiles('.meteor/versions') }}-${{ hashFiles('.github/workflows/build_and_test.yml') }} + + - name: Cache meteor + uses: actions/cache@v1 + with: + path: ~/.meteor + key: ${{ runner.OS }}-meteor-${{ hashFiles('.meteor/release') }}-${{ hashFiles('.github/workflows/build_and_test.yml') }} + + - name: Use Node.js 12.16.1 + uses: actions/setup-node@v1 + with: + node-version: "12.16.1" + + - name: Install Meteor + run: | + # Restore bin from cache + set +e + METEOR_SYMLINK_TARGET=$(readlink ~/.meteor/meteor) + METEOR_TOOL_DIRECTORY=$(dirname "$METEOR_SYMLINK_TARGET") + set -e + LAUNCHER=$HOME/.meteor/$METEOR_TOOL_DIRECTORY/scripts/admin/launch-meteor + if [ -e $LAUNCHER ] + then + echo "Cached Meteor bin found, restoring it" + sudo cp "$LAUNCHER" "/usr/local/bin/meteor" + else + echo "No cached Meteor bin found." + fi + + # only install meteor if bin isn't found + command -v meteor >/dev/null 2>&1 || curl https://install.meteor.com | sed s/--progress-bar/-sL/g | /bin/sh + + - name: Versions + run: | + npm --versions + node -v + meteor --version + meteor npm --versions + meteor node -v + git version + echo $GITHUB_REF + + - name: npm install + if: steps.cache-nodemodules.outputs.cache-hit != 'true' + run: | + meteor npm install + + # To reduce memory need during actual build, build the packages solely first + # - name: Build a Meteor cache + # run: | + # # to do this we can clear the main files and it build the rest + # echo "" > server/main.js + # echo "" > client/main.js + # sed -i.backup 's/rocketchat:livechat/#rocketchat:livechat/' .meteor/packages + # meteor build --server-only --debug --directory /tmp/build-temp + # git checkout -- server/main.js client/main.js .meteor/packages + + - name: Build Rocket.Chat + run: | + meteor build --server-only --directory /tmp/build-pr + + - name: Build Docker image for PRs + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + VERSION: pr-${{ github.event.number }} + run: | + cd /tmp/build-pr + + docker login docker.pkg.github.com -u "${GITHUB_ACTOR}" -p "${GITHUB_TOKEN}" + + cp $GITHUB_WORKSPACE/.docker/Dockerfile . + + export LOWERCASE_REPOSITORY=$(echo "$GITHUB_REPOSITORY" | tr "[:upper:]" "[:lower:]") + + export IMAGE_NAME="docker.pkg.github.com/${LOWERCASE_REPOSITORY}/rocket.chat:${VERSION}" + + echo "Build official Docker image ${IMAGE_NAME}" + + docker build -t $IMAGE_NAME . + docker push $IMAGE_NAME + deploy: runs-on: ubuntu-latest if: github.event_name == 'release' || github.ref == 'refs/heads/develop' diff --git a/.github/workflows/build_test_docker.yml b/.github/workflows/build_test_docker.yml deleted file mode 100644 index 18f5c59ecf1de..0000000000000 --- a/.github/workflows/build_test_docker.yml +++ /dev/null @@ -1,109 +0,0 @@ -name: Build Test Docker Image - -on: - pull_request: - branches: '**' - types: [opened,synchronize,reopened,labeled] - -env: - CI: true - MONGO_URL: mongodb://localhost:27017 - TOOL_NODE_FLAGS: --max_old_space_size=4096 - -jobs: - build-image-pr: - runs-on: ubuntu-latest - if: contains(github.event.pull_request.labels.*.name, 'docker image') - - steps: - - uses: actions/checkout@v2 - - - name: Free disk space - run: | - sudo swapoff -a - sudo rm -f /swapfile - sudo apt clean - docker rmi $(docker image ls -aq) - df -h - - - name: Cache node modules - id: cache-nodemodules - uses: actions/cache@v1 - with: - path: node_modules - key: ${{ runner.OS }}-node_modules-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('.github/workflows/build_and_test.yml') }} - - - name: Cache meteor local - uses: actions/cache@v1 - with: - path: ./.meteor/local - key: ${{ runner.OS }}-meteor_cache-${{ hashFiles('.meteor/versions') }}-${{ hashFiles('.github/workflows/build_and_test.yml') }} - - - name: Cache meteor - uses: actions/cache@v1 - with: - path: ~/.meteor - key: ${{ runner.OS }}-meteor-${{ hashFiles('.meteor/release') }}-${{ hashFiles('.github/workflows/build_and_test.yml') }} - - - name: Use Node.js 12.16.1 - uses: actions/setup-node@v1 - with: - node-version: "12.16.1" - - - name: Install Meteor - run: | - # Restore bin from cache - set +e - METEOR_SYMLINK_TARGET=$(readlink ~/.meteor/meteor) - METEOR_TOOL_DIRECTORY=$(dirname "$METEOR_SYMLINK_TARGET") - set -e - LAUNCHER=$HOME/.meteor/$METEOR_TOOL_DIRECTORY/scripts/admin/launch-meteor - if [ -e $LAUNCHER ] - then - echo "Cached Meteor bin found, restoring it" - sudo cp "$LAUNCHER" "/usr/local/bin/meteor" - else - echo "No cached Meteor bin found." - fi - - # only install meteor if bin isn't found - command -v meteor >/dev/null 2>&1 || curl https://install.meteor.com | sed s/--progress-bar/-sL/g | /bin/sh - - - name: Versions - run: | - npm --versions - node -v - meteor --version - meteor npm --versions - meteor node -v - git version - echo $GITHUB_REF - - - name: npm install - if: steps.cache-nodemodules.outputs.cache-hit != 'true' - run: | - meteor npm install - - - name: Build Rocket.Chat - run: | - meteor build --server-only --directory /tmp/build-pr - - - name: Build Docker image for PRs - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - VERSION: pr-${{ github.event.number }} - run: | - cd /tmp/build-pr - - docker login docker.pkg.github.com -u "${GITHUB_ACTOR}" -p "${GITHUB_TOKEN}" - - cp $GITHUB_WORKSPACE/.docker/Dockerfile . - - export LOWERCASE_REPOSITORY=$(echo "$GITHUB_REPOSITORY" | tr "[:upper:]" "[:lower:]") - - export IMAGE_NAME="docker.pkg.github.com/${LOWERCASE_REPOSITORY}/rocket.chat:${VERSION}" - - echo "Build official Docker image ${IMAGE_NAME}" - - docker build -t $IMAGE_NAME . - docker push $IMAGE_NAME