This repository has been archived by the owner on May 21, 2024. It is now read-only.
upgrade #43
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: upgrade | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: "terraform-modules version" | |
required: true | |
type: string | |
jobs: | |
upgrade: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout this | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Update version | |
id: update | |
env: | |
VERSION: ${{ inputs.version }} | |
run: | | |
set -x | |
echo "Upgrading to terraform-modules version $VERSION" | |
grep -RIl --include \*.tf 'github.com/xenitab/terraform-modules//modules' ${GITHUB_WORKSPACE} | xargs sed -i "s/ref=.*\"/ref=$VERSION\"/g" | |
- name: Generate token | |
uses: tibdex/github-app-token@v1 | |
id: generate_token | |
with: | |
app_id: ${{ secrets.GH_ACTION_APP_ID }} | |
private_key: ${{ secrets.GH_ACTION_APP_PRIVATE_KEY }} | |
- name: Check | |
id: check | |
env: | |
VERSION: ${{ inputs.version }} | |
GH_TOKEN: ${{ steps.generate_token.outputs.token }} | |
run: | | |
set -x | |
NUM_CHANGED=$(git status --porcelain | wc -l) | |
if [ $NUM_CHANGED == 0 ]; then | |
echo "No changes, version $VERSION already used" | |
exit 0 | |
fi | |
PR_BRANCH="upgrade_terraform_modules_${VERSION//./$'_'}" | |
set +e | |
PR_STATUS="$(gh pr view $PR_BRANCH --json state --jq .state)" | |
if [ $? == 0 ]; then | |
if [ $PR_STATUS == 'OPEN' ]; then | |
echo "Open PR already exist" | |
exit 0 | |
fi | |
fi | |
echo "pr_branch=$PR_BRANCH" >> $GITHUB_OUTPUT | |
- name: Create PR | |
if: steps.check.outputs.pr_branch != '' | |
env: | |
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }} | |
PR_BRANCH: ${{ steps.check.outputs.pr_branch }} | |
VERSION: ${{ inputs.version }} | |
run: | | |
set -x | |
set +e | |
git config --global user.email "gh-actions-automation[bot]@users.noreply.github.com" | |
git config --global user.name "gh-actions-automation[bot]" | |
git ls-remote --exit-code --heads origin "$PR_BRANCH" | |
if [ $? == 0 ]; then | |
echo "Branch $PR_BRANCH alredy exist, please delete it." | |
exit 1 | |
fi | |
set -e | |
echo "Checking out branch: $PR_BRANCH" | |
git checkout -b "$PR_BRANCH" | |
git add . | |
git status | |
git commit -m "Upgrade to terraform-modules version $VERSION" | |
git push origin "$PR_BRANCH" | |
echo "Creating PR for branch: $PR_BRANCH" | |
gh pr create --title "Upgrade to terraform-modules $VERSION" --body "https://github.com/XenitAB/terraform-modules" |