From 1c428911251ed21e5f3adb9f17ba1fd1b4d516c0 Mon Sep 17 00:00:00 2001 From: David Houweling Date: Mon, 4 Nov 2024 11:44:10 +1100 Subject: [PATCH] Fix deployment not working (#16) --- .github/workflows/deploy.yml | 45 ++++++++++++++++++++++++++++++++++-- .github/workflows/lint.yml | 18 +++------------ .gitignore | 2 ++ README.md | 6 ++--- package-lock.json | 17 +++++++------- package.json | 2 +- wrangler.toml | 16 +++++++++++++ 7 files changed, 77 insertions(+), 29 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 5717c00..e4a3d79 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,16 +1,43 @@ -name: Deply +name: Deploy on: workflow_run: workflows: [Build] - types: [completed] + types: + - completed + +env: + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} jobs: deploy: runs-on: ubuntu-latest + environment: + name: ${{ github.env.BRANCH_NAME == 'main' && 'production' || 'staging' }} if: ${{ github.event.workflow_run.conclusion == 'success' }} timeout-minutes: 60 steps: + - name: Print Github head ref + run: echo ${{ github.head_ref}} + + - name: Print Github ref name + run: echo ${{ github.ref_name}} + + - name: Print GitHub context + run: echo "$GITHUB_CONTEXT" + + - name: Check out Git repository + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: "npm" + + - name: Install Node.js dependencies + run: npm ci + - name: Download artifacts uses: actions/download-artifact@v4 with: @@ -24,6 +51,20 @@ jobs: with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + environment: ${{ github.env.BRANCH_NAME == 'main' && 'production' || 'staging' }} + vars: | + DISCORD_APP_ID + DISCORD_PUBLIC_KEY + XBOX_USERNAME + secrets: | + DISCORD_TOKEN + XBOX_PASSWORD + env: + DISCORD_APP_ID: ${{ vars.DISCORD_APP_ID }} + DISCORD_PUBLIC_KEY: ${{ vars.DISCORD_PUBLIC_KEY }} + DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }} + XBOX_USERNAME: ${{ vars.XBOX_USERNAME }} + XBOX_PASSWORD: ${{ secrets.XBOX_PASSWORD }} deploy-cancel: runs-on: ubuntu-latest if: ${{ github.event.workflow_run.conclusion == 'failure' }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index c4af3b9..56b4766 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -8,10 +8,6 @@ on: branches: - main -permissions: - checks: write - contents: write - jobs: run-linters: name: Run linters @@ -36,17 +32,9 @@ jobs: - name: Generate types run: npm run build:generate-types + - name: Run format + run: npm run format + # TODO: remove once lint-action supports eslint v9 - name: Run eslint run: npm run lint - - - name: Run linters - uses: wearerequired/lint-action@v2 - with: - auto_fix: true - # TODO: enable again once eslint v9 is supported - # eslint: true - # eslint_auto_fix: true - # eslint_args: "--max-warnings 0" - prettier: true - prettier_auto_fix: true diff --git a/.gitignore b/.gitignore index 71da00a..cdc4493 100644 --- a/.gitignore +++ b/.gitignore @@ -50,6 +50,8 @@ jspm_packages/ # cloudflare workers prefer .dev.vars .dev.vars +.staging.vars +.production.vars .wrangler # Stores VSCode versions used for testing VSCode extensions diff --git a/README.md b/README.md index 6b6c882..fae1e20 100644 --- a/README.md +++ b/README.md @@ -22,9 +22,9 @@ This Discord bot can pull stats from Halo Waypoint and post accordingly. 1. [Download and install node.js](https://nodejs.org/en/download/package-manager) if you haven't done already 2. Clone the repo (assuming you already know how) 3. Follow the instructions from [`discord/cloudflare-sample-app`](https://github.com/discord/cloudflare-sample-app) - a. [Configuring project](https://github.com/discord/cloudflare-sample-app?tab=readme-ov-file#configuring-project) - b. [Creating your Cloudflare worker](https://github.com/discord/cloudflare-sample-app?tab=readme-ov-file#creating-your-cloudflare-worker) - c. [Running locally](https://github.com/discord/cloudflare-sample-app?tab=readme-ov-file#running-locally) + 1. [Configuring project](https://github.com/discord/cloudflare-sample-app?tab=readme-ov-file#configuring-project) + 2. [Creating your Cloudflare worker](https://github.com/discord/cloudflare-sample-app?tab=readme-ov-file#creating-your-cloudflare-worker) + 3. [Running locally](https://github.com/discord/cloudflare-sample-app?tab=readme-ov-file#running-locally) Now in a channel you can use `/stats` command. diff --git a/package-lock.json b/package-lock.json index 056da87..7e246ad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,6 +7,7 @@ "": { "name": "guilty-spark", "version": "1.0.0", + "hasInstallScript": true, "license": "MIT", "dependencies": { "@xboxreplay/xboxlive-auth": "^4.0.0", @@ -30,7 +31,7 @@ "tsx": "^4.19.2", "typescript": "^5.6.3", "typescript-eslint": "^8.10.0", - "wrangler": "^3.83.0" + "wrangler": "^3.84.1" } }, "node_modules/@azure/msal-common": { @@ -4186,9 +4187,9 @@ }, "node_modules/unenv": { "name": "unenv-nightly", - "version": "2.0.0-20241018-011344-e666fcf", - "resolved": "https://registry.npmjs.org/unenv-nightly/-/unenv-nightly-2.0.0-20241018-011344-e666fcf.tgz", - "integrity": "sha512-D00bYn8rzkCBOlLx+k1iHQlc69jvtJRT7Eek4yIGQ6461a2tUBjngGZdRpqsoXAJCz/qBW0NgPting7Zvg+ysg==", + "version": "2.0.0-20241024-111401-d4156ac", + "resolved": "https://registry.npmjs.org/unenv-nightly/-/unenv-nightly-2.0.0-20241024-111401-d4156ac.tgz", + "integrity": "sha512-xJO1hfY+Te+/XnfCYrCbFbRcgu6XEODND1s5wnVbaBCkuQX7JXF7fHEXPrukFE2j8EOH848P8QN19VO47XN8hw==", "dev": true, "license": "MIT", "dependencies": { @@ -4275,9 +4276,9 @@ } }, "node_modules/wrangler": { - "version": "3.83.0", - "resolved": "https://registry.npmjs.org/wrangler/-/wrangler-3.83.0.tgz", - "integrity": "sha512-qDzdUuTngKqmm2OJUZm7Gk4+Hv37F2nNNAHuhIgItEIhxBdOVDsgKmvpd+f41MFxyuGg3fbGWYANHI+0V2Z5yw==", + "version": "3.84.1", + "resolved": "https://registry.npmjs.org/wrangler/-/wrangler-3.84.1.tgz", + "integrity": "sha512-w27/QpIk2qz6aMIVi9T8cDcXMvh/RXjcL+vf4o5J2GpQAE4U7wTCNHyaY9H3oTJWRN97KqCAEbiHBNtTKoUJEw==", "dev": true, "license": "MIT OR Apache-2.0", "dependencies": { @@ -4297,7 +4298,7 @@ "resolve.exports": "^2.0.2", "selfsigned": "^2.0.1", "source-map": "^0.6.1", - "unenv": "npm:unenv-nightly@2.0.0-20241018-011344-e666fcf", + "unenv": "npm:unenv-nightly@2.0.0-20241024-111401-d4156ac", "workerd": "1.20241022.0", "xxhash-wasm": "^1.0.1" }, diff --git a/package.json b/package.json index 4781879..45aac46 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "tsx": "^4.19.2", "typescript": "^5.6.3", "typescript-eslint": "^8.10.0", - "wrangler": "^3.83.0" + "wrangler": "^3.84.1" }, "overrides": { "@types/node": "20.8.3" diff --git a/wrangler.toml b/wrangler.toml index 3937807..8a40d4a 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -3,3 +3,19 @@ main = "./src/server.mts" compatibility_flags = [ "nodejs_compat" ] compatibility_date = "2024-09-23" upload_source_maps = true + +[observability] +enabled = true +head_sampling_rate = 1 # optional. default = 1. + +[env.dev] +name = "guilty-spark-dev" +workers_dev = true + +[env.staging] +name = "guilty-spark-staging" +workers_dev = true + +[env.production] +name = "guilty-spark" +workers_dev = false