diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 085fedb18..ac1dfa858 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -2,16 +2,16 @@ version: 2 updates: - package-ecosystem: "github-actions" directory: "/" + rebase-strategy: "disabled" schedule: interval: weekly day: "saturday" timezone: "Europe/Berlin" time: "03:00" - # open-pull-requests-limit: 10 - # ignore: - package-ecosystem: npm directory: "/" + rebase-strategy: "disabled" schedule: interval: weekly day: "saturday" @@ -19,6 +19,7 @@ updates: time: "03:00" - package-ecosystem: npm directory: "/backend" + rebase-strategy: "disabled" schedule: interval: weekly day: "saturday" @@ -26,6 +27,7 @@ updates: time: "03:00" - package-ecosystem: npm directory: "/webapp" + rebase-strategy: "disabled" schedule: interval: weekly day: "saturday" @@ -34,6 +36,7 @@ updates: - package-ecosystem: docker directory: "/backend" + rebase-strategy: "disabled" schedule: interval: weekly day: "saturday" @@ -41,6 +44,7 @@ updates: time: "03:00" - package-ecosystem: docker directory: "/webapp" + rebase-strategy: "disabled" schedule: interval: weekly day: "saturday" @@ -48,6 +52,7 @@ updates: time: "03:00" - package-ecosystem: docker directory: "/neo4j" + rebase-strategy: "disabled" schedule: interval: weekly day: "saturday" @@ -55,6 +60,7 @@ updates: time: "03:00" - package-ecosystem: docker directory: "/deployment/src/docker" + rebase-strategy: "disabled" schedule: interval: weekly day: "saturday" diff --git a/.github/workflows/lint_pr.yml b/.github/workflows/lint_pr.yml index 5a06f9144..5a8bb662f 100644 --- a/.github/workflows/lint_pr.yml +++ b/.github/workflows/lint_pr.yml @@ -1,7 +1,6 @@ name: "ocelot.social lint pull request CI" on: - pull_request: pull_request_target: types: - opened diff --git a/.github/workflows/publish-branded.yml b/.github/workflows/publish-branded.yml index 2877aa213..a404453e6 100644 --- a/.github/workflows/publish-branded.yml +++ b/.github/workflows/publish-branded.yml @@ -1,9 +1,7 @@ -name: ocelot.social publish branded CI - +name: publish-branded on: - push: - branches: - - master + repository_dispatch: + types: [trigger-build-success] jobs: build_branded: name: Docker Build Branded @@ -11,7 +9,10 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v2 - + with: + ref: ${{ github.event.client_payload.ref }} + - name: Setup env + run: echo "OCELOT_VERSION=${{ github.event.client_payload.BUILD_VERSION }}" >> $GITHUB_ENV - name: Build branded images run: | deployment/scripts/branded-images.build.sh @@ -45,9 +46,6 @@ jobs: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} steps: - - name: Checkout code - uses: actions/checkout@v2 - - name: Download Docker Image (Backend) uses: actions/download-artifact@v2 with: @@ -73,13 +71,4 @@ jobs: run: docker load < /tmp/maintenance-branded.tar - name: Upload to dockerhub - run: deployment/scripts/branded-images.upload.sh -# - name: login to dockerhub -# run: echo "${DOCKERHUB_TOKEN}" | docker login -u "${DOCKERHUB_USERNAME}" --password-stdin -# -# - name: Push Backend -# run: docker push --all-tags ocelotsocialnetwork/backend-branded -# - name: Push Webapp -# run: docker push --all-tags ocelotsocialnetwork/webapp-branded -# - name: Push Maintenance -# run: docker push --all-tags ocelotsocialnetwork/maintenance-branded \ No newline at end of file + run: deployment/scripts/branded-images.upload.sh \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 32198dd62..01256d719 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,64 +1,36 @@ -name: ocelot.social publish CI +name: publish on: push: branches: - master - # - 5059-epic-groups # for testing while developing - # template branches in repo - # - template--separate-branch-auto-deployment--5059-epic-groups jobs: - ############################################################################## - # JOB: PREPARE ############################################################### - ############################################################################## - prepare: - name: Prepare - runs-on: ubuntu-latest - # needs: [nothing] - steps: - ########################################################################## - # CHECKOUT CODE ########################################################## - ########################################################################## - - name: Checkout code - uses: actions/checkout@v3 - ########################################################################## - # TODO: DO STUFF ??? ##################################################### - ########################################################################## - - name: Check translation files - run: | - scripts/translations/sort.sh - scripts/translations/missing-keys.sh - ############################################################################## # JOB: DOCKER BUILD COMMUNITY NEO4J ########################################## ############################################################################## build_production_neo4j: name: Docker Build Production - Neo4J runs-on: ubuntu-latest - needs: [prepare] steps: - ########################################################################## - # CHECKOUT CODE ########################################################## - ########################################################################## - name: Checkout code uses: actions/checkout@v3 - ########################################################################## - # SET ENVS ############################################################### - ########################################################################## - - name: ENV - VERSION - run: echo "VERSION=$(node -p -e "require('./package.json').version")" >> $GITHUB_ENV - - name: ENV - BUILD_DATE - run: echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV - - name: ENV - BUILD_VERSION - run: echo "BUILD_VERSION=${VERSION}-${GITHUB_RUN_NUMBER}" >> $GITHUB_ENV - - name: ENV - BUILD_COMMIT - run: echo "BUILD_COMMIT=${GITHUB_SHA}" >> $GITHUB_ENV - ########################################################################## - # NEO4J ################################################################## - ########################################################################## + - name: Setup env + run: | + echo "VERSION=$(node -p -e "require('./package.json').version")" >> $GITHUB_ENV + echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV + echo "BUILD_COMMIT=${GITHUB_SHA}" >> $GITHUB_ENV + - run: echo "BUILD_VERSION=${VERSION}-${GITHUB_RUN_NUMBER}" >> $GITHUB_ENV - name: Neo4J | Build `community` image - run: docker build --target community -t "ocelotsocialnetwork/neo4j-community:latest" -t "ocelotsocialnetwork/neo4j-community:${VERSION}" -t "ocelotsocialnetwork/neo4j-community:${BUILD_VERSION}" --build-arg BBUILD_DATE=$BUILD_DATE --build-arg BBUILD_VERSION=$BUILD_VERSION --build-arg BBUILD_COMMIT=$BUILD_COMMIT neo4j/ + run: | + docker build --target community \ + --tag "ocelotsocialnetwork/neo4j-community:latest" \ + --tag "ocelotsocialnetwork/neo4j-community:${VERSION}" \ + --tag "ocelotsocialnetwork/neo4j-community:${BUILD_VERSION}" \ + --build-arg BBUILD_DATE=$BUILD_DATE \ + --build-arg BBUILD_VERSION=$BUILD_VERSION \ + --build-arg BBUILD_COMMIT=$BUILD_COMMIT \ + neo4j/ - name: Neo4J | Save docker image run: docker save "ocelotsocialnetwork/neo4j-community" > /tmp/neo4j.tar - name: Upload Artifact @@ -73,32 +45,41 @@ jobs: build_production_backend: name: Docker Build Production - Backend runs-on: ubuntu-latest - needs: [prepare] steps: - ########################################################################## - # CHECKOUT CODE ########################################################## - ########################################################################## - name: Checkout code uses: actions/checkout@v3 - ########################################################################## - # SET ENVS ############################################################### - ########################################################################## - - name: ENV - VERSION - run: echo "VERSION=$(node -p -e "require('./package.json').version")" >> $GITHUB_ENV - - name: ENV - BUILD_DATE - run: echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV - - name: ENV - BUILD_VERSION - run: echo "BUILD_VERSION=${VERSION}-${GITHUB_RUN_NUMBER}" >> $GITHUB_ENV - - name: ENV - BUILD_COMMIT - run: echo "BUILD_COMMIT=${GITHUB_SHA}" >> $GITHUB_ENV - ########################################################################## - # BUILD BACKEND DOCKER IMAGE (production) ################################ - ########################################################################## + - name: Setup env + run: | + echo "VERSION=$(node -p -e "require('./package.json').version")" >> $GITHUB_ENV + echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV + echo "BUILD_COMMIT=${GITHUB_SHA}" >> $GITHUB_ENV + - run: echo "BUILD_VERSION=${VERSION}-${GITHUB_RUN_NUMBER}" >> $GITHUB_ENV - name: Backend | Build `production` image run: | - docker build --target base -t "ocelotsocialnetwork/backend:latest-base" -t "ocelotsocialnetwork/backend:${VERSION}-base" -t "ocelotsocialnetwork/backend:${BUILD_VERSION}-base" --build-arg BBUILD_DATE=$BUILD_DATE --build-arg BBUILD_VERSION=$BUILD_VERSION --build-arg BBUILD_COMMIT=$BUILD_COMMIT backend/ - docker build --target code -t "ocelotsocialnetwork/backend:latest-code" -t "ocelotsocialnetwork/backend:${VERSION}-code" -t "ocelotsocialnetwork/backend:${BUILD_VERSION}-code" --build-arg BBUILD_DATE=$BUILD_DATE --build-arg BBUILD_VERSION=$BUILD_VERSION --build-arg BBUILD_COMMIT=$BUILD_COMMIT backend/ - docker build --target production -t "ocelotsocialnetwork/backend:latest" -t "ocelotsocialnetwork/backend:${VERSION}" -t "ocelotsocialnetwork/backend:${BUILD_VERSION}" --build-arg BBUILD_DATE=$BUILD_DATE --build-arg BBUILD_VERSION=$BUILD_VERSION --build-arg BBUILD_COMMIT=$BUILD_COMMIT backend/ + docker build --target base \ + --tag "ocelotsocialnetwork/backend:latest-base" \ + --tag "ocelotsocialnetwork/backend:${VERSION}-base" \ + --tag "ocelotsocialnetwork/backend:${BUILD_VERSION}-base" \ + --build-arg BBUILD_DATE=$BUILD_DATE \ + --build-arg BBUILD_VERSION=$BUILD_VERSION \ + --build-arg BBUILD_COMMIT=$BUILD_COMMIT \ + backend/ + docker build --target code \ + --tag "ocelotsocialnetwork/backend:latest-code" \ + --tag "ocelotsocialnetwork/backend:${VERSION}-code" \ + --tag "ocelotsocialnetwork/backend:${BUILD_VERSION}-code" \ + --build-arg BBUILD_DATE=$BUILD_DATE \ + --build-arg BBUILD_VERSION=$BUILD_VERSION \ + --build-arg BBUILD_COMMIT=$BUILD_COMMIT \ + backend/ + docker build --target production \ + --tag "ocelotsocialnetwork/backend:latest" \ + --tag "ocelotsocialnetwork/backend:${VERSION}" \ + --tag "ocelotsocialnetwork/backend:${BUILD_VERSION}" \ + --build-arg BBUILD_DATE=$BUILD_DATE \ + --build-arg BBUILD_VERSION=$BUILD_VERSION \ + --build-arg BBUILD_COMMIT=$BUILD_COMMIT \ + backend/ - name: Backend | Save docker image run: docker save "ocelotsocialnetwork/backend" > /tmp/backend.tar - name: Upload Artifact @@ -113,32 +94,41 @@ jobs: build_production_webapp: name: Docker Build Production - WebApp runs-on: ubuntu-latest - needs: [prepare] steps: - ########################################################################## - # CHECKOUT CODE ########################################################## - ########################################################################## - name: Checkout code uses: actions/checkout@v3 - ########################################################################## - # SET ENVS ############################################################### - ########################################################################## - - name: ENV - VERSION - run: echo "VERSION=$(node -p -e "require('./package.json').version")" >> $GITHUB_ENV - - name: ENV - BUILD_DATE - run: echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV - - name: ENV - BUILD_VERSION - run: echo "BUILD_VERSION=${VERSION}-${GITHUB_RUN_NUMBER}" >> $GITHUB_ENV - - name: ENV - BUILD_COMMIT - run: echo "BUILD_COMMIT=${GITHUB_SHA}" >> $GITHUB_ENV - ########################################################################## - # BUILD WEBAPP DOCKER IMAGE (build) ###################################### - ########################################################################## + - name: Setup env + run: | + echo "VERSION=$(node -p -e "require('./package.json').version")" >> $GITHUB_ENV + echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV + echo "BUILD_COMMIT=${GITHUB_SHA}" >> $GITHUB_ENV + - run: echo "BUILD_VERSION=${VERSION}-${GITHUB_RUN_NUMBER}" >> $GITHUB_ENV - name: Webapp | Build `production` image run: | - docker build --target base -t "ocelotsocialnetwork/webapp:latest-base" -t "ocelotsocialnetwork/webapp:${VERSION}-base" -t "ocelotsocialnetwork/webapp:${BUILD_VERSION}-base" --build-arg BBUILD_DATE=$BUILD_DATE --build-arg BBUILD_VERSION=$BUILD_VERSION --build-arg BBUILD_COMMIT=$BUILD_COMMIT webapp/ - docker build --target code -t "ocelotsocialnetwork/webapp:latest-code" -t "ocelotsocialnetwork/webapp:${VERSION}-code" -t "ocelotsocialnetwork/webapp:${BUILD_VERSION}-code" --build-arg BBUILD_DATE=$BUILD_DATE --build-arg BBUILD_VERSION=$BUILD_VERSION --build-arg BBUILD_COMMIT=$BUILD_COMMIT webapp/ - docker build --target production -t "ocelotsocialnetwork/webapp:latest" -t "ocelotsocialnetwork/webapp:${VERSION}" -t "ocelotsocialnetwork/webapp:${BUILD_VERSION}" --build-arg BBUILD_DATE=$BUILD_DATE --build-arg BBUILD_VERSION=$BUILD_VERSION --build-arg BBUILD_COMMIT=$BUILD_COMMIT webapp/ + docker build --target base \ + --tag "ocelotsocialnetwork/webapp:latest-base" \ + --tag "ocelotsocialnetwork/webapp:${VERSION}-base" \ + --tag "ocelotsocialnetwork/webapp:${BUILD_VERSION}-base" \ + --build-arg BBUILD_DATE=$BUILD_DATE \ + --build-arg BBUILD_VERSION=$BUILD_VERSION \ + --build-arg BBUILD_COMMIT=$BUILD_COMMIT \ + webapp/ + docker build --target code \ + --tag "ocelotsocialnetwork/webapp:latest-code" \ + --tag "ocelotsocialnetwork/webapp:${VERSION}-code" \ + --tag "ocelotsocialnetwork/webapp:${BUILD_VERSION}-code" \ + --build-arg BBUILD_DATE=$BUILD_DATE \ + --build-arg BBUILD_VERSION=$BUILD_VERSION \ + --build-arg BBUILD_COMMIT=$BUILD_COMMIT \ + webapp/ + docker build --target production \ + --tag "ocelotsocialnetwork/webapp:latest" \ + --tag "ocelotsocialnetwork/webapp:${VERSION}" \ + --tag "ocelotsocialnetwork/webapp:${BUILD_VERSION}" \ + --build-arg BBUILD_DATE=$BUILD_DATE \ + --build-arg BBUILD_VERSION=$BUILD_VERSION \ + --build-arg BBUILD_COMMIT=$BUILD_COMMIT \ + webapp/ - name: Webapp | Save docker image run: docker save "ocelotsocialnetwork/webapp" > /tmp/webapp.tar - name: Upload Artifact @@ -153,32 +143,44 @@ jobs: build_production_maintenance: name: Docker Build Production - Maintenance runs-on: ubuntu-latest - needs: [prepare] steps: - ########################################################################## - # CHECKOUT CODE ########################################################## - ########################################################################## - name: Checkout code uses: actions/checkout@v3 - ########################################################################## - # SET ENVS ############################################################### - ########################################################################## - - name: ENV - VERSION - run: echo "VERSION=$(node -p -e "require('./package.json').version")" >> $GITHUB_ENV - - name: ENV - BUILD_DATE - run: echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV - - name: ENV - BUILD_VERSION - run: echo "BUILD_VERSION=${VERSION}-${GITHUB_RUN_NUMBER}" >> $GITHUB_ENV - - name: ENV - BUILD_COMMIT - run: echo "BUILD_COMMIT=${GITHUB_SHA}" >> $GITHUB_ENV - ########################################################################## - # BUILD MAINTENANCE DOCKER IMAGE (build) ################################# - ########################################################################## + - name: Setup env + run: | + echo "VERSION=$(node -p -e "require('./package.json').version")" >> $GITHUB_ENV + echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV + echo "BUILD_COMMIT=${GITHUB_SHA}" >> $GITHUB_ENV + - run: echo "BUILD_VERSION=${VERSION}-${GITHUB_RUN_NUMBER}" >> $GITHUB_ENV - name: Maintenance | Build `production` image run: | - docker build --target base -t "ocelotsocialnetwork/maintenance:latest-base" -t "ocelotsocialnetwork/maintenance:${VERSION}-base" -t "ocelotsocialnetwork/maintenance:${BUILD_VERSION}-base" --build-arg BBUILD_DATE=$BUILD_DATE --build-arg BBUILD_VERSION=$BUILD_VERSION --build-arg BBUILD_COMMIT=$BUILD_COMMIT webapp/ -f webapp/Dockerfile.maintenance - docker build --target code -t "ocelotsocialnetwork/maintenance:latest-code" -t "ocelotsocialnetwork/maintenance:${VERSION}-code" -t "ocelotsocialnetwork/maintenance:${BUILD_VERSION}-code" --build-arg BBUILD_DATE=$BUILD_DATE --build-arg BBUILD_VERSION=$BUILD_VERSION --build-arg BBUILD_COMMIT=$BUILD_COMMIT webapp/ -f webapp/Dockerfile.maintenance - docker build --target production -t "ocelotsocialnetwork/maintenance:latest" -t "ocelotsocialnetwork/maintenance:${VERSION}" -t "ocelotsocialnetwork/maintenance:${BUILD_VERSION}" --build-arg BBUILD_DATE=$BUILD_DATE --build-arg BBUILD_VERSION=$BUILD_VERSION --build-arg BBUILD_COMMIT=$BUILD_COMMIT webapp/ -f webapp/Dockerfile.maintenance + docker build --target base \ + --tag "ocelotsocialnetwork/maintenance:latest-base" \ + --tag "ocelotsocialnetwork/maintenance:${VERSION}-base" \ + --tag "ocelotsocialnetwork/maintenance:${BUILD_VERSION}-base" \ + --build-arg BBUILD_DATE=$BUILD_DATE \ + --build-arg BBUILD_VERSION=$BUILD_VERSION \ + --build-arg BBUILD_COMMIT=$BUILD_COMMIT \ + -f webapp/Dockerfile.maintenance \ + webapp/ + docker build --target code \ + --tag "ocelotsocialnetwork/maintenance:latest-code" \ + --tag "ocelotsocialnetwork/maintenance:${VERSION}-code" \ + --tag "ocelotsocialnetwork/maintenance:${BUILD_VERSION}-code" \ + --build-arg BBUILD_DATE=$BUILD_DATE \ + --build-arg BBUILD_VERSION=$BUILD_VERSION \ + --build-arg BBUILD_COMMIT=$BUILD_COMMIT \ + -f webapp/Dockerfile.maintenance \ + webapp/ + docker build --target production \ + --tag "ocelotsocialnetwork/maintenance:latest" \ + --tag "ocelotsocialnetwork/maintenance:${VERSION}" \ + --tag "ocelotsocialnetwork/maintenance:${BUILD_VERSION}" \ + --build-arg BBUILD_DATE=$BUILD_DATE \ + --build-arg BBUILD_VERSION=$BUILD_VERSION \ + --build-arg BBUILD_COMMIT=$BUILD_COMMIT \ + -f webapp/Dockerfile.maintenance \ + webapp/ - name: Maintenance | Save docker image run: docker save "ocelotsocialnetwork/maintenance" > /tmp/maintenance.tar - name: Upload Artifact @@ -198,130 +200,39 @@ jobs: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} steps: - ########################################################################## - # CHECKOUT CODE ########################################################## - ########################################################################## - - name: Checkout code - uses: actions/checkout@v3 - ########################################################################## - # DOWNLOAD DOCKER IMAGES ################################################# - ########################################################################## - name: Download Docker Image (Neo4J) uses: actions/download-artifact@v3 with: name: docker-neo4j-community path: /tmp - - name: Load Docker Image - run: docker load < /tmp/neo4j.tar + - run: docker load < /tmp/neo4j.tar - name: Download Docker Image (Backend) uses: actions/download-artifact@v3 with: name: docker-backend-production path: /tmp - - name: Load Docker Image - run: docker load < /tmp/backend.tar + - run: docker load < /tmp/backend.tar - name: Download Docker Image (WebApp) uses: actions/download-artifact@v3 with: name: docker-webapp-production path: /tmp - - name: Load Docker Image - run: docker load < /tmp/webapp.tar + - run: docker load < /tmp/webapp.tar - name: Download Docker Image (Maintenance) uses: actions/download-artifact@v3 with: name: docker-maintenance-production path: /tmp - - name: Load Docker Image - run: docker load < /tmp/maintenance.tar - ########################################################################## - # Upload ################################################################# - ########################################################################## + - run: docker load < /tmp/maintenance.tar + - name: login to dockerhub run: echo "${DOCKERHUB_TOKEN}" | docker login -u "${DOCKERHUB_USERNAME}" --password-stdin - - name: Push neo4j - run: docker push --all-tags ocelotsocialnetwork/neo4j-community - - name: Push backend - run: docker push --all-tags ocelotsocialnetwork/backend - - name: Push webapp - run: docker push --all-tags ocelotsocialnetwork/webapp - - name: Push maintenance - run: docker push --all-tags ocelotsocialnetwork/maintenance - - ############################################################################## - # JOB: KUBERNETES DEPLOY ACTUAL/LATEST VERSION ###################################### - ############################################################################## - kubernetes_deploy: - # see example https://github.com/do-community/example-doctl-action - # see example https://github.com/do-community/example-doctl-action/blob/main/.github/workflows/workflow.yaml - name: Kubernetes deploy of latest version to stage.ocelot.social cluster at DigitalOcean - runs-on: ubuntu-latest - needs: [upload_to_dockerhub] - steps: - ########################################################################## - # CHECKOUT CODE ########################################################## - ########################################################################## - - name: Checkout code - uses: actions/checkout@v3 - ########################################################################## - # SET ENVS ############################################################### - ########################################################################## - - name: ENV - VERSION - run: echo "VERSION=$(node -p -e "require('./package.json').version")" >> $GITHUB_ENV - - name: ENV - BUILD_VERSION - run: echo "BUILD_VERSION=${VERSION}-${GITHUB_RUN_NUMBER}" >> $GITHUB_ENV - ########################################################################## - # Install DigitalOceans doctl and set kubeconfig ######################### - ########################################################################## - - name: Install doctl - uses: digitalocean/action-doctl@v2 - with: - token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} - - name: Save DigitalOcean kubeconfig with short-lived credentials - run: doctl kubernetes cluster kubeconfig save --expiry-seconds 600 cluster-stage-ocelot-social - ########################################################################## - # Deploy new Docker images to DigitalOcean Kubernetes cluster ############ - ########################################################################## - # - name: Deploy 'latest' to DigitalOcean Kubernetes - # run: | - # kubectl -n default set image deployment/ocelot-webapp container-ocelot-webapp=ocelotsocialnetwork/webapp:latest - # kubectl -n default rollout restart deployment/ocelot-webapp - # kubectl -n default set image deployment/ocelot-backend container-ocelot-backend=ocelotsocialnetwork/backend:latest - # kubectl -n default rollout restart deployment/ocelot-backend - # kubectl -n default set image deployment/ocelot-maintenance container-ocelot-maintenance=ocelotsocialnetwork/maintenance:latest - # kubectl -n default rollout restart deployment/ocelot-maintenance - # kubectl -n default set image deployment/ocelot-neo4j container-ocelot-neo4j=ocelotsocialnetwork/neo4j-community:latest - # kubectl -n default rollout restart deployment/ocelot-neo4j - - name: Deploy actual version '$BUILD_VERSION' to DigitalOcean Kubernetes + - name: Push images run: | - kubectl -n default set image deployment/ocelot-webapp container-ocelot-webapp=ocelotsocialnetwork/webapp:$BUILD_VERSION - kubectl -n default rollout restart deployment/ocelot-webapp - kubectl -n default set image deployment/ocelot-backend container-ocelot-backend=ocelotsocialnetwork/backend:$BUILD_VERSION - kubectl -n default rollout restart deployment/ocelot-backend - kubectl -n default set image deployment/ocelot-maintenance container-ocelot-maintenance=ocelotsocialnetwork/maintenance:$BUILD_VERSION - kubectl -n default rollout restart deployment/ocelot-maintenance - kubectl -n default set image deployment/ocelot-neo4j container-ocelot-neo4j=ocelotsocialnetwork/neo4j-community:$BUILD_VERSION - kubectl -n default rollout restart deployment/ocelot-neo4j - # because this step 'kubectl -n default rollout status deployment/* --timeout=600s' does not work as expected - # and we need the pods to be up again for cleaning and seeding the Neo4j database and the backend. - # !!! this is not a perfect solution !!! - # deployments are regularly up again after 3 minutes and 10 seconds - - name: Sleep for 4 minutes, means 240 seconds - run: sleep 240s - shell: bash - - name: Verify deployment and wait for the pods of each deployment to get ready for cleaning and seeding of the database - run: | - kubectl -n default rollout status deployment/ocelot-backend --timeout=600s - kubectl -n default rollout status deployment/ocelot-neo4j --timeout=600s - kubectl -n default rollout status deployment/ocelot-maintenance --timeout=600s - kubectl -n default rollout status deployment/ocelot-webapp --timeout=600s - - name: Run migrations for Neo4j database via backend for staging - run: | - kubectl -n default exec -it $(kubectl -n default get pods | grep ocelot-backend | awk '{ print $1 }') -- /bin/sh -c "yarn prod:migrate up" - - name: Reset and seed Neo4j database via backend for staging - # db cleaning and seeding is only possible in production if env 'PRODUCTION_DB_CLEAN_ALLOW=true' is set in deployment - run: | - kubectl -n default exec -it $(kubectl -n default get pods | grep ocelot-backend | awk '{ print $1 }') -- /bin/sh -c "node --experimental-repl-await dist/db/clean.js && node --experimental-repl-await dist/db/seed.js" + docker push --all-tags ocelotsocialnetwork/neo4j-community + docker push --all-tags ocelotsocialnetwork/backend + docker push --all-tags ocelotsocialnetwork/webapp + docker push --all-tags ocelotsocialnetwork/maintenance ############################################################################## # JOB: GITHUB TAG LATEST VERSION ############################################# @@ -331,39 +242,16 @@ jobs: runs-on: ubuntu-latest needs: [upload_to_dockerhub] steps: - ########################################################################## - # CHECKOUT CODE ########################################################## - ########################################################################## - name: Checkout code uses: actions/checkout@v3 with: fetch-depth: 0 # Fetch full History for changelog - ########################################################################## - # SET ENVS ############################################################### - ########################################################################## - - name: ENV - VERSION - run: echo "VERSION=$(node -p -e "require('./package.json').version")" >> $GITHUB_ENV - - name: ENV - BUILD_DATE - run: echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV - - name: ENV - BUILD_VERSION - run: echo "BUILD_VERSION=${VERSION}-${GITHUB_RUN_NUMBER}" >> $GITHUB_ENV - - name: ENV - BUILD_COMMIT - run: echo "BUILD_COMMIT=${GITHUB_SHA}" >> $GITHUB_ENV - ########################################################################## - # Push version tag to GitHub ############################################# - ########################################################################## - # TODO: this will error on duplicate - #- name: package-version-to-git-tag - # uses: pkgdeps/git-tag-action@v2 - # with: - # github_token: ${{ secrets.GITHUB_TOKEN }} - # github_repo: ${{ github.repository }} - # version: ${{ env.VERSION }} - # git_commit_sha: ${{ github.sha }} - # git_tag_prefix: "v" - ########################################################################## - # Push build tag to GitHub ############################################### - ########################################################################## + - name: Setup env + run: | + echo "VERSION=$(node -p -e "require('./package.json').version")" >> $GITHUB_ENV + echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV + echo "BUILD_COMMIT=${GITHUB_SHA}" >> $GITHUB_ENV + - run: echo "BUILD_VERSION=${VERSION}-${GITHUB_RUN_NUMBER}" >> $GITHUB_ENV - name: package-version-to-git-tag + build number uses: pkgdeps/git-tag-action@v2 with: @@ -372,13 +260,10 @@ jobs: version: ${{ env.BUILD_VERSION }} git_commit_sha: ${{ github.sha }} git_tag_prefix: "b" - ########################################################################## - # Push release tag to GitHub ############################################# - ########################################################################## - - name: yarn install - run: yarn install - - name: generate changelog - run: yarn auto-changelog --latest-version ${{ env.VERSION }} --unreleased-only + - name: Generate changelog + run: | + yarn install + yarn auto-changelog --latest-version ${{ env.VERSION }} --unreleased-only - name: package-version-to-git-release continue-on-error: true # Will fail if tag exists id: create_release @@ -391,3 +276,101 @@ jobs: body_path: ./CHANGELOG.md draft: false prerelease: false + + build_trigger: + name: Trigger successful build + runs-on: ubuntu-latest + needs: [github_tag] + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + fetch-depth: 0 # Fetch full History for changelog + - name: Setup env + run: | + echo "VERSION=$(node -p -e "require('./package.json').version")" >> $GITHUB_ENV + echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV + echo "BUILD_COMMIT=${GITHUB_SHA}" >> $GITHUB_ENV + - run: echo "BUILD_VERSION=${VERSION}-${GITHUB_RUN_NUMBER}" >> $GITHUB_ENV + - name: Repository Dispatch + uses: peter-evans/repository-dispatch@v1 + with: + token: ${{ github.token }} + event-type: trigger-build-success + repository: ${{ github.repository }} + client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}", "VERSION": "${VERSION}", "BUILD_DATE": "${BUILD_DATE}", "BUILD_COMMIT": "${BUILD_COMMIT}", "BUILD_VERSION": "${BUILD_VERSION}"}' + + # ############################################################################## + # # JOB: KUBERNETES DEPLOY ACTUAL/LATEST VERSION ###################################### + # ############################################################################## + # kubernetes_deploy: + # # see example https://github.com/do-community/example-doctl-action + # # see example https://github.com/do-community/example-doctl-action/blob/main/.github/workflows/workflow.yaml + # name: Kubernetes deploy of latest version to stage.ocelot.social cluster at DigitalOcean + # runs-on: ubuntu-latest + # needs: [upload_to_dockerhub] + # steps: + # ########################################################################## + # # CHECKOUT CODE ########################################################## + # ########################################################################## + # - name: Checkout code + # uses: actions/checkout@v3 + # ########################################################################## + # # SET ENVS ############################################################### + # ########################################################################## + # - name: ENV - VERSION + # run: echo "VERSION=$(node -p -e "require('./package.json').version")" >> $GITHUB_ENV + # - name: ENV - BUILD_VERSION + # run: echo "BUILD_VERSION=${VERSION}-${GITHUB_RUN_NUMBER}" >> $GITHUB_ENV + # ########################################################################## + # # Install DigitalOceans doctl and set kubeconfig ######################### + # ########################################################################## + # - name: Install doctl + # uses: digitalocean/action-doctl@v2 + # with: + # token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} + # - name: Save DigitalOcean kubeconfig with short-lived credentials + # run: doctl kubernetes cluster kubeconfig save --expiry-seconds 600 cluster-stage-ocelot-social + # ########################################################################## + # # Deploy new Docker images to DigitalOcean Kubernetes cluster ############ + # ########################################################################## + # # - name: Deploy 'latest' to DigitalOcean Kubernetes + # # run: | + # # kubectl -n default set image deployment/ocelot-webapp container-ocelot-webapp=ocelotsocialnetwork/webapp:latest + # # kubectl -n default rollout restart deployment/ocelot-webapp + # # kubectl -n default set image deployment/ocelot-backend container-ocelot-backend=ocelotsocialnetwork/backend:latest + # # kubectl -n default rollout restart deployment/ocelot-backend + # # kubectl -n default set image deployment/ocelot-maintenance container-ocelot-maintenance=ocelotsocialnetwork/maintenance:latest + # # kubectl -n default rollout restart deployment/ocelot-maintenance + # # kubectl -n default set image deployment/ocelot-neo4j container-ocelot-neo4j=ocelotsocialnetwork/neo4j-community:latest + # # kubectl -n default rollout restart deployment/ocelot-neo4j + # - name: Deploy actual version '$BUILD_VERSION' to DigitalOcean Kubernetes + # run: | + # kubectl -n default set image deployment/ocelot-webapp container-ocelot-webapp=ocelotsocialnetwork/webapp:$BUILD_VERSION + # kubectl -n default rollout restart deployment/ocelot-webapp + # kubectl -n default set image deployment/ocelot-backend container-ocelot-backend=ocelotsocialnetwork/backend:$BUILD_VERSION + # kubectl -n default rollout restart deployment/ocelot-backend + # kubectl -n default set image deployment/ocelot-maintenance container-ocelot-maintenance=ocelotsocialnetwork/maintenance:$BUILD_VERSION + # kubectl -n default rollout restart deployment/ocelot-maintenance + # kubectl -n default set image deployment/ocelot-neo4j container-ocelot-neo4j=ocelotsocialnetwork/neo4j-community:$BUILD_VERSION + # kubectl -n default rollout restart deployment/ocelot-neo4j + # # because this step 'kubectl -n default rollout status deployment/* --timeout=600s' does not work as expected + # # and we need the pods to be up again for cleaning and seeding the Neo4j database and the backend. + # # !!! this is not a perfect solution !!! + # # deployments are regularly up again after 3 minutes and 10 seconds + # - name: Sleep for 4 minutes, means 240 seconds + # run: sleep 240s + # shell: bash + # - name: Verify deployment and wait for the pods of each deployment to get ready for cleaning and seeding of the database + # run: | + # kubectl -n default rollout status deployment/ocelot-backend --timeout=600s + # kubectl -n default rollout status deployment/ocelot-neo4j --timeout=600s + # kubectl -n default rollout status deployment/ocelot-maintenance --timeout=600s + # kubectl -n default rollout status deployment/ocelot-webapp --timeout=600s + # - name: Run migrations for Neo4j database via backend for staging + # run: | + # kubectl -n default exec -it $(kubectl -n default get pods | grep ocelot-backend | awk '{ print $1 }') -- /bin/sh -c "yarn prod:migrate up" + # - name: Reset and seed Neo4j database via backend for staging + # # db cleaning and seeding is only possible in production if env 'PRODUCTION_DB_CLEAN_ALLOW=true' is set in deployment + # run: | + # kubectl -n default exec -it $(kubectl -n default get pods | grep ocelot-backend | awk '{ print $1 }') -- /bin/sh -c "node --experimental-repl-await dist/db/clean.js && node --experimental-repl-await dist/db/seed.js" \ No newline at end of file diff --git a/backend/src/helpers/jest.js b/backend/src/helpers/jest.js index e3f6a3c84..09744e9f2 100644 --- a/backend/src/helpers/jest.js +++ b/backend/src/helpers/jest.js @@ -1,13 +1,3 @@ -// TODO: can be replaced with: (which is no a fake) -// import gql from 'graphql-tag' -// See issue: https://github.com/Ocelot-Social-Community/Ocelot-Social/issues/5152 - -//* This is a fake ES2015 template string, just to benefit of syntax -// highlighting of `gql` template strings in certain editors. -export function gql(strings) { - return strings.join('') -} - // sometime we have to wait to check a db state by having a look into the db in a certain moment // or we wait a bit to check if we missed to set an await somewhere // see: https://www.sitepoint.com/delay-sleep-pause-wait/ diff --git a/backend/src/middleware/hashtags/hashtagsMiddleware.spec.js b/backend/src/middleware/hashtags/hashtagsMiddleware.spec.js index bcecee73b..10d53ab7b 100644 --- a/backend/src/middleware/hashtags/hashtagsMiddleware.spec.js +++ b/backend/src/middleware/hashtags/hashtagsMiddleware.spec.js @@ -1,4 +1,4 @@ -import { gql } from '../../helpers/jest' +import gql from 'graphql-tag' import { cleanDatabase } from '../../db/factories' import { createTestClient } from 'apollo-server-testing' import { getNeode, getDriver } from '../../db/neo4j' diff --git a/backend/src/middleware/languages/languages.spec.js b/backend/src/middleware/languages/languages.spec.js index 99e87152e..f4f57adc4 100644 --- a/backend/src/middleware/languages/languages.spec.js +++ b/backend/src/middleware/languages/languages.spec.js @@ -1,5 +1,5 @@ import Factory, { cleanDatabase } from '../../db/factories' -import { gql } from '../../helpers/jest' +import gql from 'graphql-tag' import { getNeode, getDriver } from '../../db/neo4j' import createServer from '../../server' import { createTestClient } from 'apollo-server-testing' diff --git a/backend/src/middleware/notifications/notificationsMiddleware.spec.js b/backend/src/middleware/notifications/notificationsMiddleware.spec.js index ad7fd3f8c..a8a5d396b 100644 --- a/backend/src/middleware/notifications/notificationsMiddleware.spec.js +++ b/backend/src/middleware/notifications/notificationsMiddleware.spec.js @@ -1,4 +1,4 @@ -import { gql } from '../../helpers/jest' +import gql from 'graphql-tag' import { cleanDatabase } from '../../db/factories' import { createTestClient } from 'apollo-server-testing' import { getNeode, getDriver } from '../../db/neo4j' diff --git a/backend/src/middleware/orderByMiddleware.spec.js b/backend/src/middleware/orderByMiddleware.spec.js index 1aef1c52a..7453cf301 100644 --- a/backend/src/middleware/orderByMiddleware.spec.js +++ b/backend/src/middleware/orderByMiddleware.spec.js @@ -1,4 +1,4 @@ -import { gql } from '../helpers/jest' +import gql from 'graphql-tag' import { cleanDatabase } from '../db/factories' import { getNeode, getDriver } from '../db/neo4j' import { createTestClient } from 'apollo-server-testing' diff --git a/backend/src/middleware/permissionsMiddleware.spec.js b/backend/src/middleware/permissionsMiddleware.spec.js index 35a2ab82b..667e74164 100644 --- a/backend/src/middleware/permissionsMiddleware.spec.js +++ b/backend/src/middleware/permissionsMiddleware.spec.js @@ -1,7 +1,7 @@ import { createTestClient } from 'apollo-server-testing' import createServer from '../server' import Factory, { cleanDatabase } from '../db/factories' -import { gql } from '../helpers/jest' +import gql from 'graphql-tag' import { getDriver, getNeode } from '../db/neo4j' import CONFIG from '../config' diff --git a/backend/src/middleware/softDelete/softDeleteMiddleware.spec.js b/backend/src/middleware/softDelete/softDeleteMiddleware.spec.js index 7e14cad1f..88d46a1c7 100644 --- a/backend/src/middleware/softDelete/softDeleteMiddleware.spec.js +++ b/backend/src/middleware/softDelete/softDeleteMiddleware.spec.js @@ -1,5 +1,5 @@ import Factory, { cleanDatabase } from '../../db/factories' -import { gql } from '../../helpers/jest' +import gql from 'graphql-tag' import { getNeode, getDriver } from '../../db/neo4j' import createServer from '../../server' import { createTestClient } from 'apollo-server-testing' diff --git a/backend/src/middleware/userInteractions.spec.js b/backend/src/middleware/userInteractions.spec.js index 2f97bda5a..94d1ff274 100644 --- a/backend/src/middleware/userInteractions.spec.js +++ b/backend/src/middleware/userInteractions.spec.js @@ -1,5 +1,5 @@ import Factory, { cleanDatabase } from '../db/factories' -import { gql } from '../helpers/jest' +import gql from 'graphql-tag' import { getNeode, getDriver } from '../db/neo4j' import createServer from '../server' import { createTestClient } from 'apollo-server-testing' diff --git a/backend/src/middleware/validation/validationMiddleware.spec.js b/backend/src/middleware/validation/validationMiddleware.spec.js index a887832c1..2e1cd6fa7 100644 --- a/backend/src/middleware/validation/validationMiddleware.spec.js +++ b/backend/src/middleware/validation/validationMiddleware.spec.js @@ -1,4 +1,4 @@ -import { gql } from '../../helpers/jest' +import gql from 'graphql-tag' import Factory, { cleanDatabase } from '../../db/factories' import { getNeode, getDriver } from '../../db/neo4j' import { createTestClient } from 'apollo-server-testing' diff --git a/backend/src/schema/resolvers/comments.spec.js b/backend/src/schema/resolvers/comments.spec.js index 09487082e..b2730dad4 100644 --- a/backend/src/schema/resolvers/comments.spec.js +++ b/backend/src/schema/resolvers/comments.spec.js @@ -1,5 +1,5 @@ import Factory, { cleanDatabase } from '../../db/factories' -import { gql } from '../../helpers/jest' +import gql from 'graphql-tag' import { createTestClient } from 'apollo-server-testing' import createServer from '../../server' import { getNeode, getDriver } from '../../db/neo4j' diff --git a/backend/src/schema/resolvers/donations.spec.js b/backend/src/schema/resolvers/donations.spec.js index 5a2bcfd7b..9fc010eca 100644 --- a/backend/src/schema/resolvers/donations.spec.js +++ b/backend/src/schema/resolvers/donations.spec.js @@ -1,6 +1,6 @@ import { createTestClient } from 'apollo-server-testing' import Factory, { cleanDatabase } from '../../db/factories' -import { gql } from '../../helpers/jest' +import gql from 'graphql-tag' import { getNeode, getDriver } from '../../db/neo4j' import createServer from '../../server' diff --git a/backend/src/schema/resolvers/emails.spec.js b/backend/src/schema/resolvers/emails.spec.js index 4778e3fcf..02a631495 100644 --- a/backend/src/schema/resolvers/emails.spec.js +++ b/backend/src/schema/resolvers/emails.spec.js @@ -1,5 +1,5 @@ import Factory, { cleanDatabase } from '../../db/factories' -import { gql } from '../../helpers/jest' +import gql from 'graphql-tag' import { getDriver, getNeode } from '../../db/neo4j' import createServer from '../../server' import { createTestClient } from 'apollo-server-testing' diff --git a/backend/src/schema/resolvers/embeds.spec.js b/backend/src/schema/resolvers/embeds.spec.js index 347825f3a..0f0d41357 100644 --- a/backend/src/schema/resolvers/embeds.spec.js +++ b/backend/src/schema/resolvers/embeds.spec.js @@ -3,7 +3,7 @@ import fs from 'fs' import path from 'path' import { createTestClient } from 'apollo-server-testing' import createServer from '../../server' -import { gql } from '../../helpers/jest' +import gql from 'graphql-tag' jest.mock('node-fetch') const { Response } = jest.requireActual('node-fetch') diff --git a/backend/src/schema/resolvers/follow.spec.js b/backend/src/schema/resolvers/follow.spec.js index 14d8a366d..0d9d524ff 100644 --- a/backend/src/schema/resolvers/follow.spec.js +++ b/backend/src/schema/resolvers/follow.spec.js @@ -2,7 +2,7 @@ import { createTestClient } from 'apollo-server-testing' import Factory, { cleanDatabase } from '../../db/factories' import { getDriver, getNeode } from '../../db/neo4j' import createServer from '../../server' -import { gql } from '../../helpers/jest' +import gql from 'graphql-tag' const driver = getDriver() const neode = getNeode() diff --git a/backend/src/schema/resolvers/helpers/filterPostsOfMyGroups.js b/backend/src/schema/resolvers/helpers/filterPostsOfMyGroups.js new file mode 100644 index 000000000..a808a5582 --- /dev/null +++ b/backend/src/schema/resolvers/helpers/filterPostsOfMyGroups.js @@ -0,0 +1,40 @@ +import { mergeWith, isArray } from 'lodash' + +const getMyGroupIds = async (context) => { + const { user } = context + if (!(user && user.id)) return [] + const session = context.driver.session() + + const readTxResultPromise = await session.readTransaction(async (transaction) => { + const cypher = ` + MATCH (group:Group)<-[membership:MEMBER_OF]-(:User { id: $userId }) + WHERE membership.role IN ['usual', 'admin', 'owner'] + RETURN collect(group.id) AS myGroupIds` + const getMyGroupIdsResponse = await transaction.run(cypher, { userId: user.id }) + return getMyGroupIdsResponse.records.map((record) => record.get('myGroupIds')) + }) + try { + const [myGroupIds] = readTxResultPromise + return myGroupIds + } finally { + session.close() + } +} + +export const filterPostsOfMyGroups = async (params, context) => { + if (!(params.filter && params.filter.postsInMyGroups)) return params + delete params.filter.postsInMyGroups + const myGroupIds = await getMyGroupIds(context) + params.filter = mergeWith( + params.filter, + { + group: { id_in: myGroupIds }, + }, + (objValue, srcValue) => { + if (isArray(objValue)) { + return objValue.concat(srcValue) + } + }, + ) + return params +} diff --git a/backend/src/schema/resolvers/inviteCodes.spec.js b/backend/src/schema/resolvers/inviteCodes.spec.js index b55ab079b..1df791ba6 100644 --- a/backend/src/schema/resolvers/inviteCodes.spec.js +++ b/backend/src/schema/resolvers/inviteCodes.spec.js @@ -1,6 +1,6 @@ import Factory, { cleanDatabase } from '../../db/factories' import { getDriver } from '../../db/neo4j' -import { gql } from '../../helpers/jest' +import gql from 'graphql-tag' import createServer from '../../server' import { createTestClient } from 'apollo-server-testing' import CONSTANTS_REGISTRATION from './../../constants/registration' diff --git a/backend/src/schema/resolvers/locations.spec.js b/backend/src/schema/resolvers/locations.spec.js index 87542cf6d..82aebd441 100644 --- a/backend/src/schema/resolvers/locations.spec.js +++ b/backend/src/schema/resolvers/locations.spec.js @@ -1,5 +1,5 @@ import Factory, { cleanDatabase } from '../../db/factories' -import { gql } from '../../helpers/jest' +import gql from 'graphql-tag' import { getNeode, getDriver } from '../../db/neo4j' import createServer from '../../server' import { createTestClient } from 'apollo-server-testing' diff --git a/backend/src/schema/resolvers/moderation.spec.js b/backend/src/schema/resolvers/moderation.spec.js index 9f5014756..1665e9446 100644 --- a/backend/src/schema/resolvers/moderation.spec.js +++ b/backend/src/schema/resolvers/moderation.spec.js @@ -1,6 +1,6 @@ import { createTestClient } from 'apollo-server-testing' import Factory, { cleanDatabase } from '../../db/factories' -import { gql } from '../../helpers/jest' +import gql from 'graphql-tag' import { getNeode, getDriver } from '../../db/neo4j' import createServer from '../../server' diff --git a/backend/src/schema/resolvers/notifications.spec.js b/backend/src/schema/resolvers/notifications.spec.js index 82d6e6371..36bd530eb 100644 --- a/backend/src/schema/resolvers/notifications.spec.js +++ b/backend/src/schema/resolvers/notifications.spec.js @@ -1,5 +1,5 @@ import Factory, { cleanDatabase } from '../../db/factories' -import { gql } from '../../helpers/jest' +import gql from 'graphql-tag' import { getDriver } from '../../db/neo4j' import { createTestClient } from 'apollo-server-testing' import createServer from '../.././server' diff --git a/backend/src/schema/resolvers/passwordReset.spec.js b/backend/src/schema/resolvers/passwordReset.spec.js index 90c570f5a..fa5f26e58 100644 --- a/backend/src/schema/resolvers/passwordReset.spec.js +++ b/backend/src/schema/resolvers/passwordReset.spec.js @@ -1,5 +1,5 @@ import Factory, { cleanDatabase } from '../../db/factories' -import { gql } from '../../helpers/jest' +import gql from 'graphql-tag' import { getNeode, getDriver } from '../../db/neo4j' import CONSTANTS_REGISTRATION from './../../constants/registration' import createPasswordReset from './helpers/createPasswordReset' diff --git a/backend/src/schema/resolvers/posts.js b/backend/src/schema/resolvers/posts.js index 78515e641..d806f3803 100644 --- a/backend/src/schema/resolvers/posts.js +++ b/backend/src/schema/resolvers/posts.js @@ -6,6 +6,7 @@ import { mergeImage, deleteImage } from './images/images' import Resolver from './helpers/Resolver' import { filterForMutedUsers } from './helpers/filterForMutedUsers' import { filterInvisiblePosts } from './helpers/filterInvisiblePosts' +import { filterPostsOfMyGroups } from './helpers/filterPostsOfMyGroups' import CONFIG from '../../config' const maintainPinnedPosts = (params) => { @@ -21,12 +22,14 @@ const maintainPinnedPosts = (params) => { export default { Query: { Post: async (object, params, context, resolveInfo) => { + params = await filterPostsOfMyGroups(params, context) params = await filterInvisiblePosts(params, context) params = await filterForMutedUsers(params, context) params = await maintainPinnedPosts(params) return neo4jgraphql(object, params, context, resolveInfo) }, profilePagePosts: async (object, params, context, resolveInfo) => { + params = await filterPostsOfMyGroups(params, context) params = await filterInvisiblePosts(params, context) params = await filterForMutedUsers(params, context) return neo4jgraphql(object, params, context, resolveInfo) diff --git a/backend/src/schema/resolvers/posts.spec.js b/backend/src/schema/resolvers/posts.spec.js index 7a0dc0176..9335c1313 100644 --- a/backend/src/schema/resolvers/posts.spec.js +++ b/backend/src/schema/resolvers/posts.spec.js @@ -1,6 +1,6 @@ import { createTestClient } from 'apollo-server-testing' import Factory, { cleanDatabase } from '../../db/factories' -import { gql } from '../../helpers/jest' +import gql from 'graphql-tag' import { getNeode, getDriver } from '../../db/neo4j' import createServer from '../../server' diff --git a/backend/src/schema/resolvers/postsInGroups.spec.js b/backend/src/schema/resolvers/postsInGroups.spec.js index 5bf5820f0..1eaf7a708 100644 --- a/backend/src/schema/resolvers/postsInGroups.spec.js +++ b/backend/src/schema/resolvers/postsInGroups.spec.js @@ -1678,5 +1678,59 @@ describe('Posts in Groups', () => { }) }) }) + + describe('filter posts in my groups', () => { + describe('without any posts in groups', () => { + beforeAll(async () => { + authenticatedUser = await anyUser.toJson() + }) + + it('finds no posts', async () => { + const result = await query({ + query: filterPosts(), + variables: { filter: { postsInMyGroups: true } }, + }) + expect(result.data.Post).toHaveLength(0) + expect(result).toMatchObject({ + data: { + Post: [], + }, + errors: undefined, + }) + }) + }) + + describe('with posts in groups', () => { + beforeAll(async () => { + // member of hidden-group and closed-group + authenticatedUser = await allGroupsUser.toJson() + }) + + it('finds two posts', async () => { + const result = await query({ + query: filterPosts(), + variables: { filter: { postsInMyGroups: true } }, + }) + expect(result.data.Post).toHaveLength(2) + expect(result).toMatchObject({ + data: { + Post: expect.arrayContaining([ + { + id: 'post-to-closed-group', + title: 'A post to a closed group', + content: 'I am posting into a closed group as a member of the group', + }, + { + id: 'post-to-hidden-group', + title: 'A post to a hidden group', + content: 'I am posting into a hidden group as a member of the group', + }, + ]), + }, + errors: undefined, + }) + }) + }) + }) }) }) diff --git a/backend/src/schema/resolvers/registration.spec.js b/backend/src/schema/resolvers/registration.spec.js index ae6bcb7d7..bfc6a5fa6 100644 --- a/backend/src/schema/resolvers/registration.spec.js +++ b/backend/src/schema/resolvers/registration.spec.js @@ -1,5 +1,5 @@ import Factory, { cleanDatabase } from '../../db/factories' -import { gql } from '../../helpers/jest' +import gql from 'graphql-tag' import { getDriver, getNeode } from '../../db/neo4j' import createServer from '../../server' import { createTestClient } from 'apollo-server-testing' diff --git a/backend/src/schema/resolvers/reports.spec.js b/backend/src/schema/resolvers/reports.spec.js index 449bdb3a7..96ef07d03 100644 --- a/backend/src/schema/resolvers/reports.spec.js +++ b/backend/src/schema/resolvers/reports.spec.js @@ -1,7 +1,7 @@ import { createTestClient } from 'apollo-server-testing' import createServer from '../.././server' import Factory, { cleanDatabase } from '../../db/factories' -import { gql } from '../../helpers/jest' +import gql from 'graphql-tag' import { getDriver, getNeode } from '../../db/neo4j' const instance = getNeode() diff --git a/backend/src/schema/resolvers/rewards.spec.js b/backend/src/schema/resolvers/rewards.spec.js index 108973c9c..06fe87ec0 100644 --- a/backend/src/schema/resolvers/rewards.spec.js +++ b/backend/src/schema/resolvers/rewards.spec.js @@ -1,6 +1,6 @@ import { createTestClient } from 'apollo-server-testing' import Factory, { cleanDatabase } from '../../db/factories' -import { gql } from '../../helpers/jest' +import gql from 'graphql-tag' import { getNeode, getDriver } from '../../db/neo4j' import createServer from '../../server' diff --git a/backend/src/schema/resolvers/searches.spec.js b/backend/src/schema/resolvers/searches.spec.js index 7c1a5a254..f889c2ac8 100644 --- a/backend/src/schema/resolvers/searches.spec.js +++ b/backend/src/schema/resolvers/searches.spec.js @@ -1,5 +1,5 @@ import Factory, { cleanDatabase } from '../../db/factories' -import { gql } from '../../helpers/jest' +import gql from 'graphql-tag' import { getNeode, getDriver } from '../../db/neo4j' import createServer from '../../server' import { createTestClient } from 'apollo-server-testing' diff --git a/backend/src/schema/resolvers/shout.spec.js b/backend/src/schema/resolvers/shout.spec.js index f774d7d0b..294a28a76 100644 --- a/backend/src/schema/resolvers/shout.spec.js +++ b/backend/src/schema/resolvers/shout.spec.js @@ -1,6 +1,6 @@ import { createTestClient } from 'apollo-server-testing' import Factory, { cleanDatabase } from '../../db/factories' -import { gql } from '../../helpers/jest' +import gql from 'graphql-tag' import { getNeode, getDriver } from '../../db/neo4j' import createServer from '../../server' diff --git a/backend/src/schema/resolvers/socialMedia.spec.js b/backend/src/schema/resolvers/socialMedia.spec.js index dafbed6d6..8265e8376 100644 --- a/backend/src/schema/resolvers/socialMedia.spec.js +++ b/backend/src/schema/resolvers/socialMedia.spec.js @@ -1,7 +1,7 @@ import { createTestClient } from 'apollo-server-testing' import createServer from '../../server' import Factory, { cleanDatabase } from '../../db/factories' -import { gql } from '../../helpers/jest' +import gql from 'graphql-tag' import { getDriver } from '../../db/neo4j' const driver = getDriver() diff --git a/backend/src/schema/resolvers/statistics.spec.js b/backend/src/schema/resolvers/statistics.spec.js index 46330ef9a..15aa2d449 100644 --- a/backend/src/schema/resolvers/statistics.spec.js +++ b/backend/src/schema/resolvers/statistics.spec.js @@ -1,6 +1,6 @@ import { createTestClient } from 'apollo-server-testing' import Factory, { cleanDatabase } from '../../db/factories' -import { gql } from '../../helpers/jest' +import gql from 'graphql-tag' import { getNeode, getDriver } from '../../db/neo4j' import createServer from '../../server' diff --git a/backend/src/schema/resolvers/userData.spec.js b/backend/src/schema/resolvers/userData.spec.js index ee4901f0a..3c521a4f1 100644 --- a/backend/src/schema/resolvers/userData.spec.js +++ b/backend/src/schema/resolvers/userData.spec.js @@ -1,5 +1,5 @@ import Factory, { cleanDatabase } from '../../db/factories' -import { gql } from '../../helpers/jest' +import gql from 'graphql-tag' import { getNeode, getDriver } from '../../db/neo4j' import createServer from '../../server' import { createTestClient } from 'apollo-server-testing' diff --git a/backend/src/schema/resolvers/user_management.spec.js b/backend/src/schema/resolvers/user_management.spec.js index a249d7500..546c7a748 100644 --- a/backend/src/schema/resolvers/user_management.spec.js +++ b/backend/src/schema/resolvers/user_management.spec.js @@ -1,7 +1,7 @@ import jwt from 'jsonwebtoken' import CONFIG from './../../config' import Factory, { cleanDatabase } from '../../db/factories' -import { gql } from '../../helpers/jest' +import gql from 'graphql-tag' import { loginMutation } from '../../graphql/userManagement' import { createTestClient } from 'apollo-server-testing' import createServer, { context } from '../../server' diff --git a/backend/src/schema/resolvers/users.spec.js b/backend/src/schema/resolvers/users.spec.js index 9b7699dc1..f256c6363 100644 --- a/backend/src/schema/resolvers/users.spec.js +++ b/backend/src/schema/resolvers/users.spec.js @@ -1,5 +1,5 @@ import Factory, { cleanDatabase } from '../../db/factories' -import { gql } from '../../helpers/jest' +import gql from 'graphql-tag' import { getNeode, getDriver } from '../../db/neo4j' import createServer from '../../server' import { createTestClient } from 'apollo-server-testing' diff --git a/backend/src/schema/resolvers/users/location.spec.js b/backend/src/schema/resolvers/users/location.spec.js index 73938c41a..7097002da 100644 --- a/backend/src/schema/resolvers/users/location.spec.js +++ b/backend/src/schema/resolvers/users/location.spec.js @@ -1,4 +1,4 @@ -import { gql } from '../../../helpers/jest' +import gql from 'graphql-tag' import Factory, { cleanDatabase } from '../../../db/factories' import { getNeode, getDriver } from '../../../db/neo4j' import { createTestClient } from 'apollo-server-testing' diff --git a/backend/src/schema/resolvers/users/mutedUsers.spec.js b/backend/src/schema/resolvers/users/mutedUsers.spec.js index 5c1a7dd5d..20e37f627 100644 --- a/backend/src/schema/resolvers/users/mutedUsers.spec.js +++ b/backend/src/schema/resolvers/users/mutedUsers.spec.js @@ -1,7 +1,7 @@ import { createTestClient } from 'apollo-server-testing' import createServer from '../../../server' import { cleanDatabase } from '../../../db/factories' -import { gql } from '../../../helpers/jest' +import gql from 'graphql-tag' import { getNeode, getDriver } from '../../../db/neo4j' const driver = getDriver() diff --git a/backend/src/schema/resolvers/viewedTeaserCount.spec.js b/backend/src/schema/resolvers/viewedTeaserCount.spec.js index d7437646b..ee90d1a08 100644 --- a/backend/src/schema/resolvers/viewedTeaserCount.spec.js +++ b/backend/src/schema/resolvers/viewedTeaserCount.spec.js @@ -1,6 +1,6 @@ import { createTestClient } from 'apollo-server-testing' import Factory, { cleanDatabase } from '../../db/factories' -import { gql } from '../../helpers/jest' +import gql from 'graphql-tag' import { getNeode, getDriver } from '../../db/neo4j' import createServer from '../../server' diff --git a/backend/src/schema/types/type/Post.gql b/backend/src/schema/types/type/Post.gql index 9eac00b0b..6fc7a3215 100644 --- a/backend/src/schema/types/type/Post.gql +++ b/backend/src/schema/types/type/Post.gql @@ -82,6 +82,7 @@ input _PostFilter { emotions_single: _PostEMOTEDFilter emotions_every: _PostEMOTEDFilter group: _GroupFilter + postsInMyGroups: Boolean } enum _PostOrdering { diff --git a/cypress/integration/Moderation.ReportContent/somebody_reported_the_following_posts.js b/cypress/integration/Moderation.ReportContent/somebody_reported_the_following_posts.js index ce876a081..3ca39e6e6 100644 --- a/cypress/integration/Moderation.ReportContent/somebody_reported_the_following_posts.js +++ b/cypress/integration/Moderation.ReportContent/somebody_reported_the_following_posts.js @@ -1,5 +1,4 @@ import { Given } from "cypress-cucumber-preprocessor/steps"; -import { gql } from '../../../backend/src/helpers/jest' Given('somebody reported the following posts:', table => { table.hashes().forEach(({ submitterEmail, resourceId, reasonCategory, reasonDescription }) => { @@ -10,7 +9,7 @@ Given('somebody reported the following posts:', table => { cy.factory() .build('user', {}, submitter) .authenticateAs(submitter) - .mutate(gql`mutation($resourceId: ID!, $reasonCategory: ReasonCategory!, $reasonDescription: String!) { + .mutate(`mutation($resourceId: ID!, $reasonCategory: ReasonCategory!, $reasonDescription: String!) { fileReport(resourceId: $resourceId, reasonCategory: $reasonCategory, reasonDescription: $reasonDescription) { reportId } diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 335e00390..7d3738a3d 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -15,11 +15,10 @@ /* globals Cypress cy */ import "cypress-file-upload"; import { GraphQLClient, request } from 'graphql-request' -import { gql } from '../../backend/src/helpers/jest' import config from '../../backend/src/config' const authenticatedHeaders = (variables) => { - const mutation = gql` + const mutation = ` mutation($email: String!, $password: String!) { login(email: $email, password: $password) } diff --git a/webapp/components/FilterMenu/FollowingFilter.spec.js b/webapp/components/FilterMenu/FollowingFilter.spec.js index 4d4a827e5..0f51b305c 100644 --- a/webapp/components/FilterMenu/FollowingFilter.spec.js +++ b/webapp/components/FilterMenu/FollowingFilter.spec.js @@ -9,12 +9,14 @@ let wrapper describe('FollowingFilter', () => { const mutations = { 'posts/TOGGLE_FILTER_BY_FOLLOWED': jest.fn(), + 'posts/TOGGLE_FILTER_BY_MY_GROUPS': jest.fn(), } const getters = { 'auth/user': () => { return { id: 'u34' } }, 'posts/filteredByUsersFollowed': jest.fn(), + 'posts/filteredByPostsInMyGroups': jest.fn(), } const mocks = { @@ -34,12 +36,18 @@ describe('FollowingFilter', () => { describe('mount', () => { it('sets "filter-by-followed" button attribute `filled`', () => { getters['posts/filteredByUsersFollowed'] = jest.fn(() => true) + getters['posts/filteredByPostsInMyGroups'] = jest.fn(() => true) const wrapper = Wrapper() expect( wrapper .find('.following-filter .filter-list .follower-item .base-button') .classes('--filled'), ).toBe(true) + expect( + wrapper + .find('.following-filter .filter-list .posts-in-my-groups-item .base-button') + .classes('--filled'), + ).toBe(true) }) describe('click "filter-by-followed" button', () => { @@ -48,5 +56,14 @@ describe('FollowingFilter', () => { expect(mutations['posts/TOGGLE_FILTER_BY_FOLLOWED']).toHaveBeenCalledWith({}, 'u34') }) }) + + describe('click "filter-by-my-groups" button', () => { + it('calls TOGGLE_FILTER_BY_MY_GROUPS', () => { + wrapper + .find('.following-filter .filter-list .posts-in-my-groups-item .base-button') + .trigger('click') + expect(mutations['posts/TOGGLE_FILTER_BY_MY_GROUPS']).toHaveBeenCalled() + }) + }) }) }) diff --git a/webapp/components/FilterMenu/FollowingFilter.vue b/webapp/components/FilterMenu/FollowingFilter.vue index 7c2c2a282..9a488acd6 100644 --- a/webapp/components/FilterMenu/FollowingFilter.vue +++ b/webapp/components/FilterMenu/FollowingFilter.vue @@ -10,6 +10,15 @@ @click="toggleFilteredByFollowed(currentUser.id)" /> +
  • + +
  • @@ -28,12 +37,14 @@ export default { computed: { ...mapGetters({ filteredByUsersFollowed: 'posts/filteredByUsersFollowed', + filteredByPostsInMyGroups: 'posts/filteredByPostsInMyGroups', currentUser: 'auth/user', }), }, methods: { ...mapMutations({ toggleFilteredByFollowed: 'posts/TOGGLE_FILTER_BY_FOLLOWED', + toggleFilteredByMyGroups: 'posts/TOGGLE_FILTER_BY_MY_GROUPS', }), }, } diff --git a/webapp/locales/de.json b/webapp/locales/de.json index 9ea733068..1db5a3dcd 100644 --- a/webapp/locales/de.json +++ b/webapp/locales/de.json @@ -270,9 +270,11 @@ "filterFollow": "Beiträge von Nutzern filtern, denen ich folge", "filterMasonryGrid": { "myFriends": "Nutzer denen ich folge", + "myGroups": "Meine Gruppen", "myTopics": "Meine Themen", "noFilter": "Beiträge filtern" }, + "filterMyGroups": "Beiträge in meinen Gruppen", "inappropriatePicture": "Dieses Bild kann für einige Menschen unangemessen sein.", "languageSelectLabel": "Sprache Deines Beitrags", "languageSelectText": "Sprache wählen", @@ -380,6 +382,7 @@ "filter-by": "Filtern nach ...", "following": "Nutzer denen ich folge", "languages": "Sprachen", + "my-groups": "Meinen Gruppen", "order": { "newest": { "hint": "Sortiere die Neuesten nach vorn", diff --git a/webapp/locales/en.json b/webapp/locales/en.json index 9e45396b8..f7a7a54ad 100644 --- a/webapp/locales/en.json +++ b/webapp/locales/en.json @@ -270,9 +270,11 @@ "filterFollow": "Filter contributions from users I follow", "filterMasonryGrid": { "myFriends": "Users I follow", + "myGroups": "My groups", "myTopics": "My topics", "noFilter": "Filter posts" }, + "filterMyGroups": "Contributions in my groups", "inappropriatePicture": "This image may be inappropriate for some people.", "languageSelectLabel": "Language of your contribution", "languageSelectText": "Select Language", @@ -380,6 +382,7 @@ "filter-by": "Filter by ...", "following": "Users I follow", "languages": "Languages", + "my-groups": "My groups", "order": { "newest": { "hint": "Sort posts by the newest first", diff --git a/webapp/pages/index.vue b/webapp/pages/index.vue index d5f1ac3d0..ddadec9a8 100644 --- a/webapp/pages/index.vue +++ b/webapp/pages/index.vue @@ -30,7 +30,11 @@
    + + + {{ $t('contribution.filterMasonryGrid.myGroups') }} + + + +
    @@ -203,6 +221,7 @@ export default { methods: { ...mapMutations({ resetByFollowed: 'posts/TOGGLE_FILTER_BY_FOLLOWED', + resetByGroups: 'posts/TOGGLE_FILTER_BY_MY_GROUPS', resetCategories: 'posts/RESET_CATEGORIES', toggleCategory: 'posts/TOGGLE_CATEGORY', }), diff --git a/webapp/store/posts.js b/webapp/store/posts.js index 5d9891eff..587867b0e 100644 --- a/webapp/store/posts.js +++ b/webapp/store/posts.js @@ -30,6 +30,18 @@ export const mutations = { } } }, + TOGGLE_FILTER_BY_MY_GROUPS(state) { + const filter = clone(state.filter) + if (get(filter, 'postsInMyGroups')) { + delete filter.postsInMyGroups + state.filter = filter + } else { + state.filter = { + ...filter, + postsInMyGroups: true, + } + } + }, RESET_CATEGORIES(state) { const filter = clone(state.filter) delete filter.categories_some @@ -84,6 +96,9 @@ export const getters = { filteredByUsersFollowed(state) { return !!get(state.filter, 'author.followedBy_some.id') }, + filteredByPostsInMyGroups(state) { + return !!get(state.filter, 'postsInMyGroups') + }, filteredByEmotions(state) { return get(state.filter, 'emotions_some.emotion_in') || [] }, diff --git a/webapp/store/posts.spec.js b/webapp/store/posts.spec.js index ed728bdd8..665b147ae 100644 --- a/webapp/store/posts.spec.js +++ b/webapp/store/posts.spec.js @@ -56,6 +56,18 @@ describe('getters', () => { }) }) + describe('filteredByPostsInMyGroups', () => { + it('returns true if filter is set', () => { + state = { filter: { postsInMyGroups: true } } + expect(getters.filteredByPostsInMyGroups(state)).toBe(true) + }) + + it('returns false if filter is not set', () => { + state = { filter: { categories_some: { id_in: [23] } } } + expect(getters.filteredByUsersFollowed(state)).toBe(false) + }) + }) + describe('filteredByEmotions', () => { it('returns an emotions array if filter is set', () => { state = { filter: { emotions_some: { emotion_in: ['sad'] } } } @@ -230,6 +242,35 @@ describe('mutations', () => { }) }) + describe('TOGGLE_FILTER_BY_MY_GROUPS', () => { + beforeEach(() => { + testMutation = () => { + mutations.TOGGLE_FILTER_BY_MY_GROUPS(state) + return getters.filter(state) + } + }) + + describe('given empty filter', () => { + beforeEach(() => { + state = { filter: {} } + }) + + it('sets postsInMyGroups filter to true', () => { + expect(testMutation()).toEqual({ postsInMyGroups: true }) + }) + }) + + describe('already filtered', () => { + beforeEach(() => { + state = { filter: { postsInMyGroups: true } } + }) + + it('removes postsInMyGroups filter', () => { + expect(testMutation()).toEqual({}) + }) + }) + }) + describe('TOGGLE_ORDER', () => { beforeEach(() => { testMutation = (key) => { diff --git a/yarn.lock b/yarn.lock index 0a91bc1d6..51e44fa78 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1969,9 +1969,9 @@ cachedir@^2.3.0: integrity sha512-A+Fezp4zxnit6FanDmv9EqXNAi3vt9DWp51/71UEhXukb7QUuvtv9344h91dyAxuTLoSYJFU299qzR3tzwPAhw== caniuse-lite@^1.0.30001157: - version "1.0.30001159" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001159.tgz#bebde28f893fa9594dadcaa7d6b8e2aa0299df20" - integrity sha512-w9Ph56jOsS8RL20K9cLND3u/+5WASWdhC/PPrf+V3/HsM3uHOavWOR1Xzakbv4Puo/srmPHudkmCRWM7Aq+/UA== + version "1.0.30001458" + resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001458.tgz" + integrity sha512-lQ1VlUUq5q9ro9X+5gOEyH7i3vm+AYVT1WDCVB69XOZ17KZRhnZ9J0Sqz7wTHQaLBJccNCHq8/Ww5LlOIZbB0w== caseless@~0.12.0: version "0.12.0"