Skip to content

Commit

Permalink
wip: migration from Travis CI to GitHub Actions #149
Browse files Browse the repository at this point in the history
  • Loading branch information
tristan-greffe committed Dec 9, 2023
1 parent 89008a9 commit 40e9f51
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 65 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

source env.sh

check_code()
{
if [[ $1 -ne $2 ]]; then
echo "$3 has failed [error: $1]"
exit 1
fi
}

#
# Build the app
#
echo "##[group]Build"

cd $APP
yarn pwa:build
EXIT_CODE=$?
check_code $EXIT_CODE 0 "Builing the client"

# Log in to docker before building the app because of rate limiting
docker login -u="$DOCKER_USER" -p="$DOCKER_PASSWORD"
check_code $? 0 "Connecting to Docker"

# Create an archive to speed docker build process
cd ../..
tar --exclude='$APP/test' -zcf $GITHUB_WORKSPACE/kalisio.tgz kalisio

# Build the image
cd $GITHUB_WORKSPACE
docker build --build-arg APP=$APP --build-arg FLAVOR=$FLAVOR --build-arg BUILD_NUMBER=$GITHUB_RUN_NUMBER -f dockerfile -t kalisio/$APP:$TAG .
check_code $? 0 "Building the app docker image"

echo "##[endgroup]"

#
# Deploy the app
#
echo "##[group]Deploy"

# Push the app image to the hub with the version tag
docker push kalisio/$APP:$TAG
check_code $? 0 "Pushing the $APP:$TAG docker image"

# Push the app image to the hub with the flavor tag
docker tag kalisio/$APP:$TAG kalisio/$APP:$FLAVOR
docker push kalisio/$APP:$FLAVOR
check_code $? 0 "Pushing the $APP:$TAG docker image"

echo "##[endgroup]"
54 changes: 1 addition & 53 deletions .github/workflows/app.sh → .github/workflows/env.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
#!/bin/bash

check_code()
{
if [[ $1 -ne $2 ]]; then
echo "$3 has failed [error: $1]"
exit 1
fi
}

parse_semver()
{
local REGEXP="^([0-9]+)\.([0-9]+)\.([0-9]+)"
Expand All @@ -18,7 +10,6 @@ parse_semver()
#
# Provision the required files
#
echo "##[group]Provision"

# Define the application name
APP=$(node -p -e "require('./package.json').name")
Expand Down Expand Up @@ -79,47 +70,4 @@ fi
# Clone the project and install the dependencies
node . $APP.js --clone
node . $APP.js --install
node . $APP.js --link

echo "##[endgroup]"

#
# Build the app
#
echo "##[group]Build"

cd $APP
yarn pwa:build
EXIT_CODE=$?
check_code $EXIT_CODE 0 "Builing the client"

# Log in to docker before building the app because of rate limiting
docker login -u="$DOCKER_USER" -p="$DOCKER_PASSWORD"
check_code $? 0 "Connecting to Docker"

# Create an archive to speed docker build process
cd ../..
tar --exclude='$APP/test' -zcf $GITHUB_WORKSPACE/kalisio.tgz kalisio

# Build the image
cd $GITHUB_WORKSPACE
docker build --build-arg APP=$APP --build-arg FLAVOR=$FLAVOR --build-arg BUILD_NUMBER=$GITHUB_RUN_NUMBER -f dockerfile -t kalisio/$APP:$TAG .
check_code $? 0 "Building the app docker image"

echo "##[endgroup]"

#
# Deploy the app
#
echo "##[group]Deploy"

# Push the app image to the hub with the version tag
docker push kalisio/$APP:$TAG
check_code $? 0 "Pushing the $APP:$TAG docker image"

# Push the app image to the hub with the flavor tag
docker tag kalisio/$APP:$TAG kalisio/$APP:$FLAVOR
docker push kalisio/$APP:$FLAVOR
check_code $? 0 "Pushing the $APP:$TAG docker image"

echo "##[endgroup]"
node . $APP.js --link
38 changes: 26 additions & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,43 @@ name: Build & Deploy
on: [push]

jobs:
app:
test:
if: ${{ github.event.head_commit.message !~ /\[skip[ _-]test\]/ }}
runs-on: ubuntu-latest
env:
DB_URL: "mongodb://mongo:27017"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: ${{ secrets.NODE_VERSION }}
- name: Start MongoDB
uses: timgchile/[email protected]
with:
mongodb-version: 4.0
- name: Run tests
run: |
chmod +x ./.github/workflows/test.sh
./.github/workflows/test.sh
build:
if: ${{ github.event.head_commit.message !~ /(skip[ _-]app)/ }}
runs-on: ubuntu-latest
env:
DOCKER_USER: ${{ secrets.DOCKER_USER }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
TOKEN_GITHUB: ${{ secrets.TOKEN_GITHUB }}
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: ${{ secrets.NODE_VERSION }}
- name: Build & deploy
run: |
if [[ $COMMIT_MESSAGE !~ /(skip[ _-]app)/ ]]; then
chmod +x ./.github/workflows/app.sh
./.github/workflows/app.sh
fi
chmod +x ./.github/workflows/build.sh
./.github/workflows/build.sh
doc:
if: ${{ contains(github.event.head_commit.message, '[build doc]')}}
if: ${{ github.event.head_commit.message =~ /\[skip[ _-]test\]/ }}
runs-on: ubuntu-latest
env:
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
Expand All @@ -42,7 +56,7 @@ jobs:
name: Notify on slack
runs-on: ubuntu-latest
if: ${{ always() }}
needs: [app, doc]
needs: [test, build, doc]
steps:
- uses: actions/checkout@v4
- name: Notify on slack
Expand All @@ -51,6 +65,6 @@ jobs:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_APPS }}
SLACK_USERNAME: GitHub Actions
SLACK_ICON: https://github.githubassets.com/assets/GitHub-Mark-ea2971cee799.png
SLACK_COLOR: ${{ (needs.app.reult == 'failed' || needs.doc.reult == 'failed') && 'danger' || 'good' }}
SLACK_MESSAGE: Build of ${{ github.repository }}@${{ github.ref_name }} by ${{ github.actor }} ${{ (needs.app.reult == 'failed' || needs.doc.reult == 'failed') && 'failed' || 'passed' }}
SLACK_COLOR: ${{ (needs.test.result == 'failed' || needs.build.result == 'failed' || needs.doc.result == 'failed') && 'danger' || 'good' }}
SLACK_MESSAGE: Build of ${{ github.repository }}@${{ github.ref_name }} by ${{ github.actor }} ${{ (needs.test.result == 'failed' || needs.build.result == 'failed' || needs.doc.result == 'failed') && 'failed' || 'passed' }}
SLACK_FOOTER:
7 changes: 7 additions & 0 deletions .github/workflows/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
echo "Running tests"

source env.sh

# Run backend tests
cd api
yarn test

0 comments on commit 40e9f51

Please sign in to comment.