github.com/giantswarm/apiextensions/v6@v6.6.0/.github/workflows/zz_generated.create_release_pr.yaml (about) 1 # DO NOT EDIT. Generated with: 2 # 3 # devctl@5.8.0 4 # 5 name: Create Release PR 6 on: 7 push: 8 branches: 9 - 'legacy#release#v*.*.*' 10 - 'main#release#v*.*.*' 11 - 'main#release#major' 12 - 'main#release#minor' 13 - 'main#release#patch' 14 - 'master#release#v*.*.*' 15 - 'master#release#major' 16 - 'master#release#minor' 17 - 'master#release#patch' 18 - 'release#v*.*.*' 19 - 'release#major' 20 - 'release#minor' 21 - 'release#patch' 22 - 'release-v*.*.x#release#v*.*.*' 23 # "!" negates previous positive patterns so it has to be at the end. 24 - '!release-v*.x.x#release#v*.*.*' 25 workflow_call: 26 inputs: 27 branch: 28 required: true 29 type: string 30 jobs: 31 debug_info: 32 name: Debug info 33 runs-on: ubuntu-20.04 34 steps: 35 - name: Print github context JSON 36 run: | 37 cat <<EOF 38 ${{ toJson(github) }} 39 EOF 40 gather_facts: 41 name: Gather facts 42 runs-on: ubuntu-20.04 43 outputs: 44 repo_name: ${{ steps.gather_facts.outputs.repo_name }} 45 branch: ${{ steps.gather_facts.outputs.branch }} 46 base: ${{ steps.gather_facts.outputs.base }} 47 is_major: ${{ steps.gather_facts.outputs.is_major }} 48 skip: ${{ steps.pr_exists.outputs.skip }} 49 version: ${{ steps.gather_facts.outputs.version }} 50 steps: 51 - name: Gather facts 52 id: gather_facts 53 run: | 54 head="${{ inputs.branch || github.event.ref }}" 55 echo "::set-output name=branch::${head}" 56 57 head="${head#refs/heads/}" # Strip "refs/heads/" prefix. 58 if [[ $(echo "$head" | grep -o '#' | wc -l) -gt 1 ]]; then 59 base="$(echo $head | cut -d '#' -f 1)" 60 else 61 base="${{ github.event.base_ref }}" 62 fi 63 64 base="${base#refs/heads/}" # Strip "refs/heads/" prefix. 65 66 version="$(echo $head | awk -F# '{print $NF}')" 67 if [[ $version =~ ^major|minor|patch$ ]]; then 68 gh auth login --with-token <<<$(echo -n ${{ secrets.GITHUB_TOKEN }}) 69 version_parts=($(gh api "repos/${{ github.repository }}/releases/latest" --jq '.tag_name[1:] | split(".") | .[0], .[1], .[2]')) 70 version_major=${version_parts[0]} 71 version_minor=${version_parts[1]} 72 version_patch=${version_parts[2]} 73 case ${version} in 74 patch) 75 version_patch=$((version_patch+1)) 76 ;; 77 minor) 78 version_minor=$((version_minor+1)) 79 version_patch=0 80 ;; 81 major) 82 version_major=$((version_major+1)) 83 version_minor=0 84 version_patch=0 85 echo "::set-output name=is_major::true" 86 ;; 87 *) 88 echo "Unknown Semver level provided" 89 exit 1 90 ;; 91 esac 92 version="${version_major}.${version_minor}.${version_patch}" 93 else 94 version="${version#v}" # Strip "v" prefix. 95 version_major=$(echo "${version}" | cut -d "." -f 1) 96 version_minor=$(echo "${version}" | cut -d "." -f 2) 97 version_patch=$(echo "${version}" | cut -d "." -f 3) 98 if [[ $version_minor = 0 && $version_patch = 0 ]]; then 99 echo "::set-output name=is_major::true" 100 fi 101 fi 102 repo_name="$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" 103 echo "repo_name=\"$repo_name\" base=\"$base\" head=\"$head\" version=\"$version\"" 104 echo "::set-output name=repo_name::${repo_name}" 105 echo "::set-output name=base::${base}" 106 echo "::set-output name=head::${head}" 107 echo "::set-output name=version::${version}" 108 - name: Check if PR exists 109 id: pr_exists 110 env: 111 GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" 112 run: | 113 if gh pr view --repo ${{ github.repository }} ${{ steps.gather_facts.outputs.branch }} | grep -i 'state:[[:space:]]*open' >/dev/null; then 114 gh pr view --repo ${{ github.repository }} ${{ steps.gather_facts.outputs.branch }} 115 echo "::set-output name=skip::true" 116 else 117 echo "::set-output name=skip::false" 118 fi 119 create_release_pr: 120 name: Create release PR 121 runs-on: ubuntu-20.04 122 needs: 123 - gather_facts 124 if: ${{ needs.gather_facts.outputs.skip != 'true' }} 125 env: 126 architect_flags: "--organisation ${{ github.repository_owner }} --project ${{ needs.gather_facts.outputs.repo_name }}" 127 steps: 128 - uses: actions/setup-go@v3 129 with: 130 go-version: '=1.18.1' 131 - name: Install architect 132 uses: giantswarm/install-binary-action@v1.0.0 133 with: 134 binary: "architect" 135 version: "6.1.0" 136 - name: Checkout code 137 uses: actions/checkout@v3 138 with: 139 ref: ${{ needs.gather_facts.outputs.branch }} 140 - name: Prepare release changes 141 run: | 142 architect prepare-release ${{ env.architect_flags }} --version "${{ needs.gather_facts.outputs.version }}" 143 - name: Update version field in Chart.yaml 144 run: | 145 # Define chart_dir 146 repository="${{ needs.gather_facts.outputs.repo_name }}" 147 chart="helm/${repository}" 148 149 # Check chart directory. 150 if [ ! -d "${chart}" ] 151 then 152 echo "Could not find chart directory '${chart}', adding app suffix." 153 154 # Add app suffix. 155 chart="helm/${repository}-app" 156 157 # Check chart directory with app suffix. 158 if [ ! -d "${chart}" ] 159 then 160 echo "Could not find chart directory '${chart}', removing app suffix." 161 162 # Remove app suffix. 163 chart="helm/${repository%-app}" 164 165 if [ ! -d "${chart}" ] 166 then 167 # Print error. 168 echo "Could not find chart directory '${chart}', doing nothing." 169 fi 170 fi 171 fi 172 173 # Define chart YAML. 174 chart_yaml="${chart}/Chart.yaml" 175 176 # Check chart YAML. 177 if [ -f "${chart_yaml}" ] 178 then 179 # check if version in Chart.yaml is templated using architect 180 if [ $(grep -c "^version:.*\.Version.*$" "${chart_yaml}") = "0" ]; then 181 yq -i '.version = "${{ needs.gather_facts.outputs.version }}"' "${chart_yaml}" 182 fi 183 fi 184 185 - name: Bump go module defined in go.mod if needed 186 run: | 187 if [ "${{ needs.gather_facts.outputs.is_major }}" = true ] && test -f "go.mod"; then 188 go install github.com/marwan-at-work/mod/cmd/mod@v0.4.2 189 mod upgrade 190 fi 191 - name: Set up git identity 192 run: | 193 git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" 194 git config --local user.name "github-actions[bot]" 195 - name: Create release commit 196 env: 197 version: "${{ needs.gather_facts.outputs.version }}" 198 run: | 199 git add -A 200 git commit -m "Release v${{ env.version }}" 201 - name: Push changes 202 env: 203 remote_repo: "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" 204 run: | 205 git push "${remote_repo}" HEAD:${{ needs.gather_facts.outputs.branch }} 206 - name: Create PR 207 env: 208 GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" 209 base: "${{ needs.gather_facts.outputs.base }}" 210 version: "${{ needs.gather_facts.outputs.version }}" 211 run: | 212 hub pull-request -f -m "Release v${{ env.version }}" -a ${{ github.actor }} -b ${{ env.base }} -h ${{ needs.gather_facts.outputs.branch }}