Skip to content

Commit

Permalink
Add CI to deploy changes generated in a branch (#545)
Browse files Browse the repository at this point in the history
* Add preflight to check egress requirements

* Add the new preflight

* Add CI to deploy changes generated in a branch

* Fix

* Fix

* Add step to deploy changes

* Fix

* Fix channel name

* Add workflow to delete channel

* Finish delete channel

* Fix

* Fixes

* Fixes

* Last changes

* Last one

* Fix
  • Loading branch information
moicalcob authored Jun 4, 2024
1 parent 08d2abe commit 0be1599
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 0 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/branch-changes-delete.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Delete Branch Changes
on:
pull_request:
types: [closed, unlabeled] # Trigger on close and unlabel events in pull requests

jobs:
delete-changes:
timeout-minutes: 3
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Replicated CLI
shell: bash
run: |
curl -s https://api.github.com/repos/replicatedhq/replicated/releases/latest \
| grep "browser_download_url.*linux_amd64.tar.gz" \
| cut -d : -f 2,3 \
| tr -d \" \
| wget -O replicated.tar.gz -qi -
tar xf replicated.tar.gz replicated && rm replicated.tar.gz
mv replicated /usr/local/bin/replicated
- name: Generate channel name
id: generate-channel-info
shell: bash
run: |
GITHUB_BRANCH_NAME=${GITHUB_HEAD_REF}
# Cleaning refs/*/
# refs/whatever/main => main
export GITHUB_BRANCH_NAME=${GITHUB_BRANCH_NAME#refs/[a-z]*/}
# Normalize image tags characters
# my-branch/test-01 => my-branch_test-01
export NORMALIZED_GIT_BRANCH_NAME=${GITHUB_BRANCH_NAME//[^[:alnum:]]/_}
# To lowercase all characters
export NORMALIZED_GIT_BRANCH_NAME=${NORMALIZED_GIT_BRANCH_NAME,,}
# Set maximum 128 characters for image name
export NORMALIZED_GIT_BRANCH_NAME=${NORMALIZED_GIT_BRANCH_NAME:0:127}
# Share the variable for further steps
echo "channel-name=${NORMALIZED_GIT_BRANCH_NAME}" >> "$GITHUB_OUTPUT"
echo "version=$(yq .version -r chart/Chart.yaml)" >> "$GITHUB_OUTPUT"
- name: Check if channel assigned to PR exists
id: check-if-channel-exists
shell: bash
env:
REPLICATED_APP: carto
REPLICATED_API_TOKEN: ${{ secrets.REPLICATED_API_TOKEN }}
run: |
CHANNEL_DELETE_REQUIRED="false"
if replicated channel ls | grep -q ${{ steps.generate-channel-info.outputs.channel-name }}; then
CHANNEL_DELETE_REQUIRED="true"
fi
echo "channel-exists=${CHANNEL_DELETE_REQUIRED}" >> ${GITHUB_OUTPUT}
- name: Delete channel
if: steps.check-if-channel-exists.outputs.channel-exists == 'true'
shell: bash
env:
REPLICATED_APP: carto
REPLICATED_API_TOKEN: ${{ secrets.REPLICATED_API_TOKEN }}
run: |
CHANNEL_ID=$(replicated channel ls | grep ${{ steps.generate-channel-info.outputs.channel-name }} | awk '{print $1}')
replicated channel rm $CHANNEL_ID
63 changes: 63 additions & 0 deletions .github/workflows/branch-changes-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Release Branch Changes
on:
pull_request:
types: [labeled, synchronize] # Trigger on label and push events in pull requests

jobs:
release-changes:
if: |
github.event.label.name == 'release-changes' || (
github.event_name == 'pull_request' &&
contains(github.event.pull_request.labels.*.name, 'release-changes')
)
timeout-minutes: 3
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Generate channel name
id: generate-channel-info
shell: bash
run: |
GITHUB_BRANCH_NAME=${GITHUB_HEAD_REF}
# Cleaning refs/*/
# refs/whatever/main => main
export GITHUB_BRANCH_NAME=${GITHUB_BRANCH_NAME#refs/[a-z]*/}
# Normalize image tags characters
# my-branch/test-01 => my-branch_test-01
export NORMALIZED_GIT_BRANCH_NAME=${GITHUB_BRANCH_NAME//[^[:alnum:]]/_}
# To lowercase all characters
export NORMALIZED_GIT_BRANCH_NAME=${NORMALIZED_GIT_BRANCH_NAME,,}
# Set maximum 128 characters for image name
export NORMALIZED_GIT_BRANCH_NAME=${NORMALIZED_GIT_BRANCH_NAME:0:127}
# Share the variable for further steps
echo "channel-name=${NORMALIZED_GIT_BRANCH_NAME}" >> "$GITHUB_OUTPUT"
echo "version=$(yq .version -r chart/Chart.yaml)" >> "$GITHUB_OUTPUT"
- name: Publish changes into channel
uses: ./.github/actions/publish-release
with:
replicated-channel: ${{ steps.generate-channel-info.outputs.channel-name }}
version: ${{ steps.generate-channel-info.outputs.version }}
release-notes: "CARTO Self-Hosted dev version generated from branch ${{ steps.generate-channel-info.outputs.channel-name }}"
trigger-action: "dev"
gcloud-service-account: ${{ secrets.CARTO_ARTIFACTS_SERVICE_ACCOUNT }}
replicated-api-token: ${{ secrets.REPLICATED_API_TOKEN }}

- name: Comment on PR
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `Changes release to Replicated on channel ${{ steps.generate-channel-info.outputs.channel-name }}! Check the [Replicated Dashboard](https://vendor.replicated.com/apps/carto/channels) for more details.
If you need to test the changes, you can assign the channel to your customer and download the latest version from the Admin Console.`
})

0 comments on commit 0be1599

Please sign in to comment.