Skip to content

Commit 722370f

Browse files
committed
feat: Add Dockerhub action and refactored package to be esmodule compliant
1 parent 6b528c1 commit 722370f

File tree

8 files changed

+84
-7
lines changed

8 files changed

+84
-7
lines changed

.github/workflows/dockerhub.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Build and publish Docker image
2+
3+
on:
4+
push:
5+
tags:
6+
- '*.*.*'
7+
8+
jobs:
9+
docker-build-and-publish:
10+
environment:
11+
name: dockerhub
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Docker meta
15+
id: meta
16+
uses: docker/metadata-action@v5
17+
with:
18+
# list of Docker images to use as base name for tags
19+
images: |
20+
name/bmssp-js
21+
# generate Docker tags based on the following events/attributes
22+
tags: |
23+
type=semver,pattern={{version}}
24+
type=semver,pattern={{major}}.{{minor}}
25+
type=semver,pattern={{major}}
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
29+
- name: Login to Docker Hub
30+
uses: docker/login-action@v3
31+
with:
32+
username: ${{ secrets.DOCKERHUB_USERNAME }}
33+
password: ${{ secrets.DOCKERHUB_TOKEN }}
34+
35+
- name: Set up QEMU
36+
uses: docker/setup-qemu-action@v3
37+
38+
- name: Set up Docker Buildx
39+
uses: docker/setup-buildx-action@v3
40+
41+
- name: Build and push
42+
uses: docker/build-push-action@v6
43+
with:
44+
context: .
45+
platforms: linux/amd64,linux/arm64
46+
push: true
47+
tags: ${{ steps.meta.outputs.tags }}

.github/workflows/npmjs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
jobs:
66
build-and-publish:
77
environment:
8-
name: npmjs-publish
8+
name: npm-bmssp
99
runs-on: ubuntu-latest
1010
permissions:
1111
contents: read
@@ -17,6 +17,7 @@ jobs:
1717
with:
1818
node-version: '24.x'
1919
registry-url: 'https://registry.npmjs.org'
20+
- run: npm test
2021
- run: npm ci
2122
- run: npm publish --provenance --access public
2223
env:

Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM node:24-alpine
2+
3+
WORKDIR /app
4+
5+
# Copy package files and install dependencies
6+
COPY package*.json ./
7+
RUN npm install
8+
9+
# Mount src/ directory as a volume
10+
VOLUME ["src/", "tests/"]
11+
12+
# Default command (can be overridden)
13+
CMD ["node", "tests/main.js"]

index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bmssp",
3-
"version": "0.4.0",
3+
"version": "0.5.0",
44
"description": "Javascript package implementation of the bmssp algorithm.",
55
"keywords": [
66
"shortest-paths",
@@ -18,12 +18,12 @@
1818
},
1919
"license": "MPL-2.0",
2020
"author": "Saul Ivan Rivas Vega",
21-
"type": "commonjs",
21+
"type": "module",
2222
"main": "index.js",
2323
"directories": {
2424
"doc": "docs"
2525
},
2626
"scripts": {
27-
"test": "echo \"Error: no test specified\" && exit 1"
27+
"test": "node tests/main.js"
2828
}
2929
}

src/bmssp.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function printMessage(message) {
2+
console.log(message);
3+
}
4+
5+
export { printMessage };

tests/main.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { printMessage } from "../src/bmssp.mjs";
2+
3+
function testFunction() {
4+
try {
5+
const result = printMessage("Hello, World!");
6+
console.log('Test passed:', result);
7+
} catch (error) {
8+
console.error('Test failed:', error.message);
9+
}
10+
}
11+
12+
testFunction();

0 commit comments

Comments
 (0)