diff --git a/.github/workflows/cf.yaml b/.github/workflows/cf.yaml new file mode 100644 index 0000000..3364b8f --- /dev/null +++ b/.github/workflows/cf.yaml @@ -0,0 +1,66 @@ +name: Cloud Foundry + +on: + workflow_call: + inputs: + environment: + default: Staging + type: string + workflow_dispatch: + push: + branches: + - main + pull_request: + +permissions: + contents: read + deployments: write + packages: read + +concurrency: + group: cf-${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +env: + APP_NAME: xtravels + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + FORCE_COLOR: true +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - uses: actions/setup-node@v5 + with: + node-version: 22 + - uses: actions/setup-java@v5 + with: + distribution: sapmachine + java-version: 21 + cache: maven + - uses: cap-js/cf-setup@v1 + with: + cf-api: ${{ vars.CF_API }} + cf-org: ${{ vars.CF_ORG }} + cf-space: ${{ vars.CF_SPACE }} + cf-username: ${{ vars.CF_USERNAME }} + cf-password: ${{ secrets.CF_PASSWORD }} + - run: npm install + - run: npx cds up + + - run: cf logs "${{ env.APP_NAME }}" --recent + if: always() + - run: cf logs "${{ env.APP_NAME }}-srv" --recent + if: always() + - run: cf logs "${{ env.APP_NAME }}-db-deployer" --recent + if: always() + + - name: Get application URL + id: route + shell: bash + run: | + host=$(cf app "${APP_NAME}" | awk '/routes:/ {print $2}' | sed -E 's#^https?://##; s/,.*$//') + echo "url=https://$host" >> "$GITHUB_OUTPUT" + environment: + name: ${{ inputs.environment || 'Staging' }} + url: ${{ steps.route.outputs.url }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..7395d61 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,22 @@ +name: Release + +on: + workflow_dispatch: + release: + types: [published] + +permissions: + contents: read + deployments: write + packages: read + +jobs: + tests: + uses: capire/xtravels-java/.github/workflows/test.yaml@main + secrets: inherit + deploy-cf: + needs: [tests] + uses: capire/xtravels-java/.github/workflows/cf.yaml@main + secrets: inherit + with: + environment: Production diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..ebbf368 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,32 @@ +name: Tests + +on: + workflow_call: + workflow_dispatch: + pull_request: + merge_group: + push: + branches: + - main + +permissions: + contents: read + packages: read + +jobs: + tests: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-node@v5 + with: + node-version: 22 + - uses: actions/checkout@v5 + - run: npm install + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - uses: actions/setup-java@v5 + with: + distribution: sapmachine + java-version: 21 + cache: maven + - run: mvn test -B diff --git a/.npmrc b/.npmrc index 77ed8bc..217fb77 100644 --- a/.npmrc +++ b/.npmrc @@ -1 +1,2 @@ @capire:registry=https://npm.pkg.github.com/ +//npm.pkg.github.com/:_authToken=${NODE_AUTH_TOKEN}