CI Pipeline #27
This file contains 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: CI Pipeline | |
on: | |
workflow_dispatch: | |
# Add additional trigger events as needed (e.g., push, pull_request, etc.) | |
env: | |
AWS_DEFAULT_REGION: us-east-1 | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
MYSQL_ROOT_PASSWORD: root | |
jobs: | |
build-and-test: | |
runs-on: ubuntu-latest | |
if: github.actor == 'pablo-code-org' | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v2 | |
with: | |
path: code-dot-org | |
- name: Find and Cache Stale Files | |
id: stalefiles | |
run: | | |
# Find files not modified in the last 2 years (730 days) | |
find code-dot-org -type f -not -path './.git/*' -mtime +730 > stale_files.txt | |
# Generate a hash of this list | |
echo "::set-output name=stale_hash::$(sha256sum stale_files.txt | cut -d ' ' -f1)" | |
- name: Cache stale files | |
uses: actions/cache@v2 | |
with: | |
path: | | |
$(cat stale_files.txt) | |
key: ${{ runner.os }}-stale-${{ steps.stalefiles.outputs.stale_hash }} | |
- name: Get Branch Name from Hardcoded Pull Request ID | |
id: get_branch | |
run: | | |
PR_ID=55766 | |
PR_DATA=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
https://api.github.com/repos/code-dot-org/code-dot-org/pulls/$PR_ID) | |
BRANCH_NAME=$(echo $PR_DATA | jq -r .head.ref) | |
echo "Branch Name: $BRANCH_NAME" | |
echo "::set-output name=branch_name::$BRANCH_NAME" | |
- name: Checkout Branch | |
uses: actions/checkout@v2 | |
with: | |
ref: ${{ steps.get_branch.outputs.branch_name }} | |
path: code-dot-org | |
repository: code-dot-org/code-dot-org | |
token: ${{ secrets.GITHUB_TOKEN }} | |
fetch-depth: 0 | |
- name: List contents of the code-dot-org directory | |
run: ls -la ./code-dot-org/docker | |
- name: Set up Docker Environment | |
run: docker build -t my-ci-image -f ./code-dot-org/Dockerfile ./code-dot-org | |
- name: Run Unit Tests | |
run: | | |
docker run my-ci-image /bin/bash -c "source /home/runner/work/code-dot-org/code-dot-org/docker/unit_test.sh" | |
- name: Run UI Tests | |
run: | | |
docker run my-ci-image /bin/bash -c "source /home/runner/work/code-dot-org/code-dot-org/docker/ui_tests.sh" | |
- name: Update Cache | |
uses: actions/cache@v2 | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} |