diff --git a/.github/actions/lifecycle/action.yml b/.github/actions/lifecycle/action.yml new file mode 100644 index 0000000000..768625293d --- /dev/null +++ b/.github/actions/lifecycle/action.yml @@ -0,0 +1,54 @@ +name: "RHDH lifecycle" +description: "Runs scripts/lifecycle.ts: supported RHDH release branches, the previous Y-stream, or whether a stream is EOL, from the Red Hat Product Life Cycles API" + +inputs: + command: + description: "active-branches, previous-y-stream or is-eol" + required: true + stream: + description: "X.Y stream for previous-y-stream and is-eol" + required: false + default: "" + repository-url: + description: "Repository whose release-* branches are read (default: redhat-developer/rhdh)" + required: false + default: "" +outputs: + result: + description: "Three possible outputs, depending on command used. 1. active-branches: space-separated list of branches, from oldest to newest, then main. 2. previous-y-stream: X.Y. 3. is-eol: true or false" + value: ${{ steps.run.outputs.result }} + +runs: + using: "composite" + steps: + - name: Set up Node.js + uses: actions/setup-node@8fccf151e3ba8038c300f83b40c8fd1e94f9c5ce # v7.2.0 + with: + # The project's Node version, so the action moves with the rest of rhdh. + node-version-file: ${{ github.action_path }}/../../../.nvmrc + + - name: Run scripts/lifecycle.ts + id: run + shell: bash + env: + COMMAND: ${{ inputs.command }} + STREAM: ${{ inputs.stream }} + LIFECYCLE_REPO_URL: ${{ inputs.repository-url }} + # A remote action is checked out with its whole repository. + SCRIPT: ${{ github.action_path }}/../../../scripts/lifecycle.ts + run: | + args=("${COMMAND}") + [[ -n "${STREAM}" ]] && args+=("${STREAM}") + status=0 + result=$(node "${SCRIPT}" "${args[@]}") || status=$? + if [[ "${COMMAND}" == "is-eol" && "${status}" -le 1 ]]; then + # is-eol answers through its exit code: 0 EOL, 1 not EOL or unknown. + result=$([[ "${status}" -eq 0 ]] && echo true || echo false) + status=0 + fi + if [[ "${status}" -ne 0 ]]; then + echo "::error::lifecycle.ts ${COMMAND} failed with exit code ${status}" + exit "${status}" + fi + echo "${COMMAND}: ${result}" + echo "result=${result}" >> "${GITHUB_OUTPUT}" diff --git a/.github/workflows/e2e-tests-lint.yaml b/.github/workflows/e2e-tests-lint.yaml index b5fac7f89f..061f3074a4 100644 --- a/.github/workflows/e2e-tests-lint.yaml +++ b/.github/workflows/e2e-tests-lint.yaml @@ -7,6 +7,7 @@ on: - 'scripts/lifecycle*.ts' - 'scripts/package.json' - 'scripts/tsconfig.lifecycle.json' + - '.github/actions/lifecycle/**' - '.shellcheckrc' push: branches: @@ -17,6 +18,7 @@ on: - 'scripts/lifecycle*.ts' - 'scripts/package.json' - 'scripts/tsconfig.lifecycle.json' + - '.github/actions/lifecycle/**' - '.shellcheckrc' permissions: @@ -63,6 +65,23 @@ jobs: yarn --cwd e2e-tests tsc -p ../scripts/tsconfig.lifecycle.json node --test scripts/lifecycle.test.ts + # Smoke-test the action other repositories use (RHIDP-19630). + - name: Run the lifecycle action + id: lifecycle + uses: ./.github/actions/lifecycle + with: + command: previous-y-stream + stream: "99.0" + + - name: Check the lifecycle action output + env: + RESULT: ${{ steps.lifecycle.outputs.result }} + run: | + [[ "${RESULT}" =~ ^[0-9]+\.[0-9]+$ ]] || { + echo "::error::expected an X.Y stream, got '${RESULT}'" + exit 1 + } + - name: Run ShellCheck working-directory: ./e2e-tests env: diff --git a/scripts/lifecycle.ts b/scripts/lifecycle.ts index b52584b20a..a04c0ead5c 100755 --- a/scripts/lifecycle.ts +++ b/scripts/lifecycle.ts @@ -12,6 +12,8 @@ * branch and previous-y-stream answers from the branches. Without git, * previous-y-stream and active-branches fail. * + * GitHub workflows can run it through .github/actions/lifecycle. + * * Requires Node 22.18+ and git, no packages. LIFECYCLE_API_URL, LIFECYCLE_REPO_URL * and LIFECYCLE_TODAY (YYYY-MM-DD) override the endpoint, the repository whose * release-* branches are read (default: redhat-developer/rhdh), and the date.