diff --git a/.github/actions/setup-node-from-opencast/action.yml b/.github/actions/setup-node-from-opencast/action.yml new file mode 100644 index 0000000000..561673851b --- /dev/null +++ b/.github/actions/setup-node-from-opencast/action.yml @@ -0,0 +1,32 @@ +name: Set up Node.js like Opencast +description: Install the Node.js version declared as in the pom.xml of the matching Opencast branch + +inputs: + branch: + description: Branch of this repository. The Node.js version of the Opencast branch with the same name is used, or the one of develop if there is no such branch. + required: true + +runs: + using: composite + steps: + - name: determine node.js version + id: opencast + shell: bash + env: + BRANCH: ${{ inputs.branch }} + run: | + set -eu + # Only develop and the release branches exist in Opencast + case "${BRANCH}" in + develop|r/*) ;; + *) BRANCH=develop ;; + esac + curl -fsS "https://raw.githubusercontent.com/opencast/opencast/refs/heads/${BRANCH}/pom.xml" -o "${RUNNER_TEMP}/opencast-pom.xml" + version="$(sed -n 's/.*v\{0,1\}\([^<]*\)<.*/\1/p' "${RUNNER_TEMP}/opencast-pom.xml" | head -n1)" + test -n "${version}" + echo "Using Node.js ${version} from the pom.xml of Opencast ${BRANCH}" + echo "version=${version}" >> "${GITHUB_OUTPUT}" + + - uses: actions/setup-node@v7 + with: + node-version: ${{ steps.opencast.outputs.version }} diff --git a/.github/workflows/deploy-main-branches.yml b/.github/workflows/deploy-main-branches.yml index ce7da092ed..e56482abca 100644 --- a/.github/workflows/deploy-main-branches.yml +++ b/.github/workflows/deploy-main-branches.yml @@ -11,9 +11,6 @@ concurrency: group: ${{ github.workflow }} cancel-in-progress: false -env: - NODE_VERSION: 24 - jobs: detect-repo-owner: name: Detect branch and appropriate server @@ -47,17 +44,10 @@ jobs: - name: Checkout sources uses: actions/checkout@v7 - - name: Ensure our node version matches the main repo's version - run: | - [[ "$(curl -s https://raw.githubusercontent.com/opencast/opencast/refs/heads/${{ github.ref_name }}/pom.xml | \ - grep node.version | grep -Eo 'v[0-9.]+' | cut -f 1 -d '.' | cut -c 2-)" == "$NODE_VERSION" ]] \ - && exit 0 \ - || (echo "Node version does not match"; exit 1) - - - name: Get Node.js - uses: actions/setup-node@v7 + - name: Get Node.js in the version Opencast uses + uses: ./.github/actions/setup-node-from-opencast with: - node-version: ${{ env.NODE_VERSION }} + branch: ${{ github.ref_name }} - name: Run npm ci run: npm ci diff --git a/.github/workflows/pr-build-test-branch.yml b/.github/workflows/pr-build-test-branch.yml index 54f1594887..17f6dc8c58 100644 --- a/.github/workflows/pr-build-test-branch.yml +++ b/.github/workflows/pr-build-test-branch.yml @@ -10,9 +10,6 @@ concurrency: group: pull-request-page cancel-in-progress: false -env: - NODE_VERSION: 24 - jobs: detect-repo-owner: if: github.repository_owner == 'opencast' @@ -47,10 +44,10 @@ jobs: - name: Checkout sources uses: actions/checkout@v7 - - name: Get Node.js - uses: actions/setup-node@v7 + - name: Get Node.js in the version Opencast uses + uses: ./.github/actions/setup-node-from-opencast with: - node-version: ${{ env.NODE_VERSION }} + branch: ${{ github.base_ref }} - name: Run npm ci run: npm ci diff --git a/.github/workflows/pr-test-build.yml b/.github/workflows/pr-test-build.yml index d9c12c1c9e..908561ed42 100644 --- a/.github/workflows/pr-test-build.yml +++ b/.github/workflows/pr-test-build.yml @@ -6,9 +6,6 @@ on: - 'dependabot/**' pull_request: -env: - NODE_VERSION: 24 - jobs: check-npm-build: runs-on: ubuntu-latest @@ -16,28 +13,10 @@ jobs: - name: Checkout sources uses: actions/checkout@v7 - - name: Ensure our node version matches the main repo's version for pull requests - if: github.event_name == 'pull_request' - run: | - curl -s https://raw.githubusercontent.com/opencast/opencast/refs/heads/${{ github.base_ref }}/pom.xml -o pom.xml - export FOUND_VERSION="$(grep node.version pom.xml | grep -Eo 'v[0-9.]+' | cut -f 1 -d '.' | cut -c 2-)" - [[ "$FOUND_VERSION" == "$NODE_VERSION" ]] \ - && exit 0 \ - || (echo "Node version does not match. Expected $NODE_VERSION, found $FOUND_VERSION"; exit 1) - - - name: Ensure our node version matches the main repo's version for push events - if: github.event_name == 'push' && (startsWith('r/', github.ref_name) || 'develop' == github.ref_name) - run: | - curl -s https://raw.githubusercontent.com/opencast/opencast/refs/heads/${{ github.ref_name }}/pom.xml -o pom.xml - export FOUND_VERSION="$(grep node.version pom.xml | grep -Eo 'v[0-9.]+' | cut -f 1 -d '.' | cut -c 2-)" - [[ "$FOUND_VERSION" == "$NODE_VERSION" ]] \ - && exit 0 \ - || (echo "Node version does not match. Expected $NODE_VERSION, found $FOUND_VERSION"; exit 1) - - - name: Get Node.js - uses: actions/setup-node@v7 + - name: Get Node.js in the version Opencast uses + uses: ./.github/actions/setup-node-from-opencast with: - node-version: ${{ env.NODE_VERSION }} + branch: ${{ github.base_ref || github.ref_name }} - name: Run npm ci run: npm ci