Skip to content

Commit

Permalink
Merge pull request #4553 from luke-h1/dev
Browse files Browse the repository at this point in the history
merge dev into main
  • Loading branch information
luke-h1 authored Oct 22, 2024
2 parents 3e43cb3 + 38d9711 commit 5d0b764
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ description: 'Build frontend app'
runs:
using: 'composite'
steps:
- name: Ensure rebased with dev
shell: bash
run: ./scripts/ensure-rebased.sh

- name: install
uses: ./.github/actions/install

Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@ jobs:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.head_ref }}


- name: Ensure rebased with dev
run: ./scripts/ensure-rebased.sh

- name: Build
uses: ./.github/actions/build

- name: Deploy to dev
uses: ./.github/actions/deploy
with:
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/live-ui-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,43 @@ jobs:
uses: ./.github/actions/ui-test
with:
target: e2e-prod

discord-fail-message:
runs-on: ubuntu-latest
if: failure()
needs: test
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.head_ref }}

- name: get-npm-version
id: package-version
uses: martinbeentjes/npm-get-version-action@main
with:
path: apps/lambda

- name: Get current time
id: current-time
run: echo "TIME=$(date -u)" >> $GITHUB_ENV

- name: Get deployedAt from lhowsam.com
id: fetch-deployedAt
run: |
response=$(curl -s https://lhowsam.com/api/version)
deployedAt=$(echo $response | jq -r '.deployedAt')
echo "DEPLOYED_AT=$deployedAt" >> $GITHUB_ENV
- name: Discord fail notification
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_LIVE_WEBHOOK_URL }}
uses: Ilshidur/action-discord@master
with:
args: |
🚨 Live UI tests lhowsam.com failed! 🚨
**Failure Time**: ${{ env.TIME }}
**Last deployed at**: ${{ env.DEPLOYED_AT }}
**Vercel Status**: https://www.vercel-status.com
**CF status**: https://www.cloudflarestatus.com
13 changes: 13 additions & 0 deletions scripts/ensure-rebased.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
RESET=$(tput sgr0)

COMMITS_BEHIND_MAIN=$(eval "git rev-list --left-right --count origin/dev...HEAD" | cut -f1)

if [ $COMMITS_BEHIND_MAIN -gt 0 ]; then
echo "${RED}Branch is behind dev by $COMMITS_BEHIND_MAIN commits. Please rebase ${RESET}"
else
echo "${GREEN}Branch is in-sync with dev.${RESET}"
fi
19 changes: 18 additions & 1 deletion src/services/spotifyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ const NOW_PLAYING_ENDPOINT = `https://api.spotify.com/v1/me/player/currently-pla
const TOP_TRACKS_ENDPOINT = `https://api.spotify.com/v1/me/top/tracks`;
const TOKEN_ENDPOINT = `https://accounts.spotify.com/api/token`;

const getConsumer = () => {
let consumer: string = '';

switch (process.env.NEXT_PUBLIC_URL) {
case 'https://dev.lhowsam.com':
consumer = 'lhowsam-dev';
return consumer;
case 'https://lhowsam.com':
consumer = 'lhowsam-prod';
return consumer;

default:
return '';
}
};

const spotifyService = {
async getAccessToken(): Promise<{ access_token: string }> {
const response = await fetch(TOKEN_ENDPOINT, {
Expand Down Expand Up @@ -53,12 +69,13 @@ const spotifyService = {
return response.json();
},
async lambdaNowPlaying(): Promise<Song> {
const consumer = getConsumer();
const response = await fetch(
`${process.env.NEXT_PUBLIC_NOW_PLAYING_API_BASE_URL}/api/now-playing`,
{
headers: {
'Content-Type': 'application/json',
'x-consumer': process.env.NEXT_PUBLIC_URL,
'x-consumer': consumer,
},
},
);
Expand Down

0 comments on commit 5d0b764

Please sign in to comment.