Skip to content

Commit ced6596

Browse files
authored
Merge pull request #22 from konnectors/feat/githubactions
feat: Migrate from Travis to GitHub Actions
2 parents 6f751df + 4b68235 commit ced6596

9 files changed

Lines changed: 99 additions & 165 deletions

File tree

.github/workflows/ci-cd.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: CI/CD
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
tags:
9+
- '[0-9]+.[0-9]+.[0-9]+'
10+
- '[0-9]+.[0-9]+.[0-9]+-beta.[0-9]+'
11+
12+
env:
13+
MATTERMOST_CHANNEL: publication
14+
MATTERMOST_HOOK_URL: ${{ secrets.MATTERMOST_HOOK_URL }}
15+
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
16+
17+
jobs:
18+
build:
19+
name: Build and publish
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
- name: Use Node.js
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version-file: '.nvmrc'
28+
- name: Install dependencies
29+
run: yarn install --frozen-lockfile
30+
- name: Lint
31+
run: yarn lint
32+
- name: Build
33+
run: yarn build
34+
- name: Set SSH git push
35+
uses: webfactory/ssh-agent@v0.9.0
36+
with:
37+
ssh-private-key: ${{ secrets.DEPLOY_KEY }}
38+
- name: Publish
39+
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
40+
run: |
41+
DEPLOY_BRANCH=build yarn deploy
42+
BUILD_SHA=$(git rev-parse build)
43+
BUILD_URL=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/archive/$BUILD_SHA.tar.gz
44+
if [[ $GITHUB_REF == refs/tags/* ]]; then
45+
yarn cozyPublish --yes --build-url $BUILD_URL --postpublish mattermost
46+
else
47+
yarn cozyPublish --yes --build-url $BUILD_URL
48+
fi

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
konnector-dev-config.json*
55
fixtures/*
66
data/*
7+
.env
78

89
# NPM
910
node_modules/

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20.18.3

.travis.yml

Lines changed: 0 additions & 43 deletions
This file was deleted.

bin/generate_travis_deploy_key

Lines changed: 0 additions & 52 deletions
This file was deleted.

bin/generate_travis_deploy_key.ps1

Lines changed: 0 additions & 69 deletions
This file was deleted.

bin/init_github_action

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# .env file sample
6+
# MATTERMOST_HOOK_URL=https://***
7+
# REGISTRY_TOKEN="***"
8+
9+
if [ ! -f ".env" ]; then
10+
echo "Error: .env file is missing"
11+
echo "Please create a .env file with the following structure:"
12+
echo "MATTERMOST_HOOK_URL=https://your-mattermost-hook-url"
13+
echo "REGISTRY_TOKEN=your-registry-token"
14+
exit 1
15+
fi
16+
17+
# Check if required environment variables are present in .env
18+
if ! grep -q "^MATTERMOST_HOOK_URL=" .env || ! grep -q "^REGISTRY_TOKEN=" .env; then
19+
echo "Error: MATTERMOST_HOOK_URL and/or REGISTRY_TOKEN missing from .env file"
20+
exit 1
21+
fi
22+
23+
# Source the .env file to get variables
24+
source .env
25+
26+
# Check if variables are empty
27+
if [ -z "$MATTERMOST_HOOK_URL" ] || [ -z "$REGISTRY_TOKEN" ]; then
28+
echo "Error: MATTERMOST_HOOK_URL and/or REGISTRY_TOKEN cannot be empty in .env file"
29+
exit 1
30+
fi
31+
32+
# Check if gh CLI is installed
33+
if ! command -v gh &> /dev/null; then
34+
echo "Error: GitHub CLI (gh) is not installed"
35+
echo "Please install it from: https://cli.github.com/"
36+
exit 1
37+
fi
38+
39+
# generate a new private and public key
40+
ssh-keygen -t rsa -b 4096 -f github_deploy_key -N '' -C $url -q 1>/dev/null
41+
42+
gh repo deploy-key add --allow-write --title "github_deploy_key" ./github_deploy_key.pub
43+
gh secret set DEPLOY_KEY < github_deploy_key
44+
gh secret set -f .env
45+
46+
# cleaning
47+
rm github_deploy_key
48+
rm github_deploy_key.pub

github_deploy_key.enc

-3.34 KB
Binary file not shown.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"lint": "eslint --fix .",
3535
"deploy": "git-directory-deploy --directory build/ --branch ${DEPLOY_BRANCH:-build} --repo=${DEPLOY_REPOSITORY:-$npm_package_repository_url}",
3636
"cozyPublish": "cozy-app-publish --token $REGISTRY_TOKEN --build-commit $(git rev-parse ${DEPLOY_BRANCH:-build})",
37-
"travisDeployKey": "./bin/generate_travis_deploy_key"
37+
"initGithubAction": "./bin/init_github_action"
3838
},
3939
"dependencies": {
4040
"cheerio": "^1.0.0-rc.12",

0 commit comments

Comments
 (0)