Skip to content

Commit

Permalink
Provide deploy.sh script for deployments #3741
Browse files Browse the repository at this point in the history
  • Loading branch information
de-jcup committed Dec 13, 2024
1 parent 81b026c commit eeda133
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
21 changes: 21 additions & 0 deletions github-actions/scan/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,27 @@ npm run build

This runs the ncc compiler and transpiles the files from the src folder into the `dist/` folder.

=== Deployment
A GitHub action needs a transpiled `index.js` to be used as an action from workflows.

As long as we do not provide a new index.js the old action is still in usage, even when the source code has
changed. If we do not build the file and commit and push it to git repository, the action will not
be available!

Of course the steps can be done manual, but for convenience a script is avialable:

[source,bash]
----
./deploy.sh
----

This will
- setup (npm install)
- build (npm run build)
- test (npm run test)
- verify (only index.js is changed now)
- deploy - when no error happened - deploy the new `index.js` file by doing a commit and a push to the remote repository

=== Test

==== Unit tests
Expand Down
45 changes: 45 additions & 0 deletions github-actions/scan/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

set -e

echo "--------------------------------"
echo "Deployment of SecHub scan action"
echo "--------------------------------"
echo "[SETUP]"
npm install

echo "[BUILD]"
npm run build

echo "[TEST]"
npm run test

# Check for any changes in the repository
changed_files=$(git diff --name-only HEAD)

# Check if there are no changes
if [ -z "$changed_files" ]; then
echo "No changes detected in the repository."
echo "[CANCELED]"

exit 5
fi

# Check if the only changed file is index.js
if [ "$changed_files" != "index.js" ]; then
echo "Changes detected in files other than index.js (only):"
echo "$changed_files"
echo ""
echo "This may not happen on a deployment! Check the other changes"
echo "[FAILED]"
exit 1
fi
echo "Only index.js has changes, deployment is possible."
echo "[DEPLOY]"

git add --all
git commit -m "GitHub action (scan) deployment"
git push



1 change: 1 addition & 0 deletions github-actions/scan/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "dist/main.js",
"scripts": {
"build": "ncc build src/main.ts",
"deploy" : "./deploy.sh",
"cleanBuild": "ncc cache clean;ncc build src/main.ts",
"lint": "eslint src",
"prettier": "npx prettier --write src",
Expand Down

0 comments on commit eeda133

Please sign in to comment.