From 1e325976136a10681c68ff728dc81c520738620a Mon Sep 17 00:00:00 2001 From: cortadocodes Date: Tue, 13 Jun 2023 17:54:02 +0100 Subject: [PATCH] OPS: Add GitHub workflows --- .github/workflows/gcloud-deploy.yml | 54 +++++++++++++++++++++++ .github/workflows/release.yml | 34 ++++++++++++++ .github/workflows/update-pull-request.yml | 28 ++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 .github/workflows/gcloud-deploy.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/update-pull-request.yml diff --git a/.github/workflows/gcloud-deploy.yml b/.github/workflows/gcloud-deploy.yml new file mode 100644 index 0000000..2121fad --- /dev/null +++ b/.github/workflows/gcloud-deploy.yml @@ -0,0 +1,54 @@ +# Deploy the production cloud function if pushing to the `main` branch or the test cloud function if pushing to the +# `test` branch. +name: gcloud-deploy + +on: + push: + branches: + - main + - test + +jobs: + get-prefix: + runs-on: ubuntu-latest + outputs: + name_prefix: ${{ steps.prefix.outputs.name_prefix }} + dataset_name_prefix: ${{ steps.prefix.outputs.dataset_name_prefix }} + steps: + - name: Get prefix (test- or nothing for production) + id: prefix + run: | + echo ${{ github.ref }} + if [ "${{ github.ref }}" = "refs/heads/main" ]; then + echo "name_prefix=" >> $GITHUB_OUTPUT + echo "dataset_name_prefix=" >> $GITHUB_OUTPUT + else + echo "name_prefix=test-" >> $GITHUB_OUTPUT + echo "dataset_name_prefix=test_" >> $GITHUB_OUTPUT + fi + + deploy: + permissions: + contents: "read" + id-token: "write" + runs-on: ubuntu-latest + needs: get-prefix + steps: + - id: checkout + uses: actions/checkout@v2 + + - id: auth + uses: google-github-actions/auth@v0 + with: + workload_identity_provider: "projects/885434704038/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider" + service_account: "data-gateway-ci-testing@aerosense-twined.iam.gserviceaccount.com" + + - uses: google-github-actions/deploy-cloud-functions@v0 + with: + name: ${{ needs.get-prefix.outputs.name_prefix }}data-gateway-sessions + source_dir: data_gateway_sessions + entry_point: extract_and_add_new_measurement_sessions + memory_mb: 1024 + region: europe-west6 + runtime: python39 + service_account_email: as-ingress@aerosense-twined.iam.gserviceaccount.com diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..2a14062 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,34 @@ +# Only trigger when a pull request into main branch is merged +on: + pull_request: + types: [closed] + branches: + - main + workflow_dispatch: + +jobs: + release: + # This job will only run if the PR has been merged (and not closed without merging). + if: "github.event.pull_request.merged == true && !contains(github.event.pull_request.head.message, 'skipci')" + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install poetry + run: pip install poetry + + - name: Get package version + id: version + run: echo "::set-output name=package_version::$(poetry version -s)" + + - name: Create release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, no need to create your own. + with: + tag_name: ${{ steps.version.outputs.package_version }} + release_name: ${{ github.event.pull_request.title }} + body: ${{ github.event.pull_request.body }} + draft: false + prerelease: false diff --git a/.github/workflows/update-pull-request.yml b/.github/workflows/update-pull-request.yml new file mode 100644 index 0000000..abc9e4b --- /dev/null +++ b/.github/workflows/update-pull-request.yml @@ -0,0 +1,28 @@ +# This workflow updates the pull request description with an auto-generated section containing the categorised commit +# message headers of the commits since the last pull request merged into main. The auto generated section is enveloped +# between two comments: "" and "". Anything +# outside these in the description is left untouched. Auto-generated updates can be skipped for a commit if +# "" is added to the pull request description. + +name: update-pull-request + +# Only trigger for pull requests into main branch. +on: + pull_request: + +jobs: + description: + if: "!contains(github.event.pull_request.body, '')" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: octue/generate-pull-request-description@1.0.0.beta-2 + id: pr-description + with: + pull_request_url: ${{ github.event.pull_request.url }} + api_token: ${{ secrets.GITHUB_TOKEN }} + - name: Update pull request body + uses: riskledger/update-pr-description@v2 + with: + body: ${{ steps.pr-description.outputs.pull_request_description }} + token: ${{ secrets.GITHUB_TOKEN }}