Helm test #1
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy PR to Kubernetes | |
on: | |
pull_request: | |
types: [opened, synchronize, reopened, closed] | |
workflow_run: | |
workflows: ["tests"] | |
branches: [main] | |
types: | |
- completed | |
jobs: | |
deploy: | |
if: github.event.action != 'closed' | |
runs-on: ubuntu-latest | |
environment: pr${{ github.event.pull_request.number }} | |
concurrency: pr${{ github.event.pull_request.number }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Setup Helm | |
uses: azure/setup-helm@v3 | |
with: | |
version: v3.15.0 | |
- name: Setup Kubectl | |
uses: azure/setup-kubectl@v3 | |
with: | |
version: v1.30.1 | |
- name: Authenticate to Kubernetes cluster | |
run: | | |
echo "${{ secrets.KUBECONFIG }}" > $HOME/.kube/config | |
- name: Get branch name | |
id: branch | |
run: echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV | |
- name: Determine tag | |
id: determine-tag | |
run: | | |
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then | |
SEM_VERSION="${GITHUB_REF#refs/tags/}" | |
else | |
SEM_VERSION="0.0.0-${{ env.BRANCH_NAME }}" | |
fi | |
echo "SEM_VERSION=${SEM_VERSION}" >> $GITHUB_ENV | |
- name: Update chart dependencies | |
run: helm dependency update helm/artemis | |
- name: Chart | Push | |
uses: appany/helm-oci-chart-releaser@v0.3.0 | |
with: | |
name: artemis | |
repository: ${{ github.repository_owner }}/artemis | |
tag: ${{ env.SEM_VERSION }} | |
path: helm/artemis | |
registry: ghcr.io | |
registry_username: ${{ github.repository_owner }} | |
registry_password: ${{ secrets.GITHUB_TOKEN }} | |
update_dependencies: 'true' | |
- name: Deploy Helm chart | |
run: | | |
helm upgrade --install artemis-pr${{ github.event.pull_request.number }} \ | |
oci://ghcr.io/${{ github.repository_owner }}/artemis:${{ env.SEM_VERSION }} \ | |
--namespace artemis-pr${{ github.event.pull_request.number }} --create-namespace \ | |
--wait | |
- name: Post Deployment Comment | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const prNumber = context.issue.number; | |
const branchName = process.env.BRANCH_NAME; | |
const semVersion = process.env.SEM_VERSION; | |
github.rest.issues.createComment({ | |
...context.repo, | |
issue_number: prNumber, | |
body: `:rocket: Deployed **PR #${prNumber}** to https://pr${prNumber}.artemis-k8s.ase.cit.tum.de` | |
}); | |
destroy: | |
if: github.event.action == 'closed' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Setup Helm | |
uses: azure/setup-helm@v3 | |
with: | |
version: v3.15.0 | |
- name: Setup Kubectl | |
uses: azure/setup-kubectl@v3 | |
with: | |
version: v1.30.1 | |
- name: Authenticate to Kubernetes cluster | |
run: | | |
echo "${{ secrets.KUBECONFIG }}" > $HOME/.kube/config | |
- name: Delete Helm release | |
run: | | |
helm uninstall artemis-${{ github.event.pull_request.number }} --namespace pr${{ github.event.pull_request.number }} | |
- name: Delete Kubernetes namespace | |
run: | | |
kubectl delete namespace pr${{ github.event.pull_request.number }} |