Skip to content

Change writing to file functionality #141

Change writing to file functionality

Change writing to file functionality #141

Workflow file for this run

name: Update Values File
on:
push:
branches:
- main
- dev
tags:
- "v*" # Triggered by tags starting with 'v'
jobs:
update-values:
runs-on: ubuntu-latest
steps:
- name: echo Hello
run: echo "Hello"
# - name: Generate a token
# id: generate-token
# uses: actions/create-github-app-token@v1
# with:
# app-id: ${{ secrets.GITOPS_RUNNER_APP_ID }}
# private-key: ${{ secrets.GITOPS_RUNNER_PRIVATE_KEY }}
# owner: ditkrg
# repositories: "pilgrimage-gitops-duplicate"
# - uses: actions/checkout@v4
# with:
# repository: ditkrg/pilgrimage-gitops-duplicate
# token: ${{ steps.generate-token.outputs.token }}
# - name: Determine Environment
# id: env
# run: |
# if [[ $GITHUB_REF == refs/tags/* ]]; then
# environment=production
# elif [[ $GITHUB_REF == refs/heads/main ]]; then
# environment=staging
# else
# environment=dev
# fi
# echo "::set-output name=environment::${environment}"
# - name: Determine Component Name
# id: component
# run: |
# component=oauth2-proxy
# echo "::set-output name=component::${component}"
# - id: get-environment
# run: |
# if [[ $GITHUB_REF == refs/tags/* ]]; then
# environment=production
# elif [[ $GITHUB_REF == refs/heads/main ]]; then
# environment=staging
# else
# environment=dev
# fi
# echo "::set-output name=environment::${environment}"
# - id: find-target-file
# run: |
# environment=${{ steps.env.outputs.environment }}
# component=${{ steps.component.outputs.component }}
# if [ $environment == "production" ]; then
# target_file="overlays/production/image.yaml"
# elif [ $environment == "staging" ]; then
# target_file="overlays/staging/image.yaml"
# else
# target_file="overlays/development/image.yaml"
# fi
# echo "::set-output name=target_file::${target_file}"
# - id: create-label
# run: |
# # Define your GitHub repository and access token
# REPO="ditkrg/pilgrimage-gitops-duplicate"
# # Define the label you want to check and create if it doesn't exist
# LABEL_NAME="autodeploy"
# LABEL_COLOR="00FF00" # You can specify a color in hexadecimal format
# # Make a request to fetch the list of labels
# response=$(curl -s -H "Authorization: token ${{ steps.generate-token.outputs.token }}" "https://api.github.com/repos/$REPO/labels")
# # Check if the label exists in the response
# if [[ "$response" == *"$LABEL_NAME"* ]]; then
# echo "Label '$LABEL_NAME' exists in the repository."
# else
# echo "Label '$LABEL_NAME' does not exist in the repository. Creating it..."
# # Create the label using the GitHub API
# curl -X POST "https://api.github.com/repos/$REPO/labels" \
# -H "Authorization: token ${{ steps.generate-token.outputs.token }}" \
# -d "{\"name\":\"$LABEL_NAME\",\"color\":\"$LABEL_COLOR\"}"
# echo "Label '$LABEL_NAME' has been created."
# fi
# - run: |
# environment=${{ steps.env.outputs.environment }}
# component=${{ steps.component.outputs.component }}
# branch_name="update-$component-$environment"
# # Do not create a new branch if the branch already exists
# if [[ $(git ls-remote origin $branch_name) ]]; then
# git fetch origin
# git checkout $branch_name
# else
# git checkout -b $branch_name
# git push --set-upstream origin $branch_name
# fi
# # Use the REST API to commit changes, so we get automatic commit signing
# - run: |
# # Update the image.yaml file with the new image tag
# echo "image:" > $TARGET_FILE
# echo " tag: V1.2.6" >> $TARGET_FILE
# export MESSAGE="chore: Update $TARGET_FILE for to V1.2.6"
# export SHA=$( git rev-parse $DESTINATION_BRANCH:$TARGET_FILE )
# export CONTENT=$( base64 -i $TARGET_FILE )
# gh api --method PUT /repos/ditkrg/pilgrimage-gitops-duplicate/contents/$TARGET_FILE \
# --field message="$MESSAGE" \
# --field content="$CONTENT" \
# --field encoding="base64" \
# --field branch="$DESTINATION_BRANCH" \
# --field sha="$SHA"
# env:
# GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
# DESTINATION_BRANCH: update-${{ steps.component.outputs.component }}-${{ steps.env.outputs.environment }}
# TARGET_FILE: ${{ steps.component.outputs.component }}/${{ steps.find-target-file.outputs.target_file }}
# - name: Create Pull Request
# run: |
# # do not create the PR if it already exists from the same branch
# if [[ $(gh pr list --state open --head $HEAD_BRANCH) ]]; then
# echo "PR already exists"
# else gh pr create \
# --body "" \
# --title "Update $component/$target_file for $environment" \
# --label autodeploy
# fi
# env:
# GH_TOKEN: ${{ steps.generate-token.outputs.token }}
# environment: ${{ steps.env.outputs.environment }}
# component: ${{ steps.component.outputs.component }}
# target_file: ${{ steps.find-target-file.outputs.target_file }}
# HEAD_BRANCH: update-${{ steps.component.outputs.component }}-${{ steps.env.outputs.environment }}