From d33f4aa54f06067ceaeb8252bc5f748cb49a6650 Mon Sep 17 00:00:00 2001 From: "darwin.apolinario" Date: Thu, 13 Jun 2024 10:16:46 +0800 Subject: [PATCH] feat(ci): initialize ci --- .github/actions/gcloud/action.yml | 38 +++++++++++++++++++++ .github/workflows/ci.yml | 55 +++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 .github/actions/gcloud/action.yml create mode 100644 .github/workflows/ci.yml diff --git a/.github/actions/gcloud/action.yml b/.github/actions/gcloud/action.yml new file mode 100644 index 0000000..f2425a9 --- /dev/null +++ b/.github/actions/gcloud/action.yml @@ -0,0 +1,38 @@ +name: gcloud +description: gcloud authentication + +inputs: + credentials_json: + description: "The JSON key for authenticating with Google Cloud." + required: true + project_id: + description: "The Google Cloud project ID." + required: true + modules_token: + description: "The token for accessing private modules." + required: true + +runs: + using: "composite" + steps: + - name: โœ… Checkout code + uses: actions/checkout@v4 + + - name: ๐Ÿ˜ˆ Auth with Gcloud + uses: google-github-actions/auth@v2 + with: + credentials_json: ${{ inputs.credentials_json }} + + - name: ๐Ÿ”ง Set up Gcloud SDK + uses: google-github-actions/setup-gcloud@v2 + with: + project_id: ${{ inputs.project_id }} + + - name: ๐Ÿณ Register gcloud as a Docker credential helper + shell: bash + run: gcloud auth configure-docker + + - name: ๐Ÿฅท Granting Private Modules Access + shell: bash + run: | + git config --global url."https://${{ inputs.modules_token }}:x-oauth-basic@github.com/zesty-io".insteadOf "https://github.com/zesty-io" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3989908 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,55 @@ +name: Ci + +on: + pull_request: + branches: [master] + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build-test: + strategy: + matrix: + os: [ubuntu-latest] + node-version: [18, 20, 22] + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + # Reusable workflow + - name: Authenticate in Gcloud + uses: ./.github/actions/gcloud + with: + credentials_json: ${{ secrets.GCP_DEV_SA_KEY }} + project_id: zesty-dev + modules_token: ${{ secrets.GO_MODULES_TOKEN }} + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + + - name: Write the .env file + run: | + echo '${{ secrets.ENV_FILE }}' > .env + + - name: Install dependencies + run: npm install + + - name: ๐Ÿงช Run unit tests + run: npm run test + + tests-pass: + needs: [build-test] + + if: always() + runs-on: ubuntu-latest + name: ๐Ÿš€๐Ÿš€๐Ÿš€ Ok to Merge ๐Ÿ˜Ž ๐Ÿ‘๐Ÿ‘๐Ÿ‘ + steps: + - run: exit 1 + if: ${{ always() && (contains(needs.*.result, 'failure') || contains(needs.*.result, 'skipped') || contains(needs.*.result, 'cancelled')) }}