Skip to content

Commit 009ca1c

Browse files
authored
Merge pull request #10 from TingluoHuang/main
Create schedule workflow to build/publish node.js on schedules.
2 parents 3b5ac71 + 5a1827a commit 009ca1c

File tree

3 files changed

+134
-19
lines changed

3 files changed

+134
-19
lines changed

.github/workflows/build-release-alpine-nodejs.yml

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,81 +8,112 @@ on:
88
NodeVersion:
99
required: true
1010
description: 'Node.js version to build (ex: v12.22.7, v16.12.0)'
11+
workflow_call:
12+
inputs:
13+
NodeVersion:
14+
required: true
15+
description: 'Node.js version to build (ex: v12.22.7, v16.12.0)'
16+
type: string
1117

1218
jobs:
19+
prebuild:
20+
outputs:
21+
NodeVersion: ${{ steps.check_node_version.outputs.NodeVersion }}
22+
name: Determine node.js version
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Check node.js version
26+
id: check_node_version
27+
run: |
28+
# Determine which NodeVersion input to use
29+
if [ -n "${{ github.event.inputs.NodeVersion }}" ]; then
30+
NODE_VERSION="${{ github.event.inputs.NodeVersion }}"
31+
echo "Using NodeVersion from workflow_dispatch: $NODE_VERSION"
32+
elif [ -n "${{ inputs.NodeVersion }}" ]; then
33+
NODE_VERSION="${{ inputs.NodeVersion }}"
34+
echo "Using NodeVersion from workflow_call: $NODE_VERSION"
35+
else
36+
echo "Error: No NodeVersion specified"
37+
exit 1
38+
fi
39+
40+
# Set the output that will be used by subsequent steps/jobs
41+
echo "NodeVersion=$NODE_VERSION" >> $GITHUB_OUTPUT
42+
1343
build:
14-
name: Build node.js ${{github.event.inputs.NodeVersion}}
44+
needs: [prebuild]
45+
name: Build node.js ${{needs.prebuild.outputs.NodeVersion}}
1546
runs-on: ubuntu-latest
1647
steps:
1748
- uses: actions/checkout@v3
1849
- name: Build the Docker image
1950
run: |
20-
NodeVersion="${{github.event.inputs.NodeVersion}}"
51+
NodeVersion="${{needs.prebuild.outputs.NodeVersion}}"
2152
PythonVersion="python3"
2253
if [[ $NodeVersion = v12* ]]
2354
then
2455
PythonVersion="python2"
2556
fi
2657
echo node.js version $NodeVersion
2758
echo python version $PythonVersion
28-
docker build --file Dockerfile --tag alpine_nodejs:${{github.event.inputs.NodeVersion}} --build-arg NodeVersion=${{github.event.inputs.NodeVersion}} --build-arg PythonVersion=$PythonVersion .
59+
docker build --file Dockerfile --tag alpine_nodejs:${{needs.prebuild.outputs.NodeVersion}} --build-arg NodeVersion=${{needs.prebuild.outputs.NodeVersion}} --build-arg PythonVersion=$PythonVersion .
2960
- name: Copy alpine node.js out
3061
run: |
3162
mkdir $RUNNER_TEMP/alpine_node
32-
docker run --rm -v $RUNNER_TEMP/alpine_node:/node_output alpine_nodejs:${{github.event.inputs.NodeVersion}}
63+
docker run --rm -v $RUNNER_TEMP/alpine_node:/node_output alpine_nodejs:${{needs.prebuild.outputs.NodeVersion}}
3364
ls -l -R $RUNNER_TEMP/alpine_node
3465
- name: Upload alpine node.js
3566
uses: actions/upload-artifact@v4
3667
with:
37-
name: alpine_nodejs_${{github.event.inputs.NodeVersion}}
38-
path: ${{runner.temp}}/alpine_node/node-${{github.event.inputs.NodeVersion}}-alpine-x64.tar.gz
68+
name: alpine_nodejs_${{needs.prebuild.outputs.NodeVersion}}
69+
path: ${{runner.temp}}/alpine_node/node-${{needs.prebuild.outputs.NodeVersion}}-alpine-x64.tar.gz
3970

4071
test:
41-
name: Test node.js ${{github.event.inputs.NodeVersion}}
42-
needs: [build]
72+
name: Test node.js ${{needs.prebuild.outputs.NodeVersion}}
73+
needs: [prebuild, build]
4374
runs-on: ubuntu-latest
4475
container: alpine
4576
steps:
4677
- name: Download alpine node.js
4778
uses: actions/download-artifact@v4
4879
with:
49-
name: alpine_nodejs_${{github.event.inputs.NodeVersion}}
80+
name: alpine_nodejs_${{needs.prebuild.outputs.NodeVersion}}
5081
- run: |
5182
ls -l
52-
tar xzf ./node-${{github.event.inputs.NodeVersion}}-alpine-x64.tar.gz
83+
tar xzf ./node-${{needs.prebuild.outputs.NodeVersion}}-alpine-x64.tar.gz
5384
ls -l -R
5485
./bin/node -v
5586
./bin/node -e "console.log('hello world')"
5687
uname -a
5788
ldd ./bin/node
5889
name: Test node
5990
release:
60-
name: Create release for node.js ${{github.event.inputs.NodeVersion}}
61-
needs: [test]
91+
name: Create release for node.js ${{needs.prebuild.outputs.NodeVersion}}
92+
needs: [prebuild, test]
6293
runs-on: ubuntu-latest
6394
steps:
6495
- name: Download alpine node.js
6596
uses: actions/download-artifact@v4
6697
with:
67-
name: alpine_nodejs_${{github.event.inputs.NodeVersion}}
98+
name: alpine_nodejs_${{needs.prebuild.outputs.NodeVersion}}
6899
# Create GitHub release
69100
- uses: actions/create-release@master
70101
id: createRelease
71-
name: Create node.js ${{github.event.inputs.NodeVersion}} Alpine Release
102+
name: Create node.js ${{needs.prebuild.outputs.NodeVersion}} Alpine Release
72103
env:
73104
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74105
with:
75-
tag_name: "${{github.event.inputs.NodeVersion}}"
76-
release_name: "${{github.event.inputs.NodeVersion}}"
106+
tag_name: "${{needs.prebuild.outputs.NodeVersion}}"
107+
release_name: "${{needs.prebuild.outputs.NodeVersion}}"
77108
body: |
78-
Alpine node.js ${{github.event.inputs.NodeVersion}}
109+
Alpine node.js ${{needs.prebuild.outputs.NodeVersion}}
79110
# Upload release assets
80111
- name: Upload Release Asset
81112
uses: actions/upload-release-asset@v1.0.1
82113
env:
83114
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
84115
with:
85116
upload_url: ${{ steps.createRelease.outputs.upload_url }}
86-
asset_path: ${{ github.workspace }}/node-${{github.event.inputs.NodeVersion}}-alpine-x64.tar.gz
87-
asset_name: node-${{github.event.inputs.NodeVersion}}-alpine-x64.tar.gz
117+
asset_path: ${{ github.workspace }}/node-${{needs.prebuild.outputs.NodeVersion}}-alpine-x64.tar.gz
118+
asset_name: node-${{needs.prebuild.outputs.NodeVersion}}-alpine-x64.tar.gz
88119
asset_content_type: application/octet-stream
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Build and Release Alpine Node.js on Schedule
2+
permissions:
3+
contents: write
4+
5+
on:
6+
schedule:
7+
- cron: '0 0 * * 0' # Every Sunday at midnight
8+
workflow_dispatch:
9+
10+
jobs:
11+
get_versions:
12+
outputs:
13+
versions: ${{ steps.set-matrix.outputs.versions }}
14+
buildnode: ${{ steps.set-matrix.outputs.buildnode }}
15+
name: Find versions to build and release
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
- name: Find latest versions from each major version
20+
id: set-matrix
21+
run: |
22+
BUILD_NODE=0
23+
24+
# Read major versions from versions.json
25+
MAJOR_VERSIONS=$(jq -r '.[]' versions.json)
26+
27+
# Initialize array to store latest versions
28+
LATEST_VERSIONS=()
29+
30+
# For each major version, find the latest release
31+
for VERSION in $MAJOR_VERSIONS; do
32+
# Get latest release for this major version
33+
LATEST=$(curl -s "https://nodejs.org/dist/index.json" | \
34+
jq -r "[.[] | select(.version | startswith(\"$VERSION.\"))] | sort_by(.date) | reverse | .[0].version")
35+
36+
if [ -n "$LATEST" ]; then
37+
echo "Found latest $VERSION: $LATEST"
38+
39+
# Check if this version already exists in GitHub releases
40+
# Using the GitHub API to check if the tag/release exists
41+
RELEASE_EXISTS=$(curl -s -H "Authorization: token ${{github.token}}" \
42+
"https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/tags/${LATEST}" | \
43+
jq -r '.id != null')
44+
45+
if [ "$RELEASE_EXISTS" == "true" ]; then
46+
echo "Release for $LATEST already exists - skipping"
47+
else
48+
echo "Release for $LATEST does not exist - will build"
49+
LATEST_VERSIONS+=("$LATEST")
50+
BUILD_NODE=1
51+
fi
52+
else
53+
echo "No version found for $VERSION"
54+
fi
55+
done
56+
57+
# Create properly escaped JSON for GitHub Actions
58+
MATRIX_JSON=$(jq -c -n --argjson versions "$(printf '%s\n' "${LATEST_VERSIONS[@]}" | jq -R . | jq -s .)" '{"node_version":$versions}')
59+
echo "Matrix JSON: $MATRIX_JSON"
60+
61+
# Setting output with proper delimiter for multiline values
62+
echo "versions<<EOF" >> $GITHUB_OUTPUT
63+
echo "$MATRIX_JSON" >> $GITHUB_OUTPUT
64+
echo "EOF" >> $GITHUB_OUTPUT
65+
66+
echo "buildnode=$BUILD_NODE" >> $GITHUB_OUTPUT
67+
68+
build_release:
69+
name: Build and Release Node.js
70+
needs: get_versions
71+
if: needs.get_versions.outputs.buildnode == 1
72+
strategy:
73+
matrix: ${{ fromJSON(needs.get_versions.outputs.versions) }}
74+
uses: ./.github/workflows/build-release-alpine-nodejs.yml
75+
permissions:
76+
contents: write
77+
with:
78+
NodeVersion: ${{ matrix.node_version }}
79+
80+

versions.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[
2+
"v20",
3+
"v24"
4+
]

0 commit comments

Comments
 (0)