|
| 1 | +name: "Integration tests" |
| 2 | +description: "Run tests with BTP services being bound" |
| 3 | +inputs: |
| 4 | + CF_API: |
| 5 | + description: "Cloud Foundry API endpoint" |
| 6 | + required: true |
| 7 | + CF_USERNAME: |
| 8 | + description: "Cloud Foundry username" |
| 9 | + required: true |
| 10 | + CF_PASSWORD: |
| 11 | + description: "Cloud Foundry password" |
| 12 | + required: true |
| 13 | + CF_ORG: |
| 14 | + description: "Cloud Foundry organization" |
| 15 | + required: true |
| 16 | + CF_SPACE: |
| 17 | + description: "Cloud Foundry space" |
| 18 | + required: true |
| 19 | + NODE_VERSION: |
| 20 | + description: "Node.js version to use for tests" |
| 21 | + required: true |
| 22 | +runs: |
| 23 | + using: "composite" |
| 24 | + steps: |
| 25 | + - name: Install dependencies and Cloud Foundry CLI (v8.9.0) |
| 26 | + shell: bash |
| 27 | + run: | |
| 28 | + sudo apt-get update |
| 29 | + sudo apt-get install -y libc6 wget tar |
| 30 | + wget "https://packages.cloudfoundry.org/stable?release=linux64-binary&version=8.9.0&source=github-rel" -O cf-cli.tar.gz |
| 31 | + tar -xvzf cf-cli.tar.gz |
| 32 | + sudo mv cf /usr/local/bin/ |
| 33 | + sudo mv cf8 /usr/local/bin/ |
| 34 | + cf --version |
| 35 | +
|
| 36 | + - name: Authenticate with Cloud Foundry |
| 37 | + shell: bash |
| 38 | + run: | |
| 39 | + echo "::debug::CF_API=${{ inputs.CF_API }}" |
| 40 | + for i in {1..3}; do |
| 41 | + cf login -a ${{ inputs.CF_API }} -u ${{ inputs.CF_USERNAME }} -p ${{ inputs.CF_PASSWORD }} -o ${{ inputs.CF_ORG }} -s ${{ inputs.CF_SPACE }} && break |
| 42 | + echo "cf login failed, retrying ($i/3)..." |
| 43 | + sleep 10 |
| 44 | + if [ "$i" -eq 3 ]; then |
| 45 | + echo "❌ cf login failed after 3 attempts." |
| 46 | + exit 1 |
| 47 | + fi |
| 48 | + done |
| 49 | +
|
| 50 | + - uses: actions/checkout@v5 |
| 51 | + with: |
| 52 | + ref: ${{ github.event.pull_request.head.sha || github.sha }} |
| 53 | + - name: Use Node.js ${{ inputs.NODE_VERSION}} |
| 54 | + uses: actions/setup-node@v6 |
| 55 | + with: |
| 56 | + node-version: ${{ inputs.NODE_VERSION }} |
| 57 | + - name: Set CDS version-specific dependencies |
| 58 | + shell: bash |
| 59 | + run: | |
| 60 | + if [ "${{ matrix.cds-version }}" == "8" ]; then |
| 61 | + echo "Installing CDS 8 compatible packages..." |
| 62 | + npm pkg set "devDependencies.@cap-js/sqlite=^1.0.0" |
| 63 | + npm pkg set "overrides.@cap-js/sqlite=^1.0.0" |
| 64 | + npm pkg set "overrides.@cap-js/hana=^1.0.0" |
| 65 | + npm pkg set "overrides.@cap-js/db-service=^1.0.0" |
| 66 | + cd tests/bookshop |
| 67 | + npm pkg set "dependencies.@cap-js/hana=^1.0.0" |
| 68 | + npm pkg set "dependencies.@cap-js/db-service=^1.0.0" |
| 69 | + cd ../.. |
| 70 | + cd tests/bookshop-mtx |
| 71 | + npm pkg set "dependencies.@cap-js/hana=^1.0.0" |
| 72 | + npm pkg set "dependencies.@cap-js/db-service=^1.0.0" |
| 73 | + cd ../.. |
| 74 | + fi |
| 75 | +
|
| 76 | + - name: Install global CDS |
| 77 | + shell: bash |
| 78 | + run: npm i -g @sap/cds-dk@${{ matrix.cds-version }} |
| 79 | + - name: Install root dependencies |
| 80 | + shell: bash |
| 81 | + run: | |
| 82 | + npm install @sap/cds@${{ matrix.cds-version }} |
| 83 | + npm install |
| 84 | + - name: Install bookshop dependencies |
| 85 | + shell: bash |
| 86 | + run: | |
| 87 | + cd tests/bookshop && npm install @sap/cds@${{ matrix.cds-version }} |
| 88 | + cd tests/bookshop && npm install |
| 89 | + - name: Install bookshop mtx dependencies |
| 90 | + shell: bash |
| 91 | + run: | |
| 92 | + cd tests/bookshop-mtx && npm install @sap/cds@${{ matrix.cds-version }} |
| 93 | + cd tests/bookshop-mtx && npm install |
| 94 | + |
| 95 | + - name: Set node env for HANA |
| 96 | + run: echo "NODE_VERSION_HANA=$(echo ${{ inputs.NODE_VERSION }} | tr . _)" >> $GITHUB_ENV |
| 97 | + shell: bash |
| 98 | + - name: Set node env for CDS |
| 99 | + run: echo "CDS_VERSION=$(echo ${{ matrix.cds-version }} | tr . _)" >> $GITHUB_ENV |
| 100 | + shell: bash |
| 101 | + - name: CDS Versions being used |
| 102 | + run: cds v -i |
| 103 | + shell: bash |
| 104 | + |
| 105 | + # Deploy model to HANA |
| 106 | + - name: Create HDI Container |
| 107 | + shell: bash |
| 108 | + run: cf create-service hana hdi-shared cap-js-change-tracking-hana-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}-$NODE_VERSION_HANA-$CDS_VERSION |
| 109 | + - run: cd tests/bookshop/ && cds deploy --to hana:cap-js-change-tracking-hana-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}-$NODE_VERSION_HANA-$CDS_VERSION |
| 110 | + shell: bash |
| 111 | + |
| 112 | + # Bind against BTP services |
| 113 | + - run: cds bind db -2 cap-js-change-tracking-hana-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}-$NODE_VERSION_HANA-$CDS_VERSION -o package.json |
| 114 | + shell: bash |
| 115 | + |
| 116 | + # Run tests in hybrid mode |
| 117 | + - run: cds bind --exec npm run test |
| 118 | + shell: bash |
| 119 | + |
| 120 | + # Cleanup BTP services |
| 121 | + - name: Delete HDI Container Key |
| 122 | + if: ${{ always() }} |
| 123 | + run: cf delete-service-key cap-js-change-tracking-hana-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}-$NODE_VERSION_HANA-$CDS_VERSION cap-js-change-tracking-hana-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}-$NODE_VERSION_HANA-$CDS_VERSION-key -f |
| 124 | + shell: bash |
| 125 | + |
| 126 | + # Note: The initial delete attempt often fails due to an "ongoing operation on service binding" error. |
| 127 | + - name: Delete HDI Container |
| 128 | + if: ${{ always() }} |
| 129 | + shell: bash |
| 130 | + run: | |
| 131 | + for i in {1..3}; do |
| 132 | + cf delete-service cap-js-change-tracking-hana-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}-$NODE_VERSION_HANA-$CDS_VERSION -f && break |
| 133 | + echo "HDI container delete failed, retrying ($i/3)..." |
| 134 | + sleep 10 |
| 135 | + if [ "$i" -eq 3 ]; then |
| 136 | + echo "❌ HDI container delete failed after 3 attempts." |
| 137 | + exit 1 |
| 138 | + fi |
| 139 | + done |
0 commit comments