diff --git a/.github/actions/install-deps/action.yml b/.github/actions/install-deps/action.yml new file mode 100644 index 000000000..8a3c9e9f3 --- /dev/null +++ b/.github/actions/install-deps/action.yml @@ -0,0 +1,9 @@ +name: 'Install Dependencies' +description: 'Install Node.js dependencies' + +runs: + using: 'composite' + steps: + - name: Install dependencies + run: yarn install --frozen-lockfile + shell: bash \ No newline at end of file diff --git a/.github/actions/setup-eas/action.yml b/.github/actions/setup-eas/action.yml new file mode 100644 index 000000000..b8d5e6f4b --- /dev/null +++ b/.github/actions/setup-eas/action.yml @@ -0,0 +1,41 @@ +name: 'Setup EAS' +description: 'Set up EAS and install dependencies' + +inputs: + expo-token: + description: 'Expo token for authentication' + required: true + node-version: + description: 'Node.js version to use' + required: true + default: '20.x' + +runs: + using: 'composite' + steps: + - name: Check for EXPO_TOKEN + run: | + if [ -z "${{ inputs.expo-token }}" ]; then + echo "You must provide an EXPO_TOKEN secret linked to this project's Expo account in this repo's secrets. Learn more: https://docs.expo.dev/eas-update/github-actions" + exit 1 + fi + shell: bash + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: ${{ inputs.node-version }} + cache: yarn + + - name: Setup EAS + uses: expo/expo-github-action@v8 + with: + eas-version: latest + token: ${{ inputs.expo-token }} + + - name: Install dependencies + run: yarn install + shell: bash \ No newline at end of file diff --git a/.github/workflows/labeler.yml b/.github/labeler.yml similarity index 53% rename from .github/workflows/labeler.yml rename to .github/labeler.yml index 01b0da161..8ca02d59a 100644 --- a/.github/workflows/labeler.yml +++ b/.github/labeler.yml @@ -6,12 +6,17 @@ repo: test: - '**/*.spec.ts' - '**/*.spec.js' + - '**/*.test.ts' + - '**/*.test.js' + - '**/tests/**/*.ts' + - '**/tests/**/*.js' + # Add 'frontend' label to any change in the 'client' directory frontend: - - 'client/**/*.{ts,js}' - - any: ['client/**/*.ts', 'client/**/*.js'] - all: ['!client/src/main.ts', '!client/src/main.js'] + - 'apps/**/*.{ts,js}' + - any: ['apps/**/*.ts', 'apps/**/*.js'] + all: ['!apps/src/main.ts', '!apps/src/main.js'] # Add 'backend' label to any change in the 'server' directory backend: @@ -24,19 +29,18 @@ AnyChange: - '**/.*/**' - '**/.*/**/.*' -# Workflow configuration starts here - -name: Pull request labeler -on: [ pull_request_target ] - -jobs: - triage: - runs-on: ubuntu-latest - permissions: - contents: read - pull-requests: write - steps: - - uses: actions/labeler@v4 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - +client: + - apps/**/* + +expo: + - apps/expo/**/* + +next: + - apps/next/**/* + +vite: + - apps/vite/**/* + +api: + - api/**/* + - server/**/* \ No newline at end of file diff --git a/.github/workflows/android-build-manual.yml b/.github/workflows/android-build-manual.yml new file mode 100644 index 000000000..a52852034 --- /dev/null +++ b/.github/workflows/android-build-manual.yml @@ -0,0 +1,49 @@ +name: android build manual + +on: + workflow_dispatch: + inputs: + name: + description: 'Build manually' + default: 'World' + required: true + type: string + +jobs: + update: + name: EAS Android Preview Build + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + steps: + - name: Check for EXPO_TOKEN + run: | + if [ -z "${{ secrets.EXPO_TOKEN }}" ]; then + echo "You must provide an EXPO_TOKEN secret linked to this project's Expo account in this repo's secrets. Learn more: https://docs.expo.dev/eas-update/github-actions" + exit 1 + fi + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: 20.x + cache: yarn + + - name: Setup EAS + uses: expo/expo-github-action@v8 + with: + eas-version: latest + token: ${{ secrets.EXPO_TOKEN }} + + - name: Install dependencies + run: yarn install + + - name: Create preview + uses: expo/expo-github-action/preview@v8 + with: + working-directory: apps/expo + command: eas build --platform android --profile preview \ No newline at end of file diff --git a/.github/workflows/android-preview-build-local.yml b/.github/workflows/android-preview-build-local.yml new file mode 100644 index 000000000..b3be73155 --- /dev/null +++ b/.github/workflows/android-preview-build-local.yml @@ -0,0 +1,47 @@ +name: android-preview-build-local +on: + push: + branches: [ "**" ] + pull_request: + branches: [ "**" ] + + + +jobs: + update: + name: EAS Android Preview Build Local + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + steps: + - name: Check for EXPO_TOKEN + run: | + if [ -z "${{ secrets.EXPO_TOKEN }}" ]; then + echo "You must provide an EXPO_TOKEN secret linked to this project's Expo account in this repo's secrets. Learn more: https://docs.expo.dev/eas-update/github-actions" + exit 1 + fi + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: 20.x + cache: yarn + + - name: Setup EAS + uses: expo/expo-github-action@v8 + with: + eas-version: latest + token: ${{ secrets.EXPO_TOKEN }} + + - name: Install dependencies + run: yarn install + + - name: Create preview + uses: expo/expo-github-action/preview@v8 + with: + working-directory: apps/expo + command: eas build --platform android --profile preview --local diff --git a/.github/workflows/eas-build-manual.yml b/.github/workflows/eas-build-manual.yml new file mode 100644 index 000000000..008f03376 --- /dev/null +++ b/.github/workflows/eas-build-manual.yml @@ -0,0 +1,44 @@ +name: EAS Build Manual + +on: + workflow_dispatch: + inputs: + platform: + description: 'Platform (android or ios)' + required: true + default: 'android' + type: choice + options: + - android + - ios + build-type: + description: 'Build type (preview or local)' + required: true + default: 'preview' + type: choice + options: + - preview + - local + +jobs: + update: + name: EAS ${{ github.event.inputs.platform }} ${{ github.event.inputs.build-type }} Build + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + + steps: + - name: Setup EAS + uses: ./.github/actions/setup-eas + with: + expo-token: ${{ secrets.EXPO_TOKEN }} + node-version: '20.x' + + - name: Create build + uses: expo/expo-github-action/preview@v8 + with: + working-directory: apps/expo + command: | + eas build --platform ${{ github.event.inputs.platform }} --profile preview \ + ${{ github.event.inputs.build-type == 'local' && '--local' || '' }} \ No newline at end of file diff --git a/.github/workflows/label.yml b/.github/workflows/label.yml index 461356907..007429836 100644 --- a/.github/workflows/label.yml +++ b/.github/workflows/label.yml @@ -5,8 +5,8 @@ # file with configuration. For more information, see: # https://github.com/actions/labeler -name: Labeler -on: [pull_request_target] +name: Pull request labeler +on: [ pull_request_target ] jobs: label: @@ -17,6 +17,6 @@ jobs: pull-requests: write steps: - - uses: actions/labeler@v4 + - uses: actions/labeler@v5 with: repo-token: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 000000000..52165f25b --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,97 @@ +name: Run Tests + +on: + push: + branches: ['**'] + pull_request: + branches: ['**'] + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: '20.x' + + - name: Find or create comment + uses: actions/github-script@v6 + id: find_or_create_comment + if: github.event_name == 'pull_request' + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const commentIdentifier = ''; + const commentBody = `${commentIdentifier}\nšŸš€ Running tests... Please wait for the results! šŸ•`; + + const comments = await github.rest.issues.listComments({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + }); + + const existingComment = comments.data.find(comment => comment.body.startsWith(commentIdentifier)); + + if (existingComment) { + core.setOutput('comment_id', existingComment.id); + } else { + const { data: { id: commentId } } = await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: commentBody + }); + core.setOutput('comment_id', commentId); + } + + - name: Install dependencies + uses: ./.github/actions/install-deps + + - name: Run tests + id: run_tests + run: | + yarn test + continue-on-error: true + + - name: Update comment with test results + uses: actions/github-script@v6 + if: always() && github.event_name == 'pull_request' + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const commentId = process.env.COMMENT_ID; + const testLogs = `${{ steps.run_tests.outputs.stdout }}\n${{ steps.run_tests.outputs.stderr }}`; + const testStatus = `${{ steps.run_tests.outcome }}`; + + let commentBody = '\n'; + let emoji = ''; + + if (testStatus === 'success') { + commentBody += 'āœ… Tests passed successfully! šŸŽ‰\n\n'; + emoji = 'šŸ’š'; + } else { + commentBody += 'āŒ Tests failed for this pull request. šŸ˜ž\n\n'; + emoji = 'ā¤ļø'; + } + + commentBody += `
Test Logs\n\n\`\`\`\n${testLogs}\n\`\`\`\n
`; + + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: commentId, + body: commentBody + }); + + await github.rest.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + labels: [`tests-${testStatus}${emoji}`] + }); + env: + COMMENT_ID: ${{ steps.find_or_create_comment.outputs.comment_id }}