hurl/.github/workflows/update-branch-version.yml

125 lines
4.8 KiB
YAML
Raw Normal View History

2022-11-03 18:10:38 +03:00
name: update-branch-version
on:
workflow_dispatch:
inputs:
new_version:
2022-11-10 18:17:29 +03:00
description: 'Version (x.y.z-SNASPHOT)'
2022-11-03 18:10:38 +03:00
required: true
type: string
workflow_call:
secrets:
LEPAPAREIL_CI_TOKEN:
description: 'secrets.LEPAPAREIL_CI_TOKEN from the caller workflow'
required: true
inputs:
new_version:
2022-11-10 18:17:29 +03:00
description: "Version (x.y.z-SNASPHOT)"
2022-11-03 18:10:38 +03:00
required: true
type: string
branch:
description: "ref branch for this workflow"
default: "master"
required: true
type: string
outputs:
pr_number:
description: "Create PR number"
value: ${{ jobs.update-branch-version.outputs.pr_number }}
concurrency: update-branch-version
jobs:
update-branch-version:
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
outputs:
pr_number: ${{ steps.create-new-version-pr.outputs.pr_number }}
name: update-branch-version
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ inputs.branch }}
- name: Init bot branch name
run: |
base=$(echo "${{ github.ref }}" | sed "s#refs/heads/##g" | tr '/' '-')
echo "BOT_UPDATE_VERSION_BRANCHE_NAME=bot/update-branch-version-${base}" | tee -a $GITHUB_ENV
- name: Update version
run: |
hurl_packages="hurl_core hurl hurlfmt"
for package in ${hurl_packages} ; do
cargo_toml="packages/${package}/Cargo.toml"
sed -i "s/^version.*/version = \"${{ inputs.new_version }}\"/" "${cargo_toml}"
echo "----------------------------"
echo " > package version for ${cargo_toml}"
echo " $(grep "^version =" "${cargo_toml}")"
for dep_package in ${hurl_packages} ; do
if [ $(grep -c "^${dep_package} =" "${cargo_toml}") -gt 0 ] ; then
sed -i "s/^${dep_package} = { version .*/${dep_package} = { version = \"${{ inputs.new_version }}\", path = \"..\/${dep_package}\" }/" "${cargo_toml}"
echo " > ${dep_package} dep package version for ${cargo_toml}"
echo " $(grep "^${dep_package} =" "${cargo_toml}")"
fi
done
done
- name: Cargo update
run: |
./bin/update_crates.sh
- name: Update packages manuals
run: |
version_doc="docs/installation.md"
old_version=$(grep "sudo dpkg -i" "${version_doc}" | cut --delimiter "_" --field 2 )
echo "old_version=${old_version}"
sed -i "s/${old_version}/${{ inputs.new_version }}/g" "${version_doc}"
grep "${{ inputs.new_version }}" "${version_doc}"
- name: Update man
run: |
for package in hurl hurlfmt ; do
python3 bin/release/gen_manpage.py "docs/manual/${package}.md" > "docs/manual/${package}.1"
done
- name: Update general docs
run: |
python3 bin/docs/build_man_md.py docs/manual/hurl.md > docs/manual.md
python3 bin/docs/build_readme.py github > README.md
python3 bin/docs/build_readme.py crates > packages/hurl/README.md
- name: Push commits
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git checkout -b "${BOT_UPDATE_VERSION_BRANCHE_NAME}"
git commit -am "Update hurl version to ${{ inputs.new_version }}"
git push --set-upstream origin "${BOT_UPDATE_VERSION_BRANCHE_NAME}" && git_exit_code=0 || git_exit_code=$?
if [ ${git_exit_code} -eq 0 ] ; then
echo " - ✅ commits pushed to ${BOT_UPDATE_VERSION_BRANCHE_NAME} branch."
else
echo " - ❌ A problem occurs when attempting to push create relase commits to ${BOT_UPDATE_VERSION_BRANCHE_NAME} branch."
exit 1
fi
- name: Create new version PR
id: create-new-version-pr
run: |
GITHUB_TOKEN=${{ secrets.LEPAPAREIL_CI_TOKEN }}
git fetch
base=$(echo "${{ github.ref }}" | sed "s#refs/heads/##g")
gh pr create --fill --label bot --base "${base}" --head "${BOT_UPDATE_VERSION_BRANCHE_NAME}" && gh_exit_code=0 || gh_exit_code=$?
if [ ${gh_exit_code} -eq 0 ] ; then
NEW_PR_NUMBER=$(gh pr list --repo "${REPO}" --head "${BOT_UPDATE_VERSION_BRANCHE_NAME}" --state "open" --json number --jq .[].number)
echo " - ✅ Creation of pull request n°${NEW_PR_NUMBER} succeeds."
echo "pr_bumber=${NEW_PR_NUMBER}" | tee -a $GITHUB_OUTPUT
else
echo " - ❌ A problem occurs when attempting to create new pull request."
exit 1
fi