Feat/brevo campaigns #53
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build, Commit Dist, and Tag Version | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'src/**' | |
| pull_request: | |
| branches: | |
| - main | |
| paths: | |
| - 'src/**' | |
| permissions: | |
| contents: write | |
| packages: write | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| environment: Test | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm install | |
| - name: Install Firebase Admin SDK | |
| run: npm install firebase-admin@^12.2.0 | |
| - name: Install Firebase CLI | |
| run: npm install -g firebase-tools | |
| - name: Install jq for JSON parsing | |
| run: sudo apt-get update && sudo apt-get install -y jq | |
| - name: Verify Test Environment | |
| run: | | |
| echo "π Verifying Test Environment Configuration..." | |
| echo "Environment: ${{ github.ref_name }}" | |
| echo "Event: ${{ github.event_name }}" | |
| echo "Actor: ${{ github.actor }}" | |
| echo "Repository: ${{ github.repository }}" | |
| - name: Set up Firebase Authentication for Testing | |
| run: | | |
| if [ -z "${{ secrets.FIREBASE_SERVICE_ACCOUNT_TEST_ENCODED }}" ]; then | |
| echo "β FIREBASE_SERVICE_ACCOUNT_TEST_ENCODED secret is not set in Test environment" | |
| echo "β οΈ Tests will run with application default credentials" | |
| echo "π‘ To use Firebase service account, set the secret in the Test environment" | |
| echo " Go to: Settings β Environments β Test β Environment secrets" | |
| exit 0 | |
| fi | |
| echo "${{ secrets.FIREBASE_SERVICE_ACCOUNT_TEST_ENCODED }}" | base64 --decode > "/home/runner/firebaseServiceAccount.json" | |
| chmod 644 /home/runner/firebaseServiceAccount.json | |
| - name: Verify Firebase Service Account | |
| run: | | |
| if [ -f "/home/runner/firebaseServiceAccount.json" ]; then | |
| echo "β Firebase service account file created successfully" | |
| echo "File size: $(wc -c < /home/runner/firebaseServiceAccount.json) bytes" | |
| # Check if file is valid JSON | |
| if jq empty /home/runner/firebaseServiceAccount.json 2>/dev/null; then | |
| echo "β File is valid JSON" | |
| echo "Project ID: $(jq -r '.project_id' /home/runner/firebaseServiceAccount.json)" | |
| echo "Client Email: $(jq -r '.client_email' /home/runner/firebaseServiceAccount.json)" | |
| echo "Private Key Length: $(jq -r '.private_key' /home/runner/firebaseServiceAccount.json | wc -c) characters" | |
| else | |
| echo "β File is not valid JSON" | |
| echo "First 100 characters of file:" | |
| head -c 100 /home/runner/firebaseServiceAccount.json | |
| echo "" | |
| exit 1 | |
| fi | |
| else | |
| echo "βΉοΈ No Firebase service account file found - will use application default credentials" | |
| fi | |
| - name: Show test environment | |
| run: | | |
| echo "π Test Environment Configuration:" | |
| echo "π GitHub Environment: Test" | |
| echo "NODE_ENV: ${NODE_ENV:-'not set'}" | |
| echo "CI: ${CI:-'not set'}" | |
| echo "FIREBASE_PROJECT_ID: ${FIREBASE_PROJECT_ID:-'not set'}" | |
| if [ -f "/home/runner/firebaseServiceAccount.json" ]; then | |
| echo "GOOGLE_APPLICATION_CREDENTIALS: /home/runner/firebaseServiceAccount.json (exists)" | |
| else | |
| echo "GOOGLE_APPLICATION_CREDENTIALS: not set (will use application default)" | |
| fi | |
| - name: Run tests | |
| env: | |
| GOOGLE_APPLICATION_CREDENTIALS: "/home/runner/firebaseServiceAccount.json" | |
| FIREBASE_PROJECT_ID: "hubby-esim-dev" | |
| NODE_ENV: "test" | |
| CI: "true" | |
| run: | | |
| # Try to run tests with Firebase first | |
| if [ -f "/home/runner/firebaseServiceAccount.json" ]; then | |
| echo "π₯ Running tests with Firebase service account" | |
| npm test | |
| else | |
| echo "β οΈ No Firebase service account, running tests with application default credentials" | |
| # Unset the credentials path so tests use application default | |
| unset GOOGLE_APPLICATION_CREDENTIALS | |
| npm test | |
| fi | |
| - name: Test coverage report | |
| if: always() | |
| run: | | |
| echo "Test execution completed" | |
| echo "Firebase project used: ${{ env.FIREBASE_PROJECT_ID }}" | |
| - name: Handle test failures | |
| if: failure() | |
| run: | | |
| echo "β Tests failed! Check the test output above for details." | |
| echo "Firebase configuration used:" | |
| echo "- Project ID: ${{ env.FIREBASE_PROJECT_ID }}" | |
| echo "- Service Account: ${{ env.GOOGLE_APPLICATION_CREDENTIALS }}" | |
| echo "- Node Environment: ${{ env.NODE_ENV }}" | |
| build: | |
| runs-on: ubuntu-latest | |
| needs: test | |
| timeout-minutes: 15 | |
| if: github.event_name == 'push' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Configure git authentication | |
| run: | | |
| git config --global user.name 'github-actions[bot]' | |
| git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
| git config --global credential.helper store | |
| echo "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com" > ~/.git-credentials | |
| - name: Set up Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: 'npm' | |
| - run: npm install | |
| - run: npm run build | |
| - name: Check if dist/ has changes | |
| id: check_changes | |
| run: | | |
| git add dist/ | |
| git diff --cached --exit-code || echo "changes=true" >> $GITHUB_ENV | |
| - name: Commit and Push compiled dist | |
| if: env.changes == 'true' | |
| run: | | |
| git config --global user.name 'github-actions[bot]' | |
| git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
| git commit -m "chore: build dist [skip ci]" | |
| git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/hubbyesim/types.git | |
| git push origin main | |
| - name: Get latest tag | |
| if: env.changes == 'true' | |
| id: get_tag | |
| run: | | |
| git fetch --tags | |
| TAG=$(git tag --sort=-v:refname | head -n 1) | |
| echo "Latest tag: $TAG" | |
| echo "tag=$TAG" >> $GITHUB_ENV | |
| - name: Bump patch version and create new tag | |
| if: env.changes == 'true' | |
| id: bump_tag | |
| run: | | |
| if [ -z "${{ env.tag }}" ]; then | |
| NEW_TAG="v1.0.0" | |
| else | |
| VERSION=${{ env.tag }} | |
| VERSION=${VERSION#v} # remove leading v | |
| IFS='.' read -ra PARTS <<< "$VERSION" | |
| MAJOR=${PARTS[0]} | |
| MINOR=${PARTS[1]} | |
| PATCH=${PARTS[2]} | |
| PATCH=$((PATCH + 1)) | |
| NEW_TAG="v${MAJOR}.${MINOR}.${PATCH}" | |
| fi | |
| echo "NEW_TAG=$NEW_TAG" >> $GITHUB_ENV | |
| git tag $NEW_TAG | |
| git push origin $NEW_TAG | |
| - name: Create GitHub Release | |
| if: env.changes == 'true' | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ env.NEW_TAG }} | |
| name: "Schemas ${{ env.NEW_TAG }}" | |
| body: | | |
| π Auto-generated release for schema build. | |
| Changes based on updates in `src/`. | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # Build-only job for PRs (no commits/tags/releases) | |
| build-pr: | |
| runs-on: ubuntu-latest | |
| needs: test | |
| timeout-minutes: 15 | |
| if: github.event_name == 'pull_request' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: 'npm' | |
| - run: npm install | |
| - run: npm run build | |
| - name: Verify build output | |
| run: | | |
| echo "β Build completed successfully" | |
| echo "π Generated files in dist/:" | |
| ls -la dist/ | |
| echo "π Build size:" | |
| du -sh dist/ |