diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index c227a26..e867953 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -24,7 +24,7 @@ jobs: runs-on: ubuntu-latest defaults: run: - working-directory: ${{ inpupts.data_project_dir }} + working-directory: ${{ inputs.data_project_dir }} name: Push changes to Workspace steps: - name: Checkout @@ -56,8 +56,8 @@ jobs: - name: Create new test Environment with data run: | tb \ - --host $TB_HOST \ - --token $ADMIN_TOKEN \ + --host ${{ secrets.tb_host }} \ + --token ${{ secrets.admin_token }} \ env create tmp_cd_${_NORMALIZED_ENV_NAME}_${GITHUB_RUN_ID} \ ${_ENV_FLAGS} @@ -84,11 +84,13 @@ jobs: tb release ls else CD_DEPLOY_FILE=./deploy/${VERSION}/cd-deploy.sh - if [! -f "$CD_DEPLOY_FILE" ]; then + if [ ! -f "$CD_DEPLOY_FILE" ]; then + tb auth \ + --host ${{ secrets.tb_host }} \ + --token ${{ secrets.admin_token }} tb deploy fi fi - fi - name: run post CD deploy commands run: | @@ -100,3 +102,30 @@ jobs: - name: echo result run: echo "A new Release with version $VERSION has been deployed in preview status. When you want to make it live use `tb release promote --semver $VERSION`" + cleanup: + runs-on: ubuntu-latest + defaults: + run: + working-directory: ${{ inputs.data_project_dir }} + if: ${{ always() }} + needs: [push_changes] + steps: + - uses: actions/checkout@master + - uses: actions/setup-python@v3 + with: + python-version: "3.8" + architecture: "x64" + + - name: Install Tinybird CLI + run: pip install tinybird-cli + + - name: Tinybird version + run: tb --version + + - name: Drop Environment + run: | + tb \ + --host ${{ secrets.tb_host }} \ + --token ${{ secrets.admin_token }} \ + env rm tmp_cd_${_NORMALIZED_ENV_NAME}_${GITHUB_RUN_ID} \ + --yes diff --git a/.gitlab/ci_cd.yaml b/.gitlab/ci_cd.yaml index 13ec9f3..cfb1ad3 100644 --- a/.gitlab/ci_cd.yaml +++ b/.gitlab/ci_cd.yaml @@ -1,8 +1,8 @@ stages: - ci - - cleanup - cd + - cleanup variables: PYTHON_VERSION: "3.11" @@ -12,6 +12,8 @@ variables: stage: ci image: ${IMAGE_BASE} interruptible: true + before_script: + - apt-get update && apt-get install -y --no-install-recommends git script: - _ENV_FLAGS="${ENV_FLAGS:=--last-partition --wait}" - cd $CI_PROJECT_DIR/$DATA_PROJECT_DIR @@ -72,6 +74,8 @@ variables: stage: cd image: ${IMAGE_BASE} interruptible: true + before_script: + - apt-get update && apt-get install -y --no-install-recommends git script: - _ENV_FLAGS="${ENV_FLAGS:=--last-partition --wait}" - cd $CI_PROJECT_DIR/$DATA_PROJECT_DIR @@ -121,7 +125,10 @@ variables: tb release ls else CD_DEPLOY_FILE=./deploy/${VERSION}/cd-deploy.sh - if [! -f "$CD_DEPLOY_FILE" ]; then + if [ ! -f "$CD_DEPLOY_FILE" ]; then + tb auth \ + --host $TB_HOST \ + --token $ADMIN_TOKEN tb deploy fi fi @@ -138,7 +145,7 @@ variables: image: ${IMAGE_BASE} script: - cd $CI_PROJECT_DIR/$DATA_PROJECT_DIR - - _NORMALIZED_ENV_NAME=`echo $DATA_PROJECT_DIR | rev | cut -d "/" -f 1 | rev` + - _NORMALIZED_ENV_NAME=$(echo $DATA_PROJECT_DIR | rev | cut -d "/" -f 1 | rev | tr '.-' '_') # Create Python Virtual Environment - python -m venv .venv @@ -163,7 +170,7 @@ variables: image: ${IMAGE_BASE} script: - cd $CI_PROJECT_DIR/$DATA_PROJECT_DIR - - _NORMALIZED_ENV_NAME=`echo $DATA_PROJECT_DIR | rev | cut -d "/" -f 1 | rev` + - _NORMALIZED_ENV_NAME=$(echo $DATA_PROJECT_DIR | rev | cut -d "/" -f 1 | rev | tr '.-' '_') # Create Python Virtual Environment - python -m venv .venv @@ -175,7 +182,7 @@ variables: # Tinybird version - tb --version - # Remove test Environment + # Remove Environment - | tb \ --host $TB_HOST \