Skip to content

DAPP1-87: updated ci file #34

DAPP1-87: updated ci file

DAPP1-87: updated ci file #34

Workflow file for this run

name: Continuous Integration and Deployment
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
continuous_integration:
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
steps:
- name: Checkout code 🛎️
uses: actions/checkout@v3
with:
clean: true
- name: Set Node Version
uses: actions/setup-node@v3
with:
node-version: 20.13.1
- name: Setup .npmrc file
run: |
echo "@3um-group:registry=https://npm.pkg.github.com/" > ~/.npmrc
echo "//npm.pkg.github.com/:_authToken=${{ secrets.NPM_TOKEN }}" >> ~/.npmrc
- name: Install Packages
run: npm install --legacy-peer-deps
# - name: Run Test
# run: npm run test
- name: Build Project
run: npm run build
- name: Check and Update .codesandbox/tasks.json
run: |
if [ ! -f .codesandbox/tasks.json ]; then
echo "Creating .codesandbox/tasks.json"
mkdir -p .codesandbox
echo '{
"tasks": {
"start": {
"name": "start dev server",
"command": "npm start",
"runAtStart": true,
"preview": {
"port": 3000
}
}
}
}' > .codesandbox/tasks.json
else
echo "Updating .codesandbox/tasks.json"
jq '.tasks.start.runAtStart = true' .codesandbox/tasks.json > temp.json && mv temp.json .codesandbox/tasks.json
fi
cat .codesandbox/tasks.json
- name: Deploy to CodeSandbox
id: deploy
env:
CODESANDBOX_TOKEN: ${{ secrets.CODESANDBOX_API_TOKEN }}
run: |
npm install -g codesandbox
DEPLOY_OUTPUT=$(codesandbox deploy --json)
SANDBOX_URL=$(echo $DEPLOY_OUTPUT | jq -r '.url')
if [ -z "$SANDBOX_URL" ]; then
echo "Error: Failed to deploy to CodeSandbox"
echo "Deploy output: $DEPLOY_OUTPUT"
exit 1
fi
echo "Sandbox URL: $SANDBOX_URL"
echo "SANDBOX_URL=$SANDBOX_URL" >> $GITHUB_ENV
echo "sandbox_url=$SANDBOX_URL" >> $GITHUB_OUTPUT
- name: Verify Dev Server
run: |
SANDBOX_URL="${{ steps.deploy.outputs.sandbox_url }}"
MAX_RETRIES=5
RETRY_DELAY=10
for i in $(seq 1 $MAX_RETRIES); do
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$SANDBOX_URL")
if [ $HTTP_STATUS -eq 200 ]; then
echo "Dev server is up and running!"
exit 0
else
echo "Attempt $i: Dev server not ready (Status: $HTTP_STATUS). Retrying in $RETRY_DELAY seconds..."
sleep $RETRY_DELAY
fi
done
echo "Error: Dev server did not start successfully after $MAX_RETRIES attempts."
exit 1
- name: Comment PR
uses: actions/github-script@v6
if: github.event_name == 'pull_request' && steps.deploy.outcome == 'success'
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const sandboxUrl = process.env.SANDBOX_URL || 'Deployment failed';
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `Deployed to CodeSandbox: ${sandboxUrl}`
})