145 lines
5.0 KiB
YAML
145 lines
5.0 KiB
YAML
name: Build Feature
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
env_json:
|
|
required: true
|
|
type: string
|
|
bats-image:
|
|
required: true
|
|
type: string
|
|
cucumber-node-image:
|
|
required: true
|
|
type: string
|
|
|
|
env:
|
|
GITEA_API_URL: ${{ fromJson(inputs.env_json).GITEA_API_URL }}
|
|
PAGES_HOST: ${{ fromJson(inputs.env_json).PAGES_HOST }}
|
|
GIT_PAGES_PUBLISH_URL: ${{ fromJson(inputs.env_json).GIT_PAGES_PUBLISH_URL }}
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
GIT_PAGES_PUBLISH_TOKEN: ${{ secrets.GIT_PAGES_PUBLISH_TOKEN }}
|
|
|
|
jobs:
|
|
bats:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
repository: niko/gitea-ci-library
|
|
path: .ci
|
|
|
|
- name: Run bats tests
|
|
id: bats-tests
|
|
shell: bash
|
|
run: |
|
|
docker volume create bats-workspace
|
|
tar c . | docker run --rm -i -v bats-workspace:/data alpine tar x -C /data
|
|
mkdir -p "reports/${GITHUB_SHA:0:8}/bats"
|
|
set +e
|
|
docker run --rm -v bats-workspace:/data \
|
|
--entrypoint bash ${{ inputs.bats-image }} \
|
|
-c 'apk add -q lsof python3 jq curl && \
|
|
cd /data && bats tests/ ' \
|
|
> "reports/${GITHUB_SHA:0:8}/bats/results.txt" 2>&1
|
|
BATS_EXIT=$?
|
|
docker volume rm bats-workspace > /dev/null 2>&1
|
|
bash .ci/.gitea/scripts/bats-report.sh "reports/${GITHUB_SHA:0:8}/bats"
|
|
echo "BATS_EXIT=${BATS_EXIT}" >> "${GITHUB_ENV}"
|
|
exit ${BATS_EXIT}
|
|
|
|
- name: Publish bats reports
|
|
if: always()
|
|
shell: bash
|
|
run: |
|
|
bash .ci/scripts/publish-git-pages.sh "bats/" "$PAGES_HOST" "$GIT_PAGES_PUBLISH_URL" "$GIT_PAGES_PUBLISH_TOKEN"
|
|
|
|
- name: Set bats commit status
|
|
if: always()
|
|
shell: bash
|
|
run: |
|
|
if [ "${BATS_EXIT}" = "0" ]; then
|
|
bash .ci/scripts/report-status.sh success "Bats tests" "" "$GITEA_API_URL" "$GITEA_TOKEN" "ci-bats" "$PAGES_HOST" "bats/"
|
|
else
|
|
bash .ci/scripts/report-status.sh failure "Bats tests FAILED" "" "$GITEA_API_URL" "$GITEA_TOKEN" "ci-bats" "$PAGES_HOST" "bats/"
|
|
fi
|
|
|
|
cucumber:
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: ${{ inputs.cucumber-node-image }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
repository: niko/gitea-ci-library
|
|
path: .ci
|
|
|
|
- name: Prepare cucumber
|
|
id: prepare-cucumber
|
|
shell: bash
|
|
run: |
|
|
apt-get update -qq && apt-get install -y -qq --no-install-recommends lsof jq
|
|
if npm install @cucumber/cucumber > /dev/null 2>&1 && \
|
|
npx --package @cucumber/cucumber cucumber-js --dry-run tests/features/ > /dev/null 2>&1; then
|
|
echo "TOOL_OK=true" >> "${GITHUB_ENV}"
|
|
else
|
|
echo "TOOL_OK=false" >> "${GITHUB_ENV}"
|
|
fi
|
|
|
|
- name: Run cucumber tests
|
|
if: always()
|
|
id: cucumber-tests
|
|
shell: bash
|
|
run: |
|
|
if [ "${TOOL_OK}" != "true" ]; then
|
|
echo "CUCUMBER_EXIT=1" >> "${GITHUB_ENV}"
|
|
exit 0
|
|
fi
|
|
mkdir -p "reports/${GITHUB_SHA:0:8}/cucumber"
|
|
set +e
|
|
npx cucumber-js \
|
|
--format json:"reports/${GITHUB_SHA:0:8}/cucumber/report.json" \
|
|
--format html:"reports/${GITHUB_SHA:0:8}/cucumber/index.html" 2>&1
|
|
CUCUMBER_EXIT=$?
|
|
echo "CUCUMBER_EXIT=${CUCUMBER_EXIT}" >> "${GITHUB_ENV}"
|
|
exit ${CUCUMBER_EXIT}
|
|
|
|
- name: Publish cucumber reports
|
|
if: always()
|
|
shell: bash
|
|
run: |
|
|
if [ "${TOOL_OK}" = "true" ]; then
|
|
bash .ci/scripts/publish-git-pages.sh "cucumber/" "$PAGES_HOST" "$GIT_PAGES_PUBLISH_URL" "$GIT_PAGES_PUBLISH_TOKEN"
|
|
fi
|
|
|
|
- name: Set cucumber commit status
|
|
if: always()
|
|
shell: bash
|
|
run: |
|
|
if [ "${TOOL_OK}" != "true" ]; then
|
|
bash .ci/scripts/report-status.sh failure "Cucumber tool unavailable" "" "$GITEA_API_URL" "$GITEA_TOKEN" "ci-cucumber" "$PAGES_HOST"
|
|
elif [ "${CUCUMBER_EXIT}" = "0" ]; then
|
|
bash .ci/scripts/report-status.sh success "Cucumber tests passed" "" "$GITEA_API_URL" "$GITEA_TOKEN" "ci-cucumber" "$PAGES_HOST" "cucumber/"
|
|
else
|
|
bash .ci/scripts/report-status.sh failure "Cucumber tests FAILED" "" "$GITEA_API_URL" "$GITEA_TOKEN" "ci-cucumber" "$PAGES_HOST" "cucumber/"
|
|
fi
|
|
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
needs: [bats, cucumber]
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
repository: niko/gitea-ci-library
|
|
path: .ci
|
|
|
|
- name: Generate report index
|
|
shell: bash
|
|
run: bash .ci/.gitea/scripts/generate-report-index.sh
|
|
|
|
- name: Set build commit status
|
|
run: |
|
|
bash .ci/scripts/report-status.sh success "Build complete" "" "$GITEA_API_URL" "$GITEA_TOKEN" "ci-build" "$PAGES_HOST"
|