From 093517d06c524e5990d38df7686d3f55efa934ea Mon Sep 17 00:00:00 2001 From: Viresh Soedhwa Date: Fri, 1 Aug 2025 22:17:38 -0700 Subject: [PATCH] include workflow files for creation and deletion --- .github/workflows/create-codespace-dagger.yml | 37 ++++++++++++++++++ .github/workflows/delete-codespace-dagger.yml | 38 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 .github/workflows/create-codespace-dagger.yml create mode 100644 .github/workflows/delete-codespace-dagger.yml diff --git a/.github/workflows/create-codespace-dagger.yml b/.github/workflows/create-codespace-dagger.yml new file mode 100644 index 0000000..4cfc0b7 --- /dev/null +++ b/.github/workflows/create-codespace-dagger.yml @@ -0,0 +1,37 @@ +name: Codespace Creation +description: This workflow runs when a pull request is opened, reopened, or synchronized. It uses Dagger to create a codespace for the PR. + +on: + pull_request: + types: [synchronize, opened, reopened] + +jobs: + codespace-manager: + name: Codespace Manager + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + # - name: Print all ENVS + # run: printenv + - name: Create Codespace with Dagger + uses: dagger/dagger-for-github@8.0.0 + env: + # setting tokens here so that it can be referenced below without exposing in dagger cloud logs + # should be referenced as env://GITHUB_TOKEN in the Dagger module + GITHUB_TOKEN: ${{ github.token }} + CODESPACE_TOKEN: ${{ secrets.CODESPACES_PAT }} + with: + module: github.com/BCIT-LTC/daggerverse/codespace-manager@40-codespace-manager-module + call: >- + create-codespace-by-pull-request + --source=. + --token=env://CODESPACE_TOKEN + --organization=${{ github.repository_owner }} + --repo_name=${{ github.event.repository.name }} + --branch_name=${{ github.event.pull_request.head.ref }} + --pull_request_number=${{ github.event.pull_request.number }} + cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }} + version: "latest" + + diff --git a/.github/workflows/delete-codespace-dagger.yml b/.github/workflows/delete-codespace-dagger.yml new file mode 100644 index 0000000..52fe09c --- /dev/null +++ b/.github/workflows/delete-codespace-dagger.yml @@ -0,0 +1,38 @@ +name: Codespace Deletion +description: This workflow runs when a pull request is closed. It uses Dagger to delete the codespace associated with the PR. + +on: + pull_request: + types: [closed] + +jobs: + + codespace-manager: + name: Codespace Manager + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + # - name: Print all ENVS + # run: printenv + - name: Delete Codespace with Dagger + uses: dagger/dagger-for-github@8.0.0 + env: + # setting tokens here so that it can be referenced below without exposing in dagger cloud logs + # should be referenced as env://GITHUB_TOKEN in the Dagger module + GITHUB_TOKEN: ${{ github.token }} + CODESPACE_TOKEN: ${{ secrets.CODESPACES_PAT }} + with: + module: github.com/BCIT-LTC/daggerverse/codespace-manager@40-codespace-manager-module + call: >- + delete-codespace-by-pull-request + --source=. + --token=env://CODESPACE_TOKEN + --organization=${{ github.repository_owner }} + --repo_name=${{ github.event.repository.name }} + --branch_name=${{ github.event.pull_request.head.ref }} + --pull_request_number=${{ github.event.pull_request.number }} + cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }} + version: "latest" + +