name: Build and Release Alpine Node.js on Schedule permissions: contents: write on: schedule: - cron: '0 0 * * 0' # Every Sunday at midnight workflow_dispatch: jobs: get_versions: outputs: versions: ${{ steps.set-matrix.outputs.versions }} buildnode: ${{ steps.set-matrix.outputs.buildnode }} name: Find versions to build and release runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Find latest versions from each major version id: set-matrix run: | BUILD_NODE=0 # Read major versions from versions.json MAJOR_VERSIONS=$(jq -r '.[]' versions.json) # Initialize array to store latest versions LATEST_VERSIONS=() # For each major version, find the latest release for VERSION in $MAJOR_VERSIONS; do # Get latest release for this major version LATEST=$(curl -s "https://nodejs.org/dist/index.json" | \ jq -r "[.[] | select(.version | startswith(\"$VERSION.\"))] | sort_by(.date) | reverse | .[0].version") if [ -n "$LATEST" ]; then echo "Found latest $VERSION: $LATEST" # Check if this version already exists in GitHub releases # Using the GitHub API to check if the tag/release exists RELEASE_EXISTS=$(curl -s -H "Authorization: token ${{github.token}}" \ "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/tags/${LATEST}" | \ jq -r '.id != null') if [ "$RELEASE_EXISTS" == "true" ]; then echo "Release for $LATEST already exists - skipping" else echo "Release for $LATEST does not exist - will build" LATEST_VERSIONS+=("$LATEST") BUILD_NODE=1 fi else echo "No version found for $VERSION" fi done # Create properly escaped JSON for GitHub Actions MATRIX_JSON=$(jq -c -n --argjson versions "$(printf '%s\n' "${LATEST_VERSIONS[@]}" | jq -R . | jq -s .)" '{"node_version":$versions}') echo "Matrix JSON: $MATRIX_JSON" # Setting output with proper delimiter for multiline values echo "versions<> $GITHUB_OUTPUT echo "$MATRIX_JSON" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT echo "buildnode=$BUILD_NODE" >> $GITHUB_OUTPUT build_release: name: Build and Release Node.js needs: get_versions if: needs.get_versions.outputs.buildnode == 1 strategy: matrix: ${{ fromJSON(needs.get_versions.outputs.versions) }} uses: ./.github/workflows/build-release-alpine-nodejs.yml permissions: contents: write with: NodeVersion: ${{ matrix.node_version }}