diff --git a/.github/workflows/autodev.yaml b/.github/workflows/autodev.yaml index a40f910..7715763 100644 --- a/.github/workflows/autodev.yaml +++ b/.github/workflows/autodev.yaml @@ -8,7 +8,7 @@ on: jobs: autodev: - uses: Staffbase/gha-workflows/.github/workflows/template_autodev.yml@dont-check-private-key + uses: Staffbase/gha-workflows/.github/workflows/template_autodev.yml@v5.3.0 with: comments: true secrets: diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml index b1b5e35..44afe48 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/cd.yaml @@ -12,18 +12,23 @@ env: DEPLOYMENT_TARGET: weather DEPLOYMENT_STATIC_FILES: staffbase.user-profile-client.min.js DEPLOYMENT_SOURCE: samples/weather-forecast/dist - + jobs: - build-and-deploy: + prepare-deployment: + name: Prepare Deployment runs-on: ubuntu-22.04 - steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 + with: + # persisting credentials breaks installing dependencies from private repos + persist-credentials: false + # fetch all history for all branches and tags + fetch-depth: 0 - name: Use Node JS - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ env.NODE_VERSION }} cache: 'yarn' @@ -44,74 +49,122 @@ jobs: mkdir samples/weather-forecast/icons cp samples/weather-forecast/resources/weather-forecast.svg samples/weather-forecast/dist/icons - - name: Publish to S3 DE Prod - if: startsWith(github.ref, 'refs/tags/') - uses: Staffbase/deploy-web-assets@0.1.0 + continuous-delivery-dev-de1: + name: Continuous Delivery (dev de1) + needs: prepare-deployment + runs-on: ubuntu-22.04 + if: github.ref == 'refs/heads/dev' + steps: + - name: Deploy + uses: Staffbase/deploy-web-assets@0.2.0 with: source: ${{ env.DEPLOYMENT_SOURCE }} - target: ${{ env.DEPLOYMENT_TARGET }} deployment_kind: ${{ env.DEPLOYMENT_KIND }} + target: ${{ env.DEPLOYMENT_TARGET }} + # Varnish settings static_files: ${{ env.DEPLOYMENT_STATIC_FILES }} - frontend_cache_host: frontend-cache-main-de1.staffbase.com - frontend_cache_password: ${{ secrets.FRONTEND_CACHE_PROD_DE1_PASSWORD }} + frontend_cache_password: ${{ secrets.FRONTEND_CACHE_DEV_DE1_PASSWORD }} + frontend_cache_host: frontend-cache-de1.staffbase.dev # AWS specific settings - aws_bucket: staffbasestatic-prod-de1 aws_region: eu-central-1 - aws_access_key_id: ${{ secrets.PROD_DE1_aws_access_key_id_ID }} - aws_access_key_secret: ${{ secrets.PROD_DE1_aws_access_key_id_SECRET }} + aws_bucket: staffbasestatic-dev-de1 + aws_access_key_id: ${{ secrets.DEV_DE1_AWS_ACCESS_KEY_ID }} + aws_access_key_secret: ${{ secrets.DEV_DE1_AWS_ACCESS_KEY_SECRET }} - - name: Deploy to S3 US Prod - if: startsWith(github.ref, 'refs/tags/') - uses: Staffbase/deploy-web-assets@0.1.0 + continuous-delivery-stage-de1: + name: Continuous Delivery (stage de1) + needs: prepare-deployment + runs-on: ubuntu-22.04 + if: github.ref == 'refs/heads/main' + steps: + - name: Deploy + uses: Staffbase/deploy-web-assets@0.2.0 with: source: ${{ env.DEPLOYMENT_SOURCE }} - target: ${{ env.DEPLOYMENT_TARGET }} deployment_kind: ${{ env.DEPLOYMENT_KIND }} + target: ${{ env.DEPLOYMENT_TARGET }} + # Varnish settings static_files: ${{ env.DEPLOYMENT_STATIC_FILES }} - frontend_cache_host: frontend-cache-us1.staffbase.com - frontend_cache_password: ${{ secrets.FRONTEND_CACHE_PROD_US1_PASSWORD }} + frontend_cache_host: frontend-cache-de1.staffbase.rocks + frontend_cache_password: ${{ secrets.FRONTEND_CACHE_STAGE_DE1_PASSWORD }} # AWS specific settings - aws_bucket: staffbasestatic-prod-us1 - aws_region: us-east-1 - aws_access_key_id: ${{ secrets.PROD_US1_aws_access_key_id_ID }} - aws_access_key_secret: ${{ secrets.PROD_US1_aws_access_key_id_SECRET }} + aws_bucket: staffbasestatic-stage-de1 + aws_region: eu-central-1 + aws_access_key_id: ${{ secrets.STAGE_DE1_AWS_ACCESS_KEY_ID }} + aws_access_key_secret: ${{ secrets.STAGE_DE1_AWS_ACCESS_KEY_SECRET }} - - name: Publish to S3 DE stage - if: github.ref == 'refs/heads/main' - uses: Staffbase/deploy-web-assets@0.1.0 + continuous-delivery-prod-de1: + name: Continuous Delivery (prod de1) + needs: prepare-deployment + runs-on: ubuntu-22.04 + if: startsWith(github.ref, 'refs/tags/') + steps: + - name: Deploy + uses: Staffbase/deploy-web-assets@0.2.0 with: source: ${{ env.DEPLOYMENT_SOURCE }} - target: ${{ env.DEPLOYMENT_TARGET }} deployment_kind: ${{ env.DEPLOYMENT_KIND }} + target: ${{ env.DEPLOYMENT_TARGET }} + # Varnish settings static_files: ${{ env.DEPLOYMENT_STATIC_FILES }} - frontend_cache_host: frontend-cache-de1.staffbase.rocks - frontend_cache_password: ${{ secrets.FRONTEND_CACHE_STAGE_DE1_PASSWORD }} + frontend_cache_host: frontend-cache-de1.staffbase.com + frontend_cache_password: ${{ secrets.FRONTEND_CACHE_PROD_DE1_PASSWORD }} # AWS specific settings - aws_bucket: staffbasestatic-stage-de1 + aws_bucket: staffbasestatic-prod-de1 aws_region: eu-central-1 - aws_access_key_id: ${{ secrets.STAGE_DE1_aws_access_key_id_ID }} - aws_access_key_secret: ${{ secrets.STAGE_DE1_aws_access_key_id_SECRET }} + aws_access_key_id: ${{ secrets.PROD_DE1_AWS_ACCESS_KEY_ID }} + aws_access_key_secret: ${{ secrets.PROD_DE1_AWS_ACCESS_KEY_SECRET }} - - name: Publish to S3 DE dev - if: github.ref == 'refs/heads/dev' - uses: Staffbase/deploy-web-assets@0.1.0 + continuous-delivery-prod-us1: + name: Continuous Delivery (prod us1) + needs: prepare-deployment + runs-on: ubuntu-22.04 + if: startsWith(github.ref, 'refs/tags/') + steps: + - name: Deploy + uses: Staffbase/deploy-web-assets@0.2.0 with: source: ${{ env.DEPLOYMENT_SOURCE }} + deployment_kind: ${{ env.DEPLOYMENT_KIND }} target: ${{ env.DEPLOYMENT_TARGET }} + + # Varnish settings + static_files: ${{ env.DEPLOYMENT_STATIC_FILES }} + frontend_cache_host: frontend-cache-us1.staffbase.com + frontend_cache_password: ${{ secrets.FRONTEND_CACHE_PROD_US1_PASSWORD }} + + # AWS specific settings + aws_bucket: staffbasestatic-prod-us1 + aws_region: us-east-1 + aws_access_key_id: ${{ secrets.PROD_US1_AWS_ACCESS_KEY_ID }} + aws_access_key_secret: ${{ secrets.PROD_US1_AWS_ACCESS_KEY_SECRET }} + + continuous-delivery-prod-au1: + name: Continuous Delivery (prod au1) + needs: prepare-deployment + runs-on: ubuntu-22.04 + if: startsWith(github.ref, 'refs/tags/') + steps: + - name: Deploy + uses: Staffbase/deploy-web-assets@0.2.0 + with: + source: ${{ env.DEPLOYMENT_SOURCE }} deployment_kind: ${{ env.DEPLOYMENT_KIND }} + target: ${{ env.DEPLOYMENT_TARGET }} + # Varnish settings static_files: ${{ env.DEPLOYMENT_STATIC_FILES }} - frontend_cache_host: frontend-cache-de1.staffbase.dev - frontend_cache_password: ${{ secrets.FRONTEND_CACHE_DEV_DE1_PASSWORD }} + frontend_cache_host: frontend-cache-au1.staffbase.com + frontend_cache_password: ${{ secrets.FRONTEND_CACHE_PROD_AU1_PASSWORD }} # AWS specific settings - aws_bucket: staffbasestatic-dev-de1 - aws_region: eu-central-1 - aws_access_key_id: ${{ secrets.DEV_DE1_aws_access_key_id_ID }} - aws_access_key_secret: ${{ secrets.DEV_DE1_aws_access_key_id_SECRET }} + aws_bucket: staffbasestatic-prod-au1 + aws_region: ap-southeast-2 + aws_access_key_id: ${{ secrets.PROD_AU1_AWS_ACCESS_KEY_ID }} + aws_access_key_secret: ${{ secrets.PROD_AU1_AWS_ACCESS_KEY_SECRET }} \ No newline at end of file diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5e17ce7..b4ce24c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,6 +1,6 @@ name: CI Tests env: - NODE_VERSION: 14 + NODE_VERSION: 16 on: push: paths-ignore: @@ -8,7 +8,7 @@ on: jobs: executing-tests: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - name: Checkout repository @@ -17,17 +17,17 @@ jobs: persist-credentials: false - name: Use Node.js Version - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ env.NODE_VERSION }} registry-url: 'https://npm.pkg.github.com/' scope: '@staffbase' + - run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.STAFFBOT_NPM_READ }}" >> .npmrc + - name: Install Yarn Dependencies working-directory: samples/weather-forecast run: yarn install --frozen-lockfile - env: - NODE_AUTH_TOKEN: ${{ secrets.STAFFBOT_NPM_READ }} - name: Run Build working-directory: samples/weather-forecast diff --git a/samples/weather-forecast/jest.config.js b/samples/weather-forecast/jest.config.js index f952777..db4915d 100644 --- a/samples/weather-forecast/jest.config.js +++ b/samples/weather-forecast/jest.config.js @@ -2,8 +2,8 @@ module.exports = { setupFilesAfterEnv: ["./test/jest-setup.js"], resetMocks: true, moduleNameMapper: { - 'icons/(.*)\.svg$': '/__mocks__/lazySvgMock.js', - '\\.svg$': '/__mocks__/fileMock.js', + 'icons/(.*)\.(png|svg)$': '/__mocks__/lazySvgMock.js', + '\\.(png|svg)$': '/__mocks__/fileMock.js', }, testEnvironment: 'jsdom', }; diff --git a/samples/weather-forecast/package.json b/samples/weather-forecast/package.json index 40dee9f..058c532 100644 --- a/samples/weather-forecast/package.json +++ b/samples/weather-forecast/package.json @@ -47,7 +47,7 @@ "@testing-library/react": "12.0.0", "@testing-library/react-hooks": "7.0.2", "@types/copy-webpack-plugin": "^8.0.1", - "@types/node": "16.7.10", + "@types/node": "20.14.2", "@types/react": "^17.0.19", "@types/react-dom": "^17.0.9", "@types/webpack": "5.28.0", @@ -72,6 +72,7 @@ "ts-loader": "^9.2.5", "ts-node": "10.2.1", "typescript": "4.4.2", + "url-loader": "^4.1.1", "webpack": "^5.51.1", "webpack-cli": "^4.8.0", "webpack-dev-server": "^4.1.0", diff --git a/samples/weather-forecast/resources/weather-forecast.svg b/samples/weather-forecast/resources/old-weather-forecast.svg similarity index 100% rename from samples/weather-forecast/resources/weather-forecast.svg rename to samples/weather-forecast/resources/old-weather-forecast.svg diff --git a/samples/weather-forecast/src/index.tsx b/samples/weather-forecast/src/index.tsx index b82107d..4a2b04c 100644 --- a/samples/weather-forecast/src/index.tsx +++ b/samples/weather-forecast/src/index.tsx @@ -23,7 +23,7 @@ import { import { WeatherForecastProps, WeatherForecast } from "./weather-forecast"; import { configurationSchema, uiSchema } from "./configuration-schema"; import pkg from "../package.json"; -import icon from "../resources/weather-forecast.svg"; +import widgetIcon from "../weather-forecast.png"; /** * This factory creates the class which is registered with the tagname in the `custom element registry` @@ -80,7 +80,7 @@ const blockDefinition: BlockDefinition = { configurationSchema: configurationSchema, uiSchema: uiSchema, label: "Weather", - iconUrl: icon, + iconUrl: widgetIcon, }; /** diff --git a/samples/weather-forecast/src/types/assets.d.ts b/samples/weather-forecast/src/types/assets.d.ts new file mode 100644 index 0000000..6a81ab5 --- /dev/null +++ b/samples/weather-forecast/src/types/assets.d.ts @@ -0,0 +1,4 @@ +declare module "*.png" { + const value: any; + export default value; +} diff --git a/samples/weather-forecast/weather-forecast.png b/samples/weather-forecast/weather-forecast.png new file mode 100644 index 0000000..42889ae Binary files /dev/null and b/samples/weather-forecast/weather-forecast.png differ diff --git a/samples/weather-forecast/webpack.common.ts b/samples/weather-forecast/webpack.common.ts index 9730d36..40823b6 100644 --- a/samples/weather-forecast/webpack.common.ts +++ b/samples/weather-forecast/webpack.common.ts @@ -30,6 +30,17 @@ const config: webpack.Configuration = { test: /\.svg$/i, use: ["@svgr/webpack"], }, + { + test: /\.(png|jpg|gif)$/i, + use: [ + { + loader: "url-loader", + options: { + limit: 8192, + }, + }, + ], + }, ], }, resolve: { diff --git a/samples/weather-forecast/yarn.lock b/samples/weather-forecast/yarn.lock index da92d03..aaf2023 100644 --- a/samples/weather-forecast/yarn.lock +++ b/samples/weather-forecast/yarn.lock @@ -2485,11 +2485,6 @@ dependencies: "@sinonjs/commons" "^1.7.0" -"@staffbase/browserslist-config@1.0.0": - version "1.0.0" - resolved "https://npm.pkg.github.com/download/@Staffbase/browserslist-config/1.0.0/57ddcbc99a2509ba6a58e37ec6c2730dccc875de#57ddcbc99a2509ba6a58e37ec6c2730dccc875de" - integrity sha512-IvzkYFUaeH/BIrg097Lw3L/pO2XRIEJEcPmmnhORrZrbnpoWknx836sm6te8fad9qRjQwY+y0UzuWX2VcEtFhg== - "@staffbase/widget-sdk@^3.3.3": version "3.3.3" resolved "https://registry.yarnpkg.com/@staffbase/widget-sdk/-/widget-sdk-3.3.3.tgz#79da379765dddedd76d50dbf955f01a9e3a4907f" @@ -2879,10 +2874,12 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-16.4.10.tgz#e57e2a54fc6da58da94b3571b1cb456d39f88597" integrity sha512-TmVHsm43br64js9BqHWqiDZA+xMtbUpI1MBIA0EyiBmoV9pcEYFOSdj5fr6enZNfh4fChh+AGOLIzGwJnkshyQ== -"@types/node@16.7.10": - version "16.7.10" - resolved "https://registry.yarnpkg.com/@types/node/-/node-16.7.10.tgz#7aa732cc47341c12a16b7d562f519c2383b6d4fc" - integrity sha512-S63Dlv4zIPb8x6MMTgDq5WWRJQe56iBEY0O3SOFA9JrRienkOVDXSXBjjJw6HTNQYSE2JI6GMCR6LVbIMHJVvA== +"@types/node@20.14.2": + version "20.14.2" + resolved "https://registry.yarnpkg.com/@types/node/-/node-20.14.2.tgz#a5f4d2bcb4b6a87bffcaa717718c5a0f208f4a18" + integrity sha512-xyu6WAMVwv6AKFLB+e/7ySZVr/0zLCzOa7rSpq6jNwpqOrUbcACDWC+53d4n2QHOnDou0fbIsg8wZu/sxrnI4Q== + dependencies: + undici-types "~5.26.4" "@types/parse-json@^4.0.0": version "4.0.0" @@ -7629,14 +7626,14 @@ semver@7.0.0: integrity sha512-+GB6zVA9LWh6zovYQLALHwv5rb2PHGlJi3lfiqIHxR0uuwCgefcOJc59v9fv1w8GbStwxuuqqAjI9NMAOOgq1A== semver@^6.0.0, semver@^6.1.1, semver@^6.1.2, semver@^6.3.0: - version "6.3.0" - resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d" - integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw== + version "6.3.1" + resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4" + integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA== semver@^7.2.1, semver@^7.3.2, semver@^7.3.4, semver@^7.3.5: - version "7.3.5" - resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.5.tgz#0b621c879348d8998e4b0e4be94b3f12e6018ef7" - integrity sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ== + version "7.5.4" + resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.4.tgz#483986ec4ed38e1c6c48c34894a9182dbff68a6e" + integrity sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA== dependencies: lru-cache "^6.0.0" @@ -8221,6 +8218,11 @@ unbox-primitive@^1.0.1: has-symbols "^1.0.2" which-boxed-primitive "^1.0.2" +undici-types@~5.26.4: + version "5.26.5" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" + integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA== + unicode-canonical-property-names-ecmascript@^1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz#2619800c4c825800efdd8343af7dd9933cbe2818" @@ -8305,6 +8307,15 @@ uri-js@^4.2.2: dependencies: punycode "^2.1.0" +url-loader@^4.1.1: + version "4.1.1" + resolved "https://registry.yarnpkg.com/url-loader/-/url-loader-4.1.1.tgz#28505e905cae158cf07c92ca622d7f237e70a4e2" + integrity sha512-3BTV812+AVHHOJQO8O5MkWgZ5aosP7GnROJwvzLS9hWDj00lZ6Z0wNak423Lp9PBZN05N+Jk/N5Si8jRAlGyWA== + dependencies: + loader-utils "^2.0.0" + mime-types "^2.1.27" + schema-utils "^3.0.0" + url@^0.11.0: version "0.11.0" resolved "https://registry.yarnpkg.com/url/-/url-0.11.0.tgz#3838e97cfc60521eb73c525a8e55bfdd9e2e28f1"