From 4f00d6600d7d71be2f1a08a648d5ee7882d41550 Mon Sep 17 00:00:00 2001 From: Olivier ORAND Date: Wed, 24 Jan 2024 14:43:48 +0000 Subject: [PATCH] chore(github-action): migrate to our github-actions create-bosh-release-action and extract-vendir-version-action --- .../create-final-bosh-release-on-commits.yml | 100 +++--------------- 1 file changed, 13 insertions(+), 87 deletions(-) diff --git a/.github/workflows/create-final-bosh-release-on-commits.yml b/.github/workflows/create-final-bosh-release-on-commits.yml index 57138641..277e8552 100644 --- a/.github/workflows/create-final-bosh-release-on-commits.yml +++ b/.github/workflows/create-final-bosh-release-on-commits.yml @@ -1,8 +1,9 @@ name: create-final-bosh-release permissions: - contents: write # allow git push to repo and the github release and its artefact + contents: write # allow git push to repo and the GitHub release and its artefact on: + workflow_dispatch: # to allow manual triggering to be able to create a release even on change on other paths push: branches: - master @@ -16,7 +17,6 @@ on: - jobs/** - releases/** - vendir.yml - - .github/workflows/create-final-bosh-release-on-commits.yml jobs: build: @@ -95,97 +95,23 @@ jobs: if [ -d blobs ];then # The blobs dir is only present when a blob is modified or has not yet been published. tree -s blobs fi - + - name: Extract k9s version + id: extract_version + uses: orange-cloudfoundry/extract-vendir-version-action@v0.2.0 + with: + library: "k3s-io/k3s" - name: create bosh final release id: create-bosh-release + uses: orange-cloudfoundry/create-bosh-release-action@v1.0.1 + with: + target_branch: ${{github.ref_name}} + tag_name: ${{ steps.extract_version.outputs.version }} + override_existing: true # allow deletion of existing tags + force_version_consistency: true # to force tag_name without 'v' prefix env: - INPUT_TARGET_BRANCH: ${{github.ref_name}} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} AWS_BOSH_ACCES_KEY_ID: ${{ secrets.AWS_BOSH_ACCES_KEY_ID }} AWS_BOSH_SECRET_ACCES_KEY: ${{ secrets.AWS_BOSH_SECRET_ACCES_KEY }} - run: | - set -x # enable traces - # extract info from vendir - version=$(yq -r '.directories[0].contents[] | select (.path=="k3s-io/k3s") | .githubRelease.tag ' ./vendir.yml) - version=${version#v} - release=true - - name=$(yq -r .final_name config/final.yml) - if [ "${name}" = "null" ]; then - name=$(yq -r .name config/final.yml) - fi - - remote_repo="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@${GITHUB_SERVER_URL#https://}/${GITHUB_REPOSITORY}.git" - - # configure git - git config --global user.name "workflows/k3s-boshrelease/create-final-bosh-release" - git config --global user.email "<>" - git config --global --add safe.directory /github/workspace - - # if [ ! -z "${INPUT_BUNDLE}" ] && [ "${INPUT_BUNDLE}" != "false" ]; then - # echo "installing bundle: ${INPUT_BUNDLE}" - # apk add ruby - # gem install bundler -v "${INPUT_BUNDLE}" - # fi - - # remove existing release if any, and prepare a commit that will be amended next - # Having a single amended commit makes it easier to inspect last commit - # See https://superuser.com/a/360986/299481 for details of the bash array syntax - NEXT_GIT_COMMIT_FLAGS=(-m "cutting release ${version}") - if [ -f releases/${name}/${name}-${version}.yml ]; then - echo "removing pre-existing version ${version}" - yq -r "{ \"builds\": (.builds | with_entries(select(.value.version != \"${version}\"))), \"format-version\": .[\"format-version\"]}" < releases/${name}/index.yml > tmp - mv tmp releases/${name}/index.yml - rm -f releases/${name}/${name}-${version}.yml - git add releases/${name}/${name}-${version}.yml releases/${name}/index.yml - git commit -a "${NEXT_GIT_COMMIT_FLAGS[@]}" - NEXT_GIT_COMMIT_FLAGS=(--amend -m "cutting release ${version} overriding existing one") - fi - - echo "Current AWS config" - # This might be required to download the blobs during the final release of the S3 bucket does not grant permission to anonymous users - ls -al config/private.yml - - echo "creating bosh release: ${name}-${version}.tgz" - bosh create-release --final --version=${version} --tarball=${name}-${version}.tgz - - git add .final_builds - git add releases/${name}/index.yml - RELEASE_FILE_NAME=releases/${name}/${name}-${version}.yml - git add ${RELEASE_FILE_NAME} - # Note: if we had removed the previous release, then we amend the commit. - git commit -a "${NEXT_GIT_COMMIT_FLAGS[@]}" - - echo "Inspecting staged files to skip commit and push if there is no blob changes in the release" - git show HEAD ${RELEASE_FILE_NAME} - if ! git show HEAD ${RELEASE_FILE_NAME} | grep sha1 ; then - echo "No sha1 found in diff in ${RELEASE_FILE_NAME}. No blob were modified. Skipping the git push" - ls -al ${RELEASE_FILE_NAME} - cat ${RELEASE_FILE_NAME} - NEED_GITHUB_RELEASE="false" - else - echo "pushing changes to git repository" - - # Override any existing tag with same version. This may happen if only part of the renovate PRs were merged - git tag -a -m "cutting release ${version}" ${version} -f - # In case a renovate PR was merged in between, try to rebase prior to pushing - git pull --rebase - git push ${remote_repo} HEAD:${INPUT_TARGET_BRANCH} - - # Delete any existing release with same tag. Ignore push failure if no tag exists. - ! git push --delete ${remote_repo} ${version} - - # Push the tag - git push ${remote_repo} ${version} --force - NEED_GITHUB_RELEASE="true" - fi - - # make asset readable outside docker image - chmod 644 ${name}-${version}.tgz - # https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#environment-files - echo "file=${name}-${version}.tgz" >> $GITHUB_OUTPUT - echo "version=${version}" >> $GITHUB_OUTPUT - echo "need_gh_release=${NEED_GITHUB_RELEASE}" >> $GITHUB_OUTPUT # see https://github.com/ncipollo/release-action - name: create github release