Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI to deploy changes generated in a branch #545

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
alvarorm22 marked this conversation as resolved.
Show resolved Hide resolved
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.`
})
Loading