From cdfa4b8d8e6f23a11ab790aee1315b86db188300 Mon Sep 17 00:00:00 2001 From: lepapareil Date: Thu, 3 Nov 2022 16:10:38 +0100 Subject: [PATCH] Add releasing workflow --- .github/workflows/accept-pull-request.yml | 317 +++++---- .github/workflows/check.yml | 28 +- .github/workflows/coverage.yml | 10 + .github/workflows/package.yml | 375 +++++++++++ .github/workflows/release.yml | 690 +++++++++++--------- .github/workflows/test.yml | 76 ++- .github/workflows/update-branch-version.yml | 124 ++++ .github/workflows/update-crates.yml | 170 ++--- 8 files changed, 1251 insertions(+), 539 deletions(-) create mode 100644 .github/workflows/package.yml create mode 100644 .github/workflows/update-branch-version.yml diff --git a/.github/workflows/accept-pull-request.yml b/.github/workflows/accept-pull-request.yml index 94c8c743b..9af4297c3 100644 --- a/.github/workflows/accept-pull-request.yml +++ b/.github/workflows/accept-pull-request.yml @@ -9,6 +9,7 @@ concurrency: accept-pull-request-${{ github.event.issue.number }} jobs: accept-pull-request: + if: ${{ github.event.issue.pull_request && startsWith(github.event.comment.body, '/accept') }} env: GITHUB_CONTEXT: ${{ toJson(github) }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -16,33 +17,39 @@ jobs: REPO: ${{ github.event.repository.name }} PR_NUMBER: ${{ github.event.issue.number }} COMMENT_USER_LOGIN: ${{ github.event.comment.user.login }} + outputs: + base_ref: ${{ steps.init-all-internal-env-vars.outputs.base_ref }} + new_version_master_snapshot_version: ${{ steps.check-github-release.outputs.new_version_master_snapshot_version }} + is_a_github_release_pr: ${{ steps.check-github-release.outputs.is_a_github_release_pr }} name: accept-pull-request runs-on: ubuntu-latest - if: ${{ github.event.issue.pull_request && startsWith(github.event.comment.body, '/accept') }} steps: - - name: Init all internal env vars + - name: Init all internal env vars + id: init-all-internal-env-vars run: | - pr_detail_file="pr_detail.json" - gh api repos/"${OWNER}"/"${REPO}"/pulls/"${PR_NUMBER}" > "${pr_detail_file}" - jq . "${pr_detail_file}" - HEAD_REPO_FULL_NAME=$(jq -rc .head.repo.full_name ${pr_detail_file}) - BASE_REPO_FULL_NAME=$(jq -rc .base.repo.full_name ${pr_detail_file}) - if [ "${HEAD_REPO_FULL_NAME}" = "${BASE_REPO_FULL_NAME}" ] ; then - HEAD_TYPE=origin - else - HEAD_TYPE=fork - fi - echo "HEAD_REPO_FULL_NAME=${HEAD_REPO_FULL_NAME}" | tee -a "${GITHUB_ENV}" - echo "BASE_REPO_FULL_NAME=${BASE_REPO_FULL_NAME}" | tee -a "${GITHUB_ENV}" - echo "HEAD_TYPE=${HEAD_TYPE}" | tee -a "${GITHUB_ENV}" - echo "HEAD_REF=$(jq -rc .head.ref ${pr_detail_file})" | tee -a "${GITHUB_ENV}" - echo "BASE_REF=$(jq -rc .base.ref ${pr_detail_file})" | tee -a "${GITHUB_ENV}" - echo "PR_STATE=$(jq -rc .state ${pr_detail_file})" | tee -a "${GITHUB_ENV}" - echo "PR_DRAFT=$(jq -rc .draft ${pr_detail_file})" | tee -a "${GITHUB_ENV}" - echo "PR_MERGEABLE=$(jq -rc .mergeable ${pr_detail_file})" | tee -a "${GITHUB_ENV}" - echo "REMAINING_COMMITS_FILE=remaining_commits.txt" | tee -a "${GITHUB_ENV}" - echo "NEW_COMMITS_FILE=new_commits.txt" | tee -a "${GITHUB_ENV}" + pr_detail_file="pr_detail.json" + gh api repos/"${OWNER}"/"${REPO}"/pulls/"${PR_NUMBER}" > "${pr_detail_file}" + jq . "${pr_detail_file}" + echo ${{ github.event.issue.title }} + HEAD_REPO_FULL_NAME=$(jq -rc .head.repo.full_name ${pr_detail_file}) + BASE_REPO_FULL_NAME=$(jq -rc .base.repo.full_name ${pr_detail_file}) + if [ "${HEAD_REPO_FULL_NAME}" = "${BASE_REPO_FULL_NAME}" ] ; then + HEAD_TYPE=origin + else + HEAD_TYPE=fork + fi + echo "HEAD_REPO_FULL_NAME=${HEAD_REPO_FULL_NAME}" | tee -a "${GITHUB_ENV}" + echo "BASE_REPO_FULL_NAME=${BASE_REPO_FULL_NAME}" | tee -a "${GITHUB_ENV}" + echo "HEAD_TYPE=${HEAD_TYPE}" | tee -a "${GITHUB_ENV}" + echo "HEAD_REF=$(jq -rc .head.ref ${pr_detail_file})" | tee -a "${GITHUB_ENV}" + echo "BASE_REF=$(jq -rc .base.ref ${pr_detail_file})" | tee -a "${GITHUB_ENV}" + echo "PR_STATE=$(jq -rc .state ${pr_detail_file})" | tee -a "${GITHUB_ENV}" + echo "PR_DRAFT=$(jq -rc .draft ${pr_detail_file})" | tee -a "${GITHUB_ENV}" + echo "PR_MERGEABLE=$(jq -rc .mergeable ${pr_detail_file})" | tee -a "${GITHUB_ENV}" + echo "REMAINING_COMMITS_FILE=remaining_commits.txt" | tee -a "${GITHUB_ENV}" + echo "NEW_COMMITS_FILE=new_commits.txt" | tee -a "${GITHUB_ENV}" + echo "base_ref=$(jq -rc .base.ref ${pr_detail_file})" | tee -a "${GITHUB_OUTPUT}" - name: Checkout repository uses: actions/checkout@v3 @@ -52,136 +59,202 @@ jobs: - name: Notify user run: | - order="${{ github.event.comment.body }}" - comment="šŸ•— [${order}](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}) is running, please wait for completion." - gh pr comment "${PR_NUMBER}" --body "${comment}" + order="${{ github.event.comment.body }}" + comment="šŸ•— [${order}](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}) is running, please wait for completion." + gh pr comment "${PR_NUMBER}" --body "${comment}" - name: Check comment user permission run: | - comment_user_permission=$(gh api repos/"${OWNER}"/"${REPO}"/collaborators/"${COMMENT_USER_LOGIN}"/permission -q .permission) - if [ "${comment_user_permission}" = "admin" ] ; then - echo " - āœ… You have the ${comment_user_permission} permission then you are allowed to accept pull request nĀ°${PR_NUMBER}" - else - comment="āŒ Sorry \`${COMMENT_USER_LOGIN}\`, you are not allowed to accept this pull request because you do not have admin permission (actual permission=${comment_user_permission})." - echo " - ${comment}" - gh pr comment "${PR_NUMBER}" --body "${comment}" - exit 1 - fi + comment_user_permission=$(gh api repos/"${OWNER}"/"${REPO}"/collaborators/"${COMMENT_USER_LOGIN}"/permission -q .permission) + if [ "${comment_user_permission}" = "admin" ] ; then + echo " - āœ… You have the ${comment_user_permission} permission then you are allowed to accept pull request nĀ°${PR_NUMBER}" + else + comment="āŒ Sorry \`${COMMENT_USER_LOGIN}\`, you are not allowed to accept this pull request because you do not have admin permission (actual permission=${comment_user_permission})." + echo " - ${comment}" + gh pr comment "${PR_NUMBER}" --body "${comment}" + exit 1 + fi - name: Check if pull request state is open run: | - if [ "${{ env.PR_STATE }}" = "open" ] ; then - echo " - āœ… Pull request is ${{ env.PR_STATE }}." - else - comment="āŒ Can not accept this pull request because it is not open (actual state=${{ env.PR_STATE }})." - echo " - ${comment}" - gh pr comment "${PR_NUMBER}" --body "${comment}" - exit 1 - fi + if [ "${{ env.PR_STATE }}" = "open" ] ; then + echo " - āœ… Pull request is ${{ env.PR_STATE }}." + else + comment="āŒ Can not accept this pull request because it is not open (actual state=${{ env.PR_STATE }})." + echo " - ${comment}" + gh pr comment "${PR_NUMBER}" --body "${comment}" + exit 1 + fi - name: Check if pull request is ready run: | - if [ "${{ env.PR_DRAFT }}" = "false" ] ; then - echo " - āœ… Pull request draft state is ${{ env.PR_DRAFT }}." - else - comment="āŒ Can not accept this pull request because it is still in draft." - echo " - ${comment}" - gh pr comment "${PR_NUMBER}" --body "${comment}" - exit 1 - fi + if [ "${{ env.PR_DRAFT }}" = "false" ] ; then + echo " - āœ… Pull request draft state is ${{ env.PR_DRAFT }}." + else + comment="āŒ Can not accept this pull request because it is still in draft." + echo " - ${comment}" + gh pr comment "${PR_NUMBER}" --body "${comment}" + exit 1 + fi - name: Check if pull request is mergeable run: | - if [ "${{ env.PR_MERGEABLE }}" = "true" ] ; then - echo " - āœ… Pull request mergeable state is ${{ env.PR_MERGEABLE }}." + if [ "${{ env.PR_MERGEABLE }}" = "true" ] ; then + echo " - āœ… Pull request mergeable state is ${{ env.PR_MERGEABLE }}." + else + comment="āŒ Pull request is not mergeable, please check unresolved discussions and pull request messages." + echo " - ${comment}" + gh pr comment "${PR_NUMBER}" --body "${comment}" + exit 1 + fi + + - name: Check github release + id: check-github-release + run: | + if [ $(echo ${{ env.HEAD_REF }} | grep -Ec '^release/') -eq 0 ] ; then + echo " - āœ… Pull request is not about a pending github release." + else + tag_version="$(echo ${{ env.HEAD_REF }} | cut --delimiter '/' --field 2)" + gh_result=$(gh api repos/"${OWNER}"/"${REPO}"/releases/tags/"${tag_version}" | tr ":" "=" | tr -d '"' | tr -d " ") + echo "gh_result=${gh_result}" + if [ $(echo "${gh_result}" | grep -Ec "message=NotFound|prerelease=true") -eq 0 ] ; then + comment="āœ… Github release ${tag_version} is published." + echo " - ${comment}" else - comment="āŒ Pull request is not mergeable, please check unresolved discussions and pull request messages." - echo " - ${comment}" - gh pr comment "${PR_NUMBER}" --body "${comment}" - exit 1 + comment="āŒ Github release ${tag_version} is still in draft/prerelease. Please publish it before trying to merge this release PR." + echo " - ${comment}" + gh pr comment "${PR_NUMBER}" --body "${comment}" + exit 1 fi + fi + go=$(echo "${tag_version}" | cut --delimiter "." --field 1) + ro=$(echo "${tag_version}" | cut --delimiter "." --field 2) + echo "go=${go}" + echo "ro=${ro}" + new_ro="$((ro + 1))" + echo "new_ro=${new_ro}" + new_version_master_snapshot_version="${go}.${new_ro}.0-SNAPSHOT" + echo "is_a_github_release_pr=true" | tee -a "${GITHUB_OUTPUT}" + echo "new_version_master_snapshot_version=${new_version_master_snapshot_version}" | tee -a "${GITHUB_OUTPUT}" - name: Check if pull request checks are successful if: ${{ !contains(github.event.comment.body, '--force') }} run: | - gh pr checks "${PR_NUMBER}" --watch --interval 30 && exit_code=0 || exit_code=$? - if [ "${exit_code}" -eq 0 ] ; then - echo " - āœ… Pull request checks are successful." - else - comment="āŒ Some checks are still failing, please fix them before trying to /accept this pull request." - echo " - ${comment}" - gh pr comment "${PR_NUMBER}" --body "${comment}" - exit 1 - fi + gh pr checks "${PR_NUMBER}" --watch --interval 30 && exit_code=0 || exit_code=$? + if [ "${exit_code}" -eq 0 ] ; then + echo " - āœ… Pull request checks are successful." + else + comment="āŒ Some checks are still failing, please fix them before trying to /accept this pull request." + echo " - ${comment}" + gh pr comment "${PR_NUMBER}" --body "${comment}" + exit 1 + fi - name: Add remote source branch run: | - if [ "${{ env.HEAD_TYPE }}" = "fork" ] ; then - git remote add fork https://github.com/${{ env.HEAD_REPO_FULL_NAME}} - git remote --verbose - git fetch --all - fi - echo " - āœ… Source branch is from ${{ env.HEAD_TYPE }} repo" + if [ "${{ env.HEAD_TYPE }}" = "fork" ] ; then + git remote add fork https://github.com/${{ env.HEAD_REPO_FULL_NAME}} + git remote --verbose + git fetch --all + fi + echo " - āœ… Source branch is from ${{ env.HEAD_TYPE }} repo" - name: Check if source branch is rebased from target branch run: | - git log --oneline --cherry ${{ env.HEAD_TYPE }}/${{ env.HEAD_REF }}...origin/${{ env.BASE_REF }} > "${{ env.REMAINING_COMMITS_FILE }}" && exit_code=0 || exit_code=1 - if [ ${exit_code} -eq 1 ] ; then - comment="āŒ Rebase check fails. Please refer to ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID} logs." - echo " - ${comment}" - gh pr comment "${PR_NUMBER}" --body "${comment}" - exit 1 - fi - diff_count=$(grep -c ^+ ${{ env.REMAINING_COMMITS_FILE }} || true) - if [ ${diff_count} -eq 0 ] ; then - echo " - āœ… ${{ env.HEAD_REPO_FULL_NAME}}/${{ env.HEAD_REF }} is already rebased from ${{ env.BASE_REPO_FULL_NAME}}/${{ env.BASE_REF }}." - else - comment="āŒ You have to rebase your \`${{ env.HEAD_REPO_FULL_NAME}}/${{ env.HEAD_REF }}\` branch first because there are new commits pending on target \`${{ env.BASE_REPO_FULL_NAME}}/${{ env.BASE_REF }}\` branch:
$(echo ; sed "s/+/-/g" ${{ env.REMAINING_COMMITS_FILE }})" - echo " - ${comment}" - gh pr comment "${PR_NUMBER}" --body "${comment}" - exit 1 - fi + git log --oneline --cherry ${{ env.HEAD_TYPE }}/${{ env.HEAD_REF }}...origin/${{ env.BASE_REF }} > "${{ env.REMAINING_COMMITS_FILE }}" && exit_code=0 || exit_code=1 + if [ ${exit_code} -eq 1 ] ; then + comment="āŒ Rebase check fails. Please refer to ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID} logs." + echo " - ${comment}" + gh pr comment "${PR_NUMBER}" --body "${comment}" + exit 1 + fi + diff_count=$(grep -c ^+ ${{ env.REMAINING_COMMITS_FILE }} || true) + if [ ${diff_count} -eq 0 ] ; then + echo " - āœ… ${{ env.HEAD_REPO_FULL_NAME}}/${{ env.HEAD_REF }} is already rebased from ${{ env.BASE_REPO_FULL_NAME}}/${{ env.BASE_REF }}." + else + comment="āŒ You have to rebase your \`${{ env.HEAD_REPO_FULL_NAME}}/${{ env.HEAD_REF }}\` branch first because there are new commits pending on target \`${{ env.BASE_REPO_FULL_NAME}}/${{ env.BASE_REF }}\` branch:
$(echo ; sed "s/+/-/g" ${{ env.REMAINING_COMMITS_FILE }})" + echo " - ${comment}" + gh pr comment "${PR_NUMBER}" --body "${comment}" + exit 1 + fi - name: Get new commits list run: | - git log --oneline --cherry origin/${{ env.BASE_REF }}...${{ env.HEAD_TYPE }}/${{ env.HEAD_REF }} | tee ${{ env.NEW_COMMITS_FILE }} + git log --oneline --cherry origin/${{ env.BASE_REF }}...${{ env.HEAD_TYPE }}/${{ env.HEAD_REF }} | tee ${{ env.NEW_COMMITS_FILE }} - name: Merge fast forward head ref to base ref run: | - git config --local user.email "action@github.com" - git config --local user.name "GitHub Action" - git merge ${{ env.HEAD_TYPE }}/${{ env.HEAD_REF }} --ff-only && exit_code=0 || exit_code=1 - if [ ${exit_code} -eq 0 ] ; then - echo " - āœ… Merge fast forward succeeds." - else - comment="āŒ Merge fast forward fails. Please refer to ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID} logs." - echo " - ${comment}" - gh pr comment "${PR_NUMBER}" --body "${comment}" - exit 1 - fi - git push && exit_code=0 || exit_code=1 - if [ ${exit_code} -eq 0 ] ; then - echo " - āœ… Push merge fast forward succeeds." - else - comment="āŒ Push merge fast forward fails. Please refer to ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID} logs." - echo " - ${comment}" - gh pr comment "${PR_NUMBER}" --body "${comment}" - exit 1 - fi + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git merge ${{ env.HEAD_TYPE }}/${{ env.HEAD_REF }} --ff-only && exit_code=0 || exit_code=1 + if [ ${exit_code} -eq 0 ] ; then + echo " - āœ… Merge fast forward succeeds." + else + comment="āŒ Merge fast forward fails. Please refer to ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID} logs." + echo " - ${comment}" + gh pr comment "${PR_NUMBER}" --body "${comment}" + exit 1 + fi + git push && exit_code=0 || exit_code=1 + if [ ${exit_code} -eq 0 ] ; then + echo " - āœ… Push merge fast forward succeeds." + else + comment="āŒ Push merge fast forward fails. Please refer to ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID} logs." + echo " - ${comment}" + gh pr comment "${PR_NUMBER}" --body "${comment}" + exit 1 + fi - name: Close pull request run: | - if [[ "${{ github.event.comment.body }}" =~ "--force" ]] ; then - comment="āœ… Pull request accepted without waiting for checks and closed by \`${COMMENT_USER_LOGIN}\` with fast forward merge." - else - comment="āœ… Pull request accepted and closed by \`${COMMENT_USER_LOGIN}\` with fast forward merge." - fi - gh pr close "${PR_NUMBER}" --delete-branch --comment "${comment}.

\# List of commits merged from \`${{ env.HEAD_REPO_FULL_NAME}}/${{ env.HEAD_REF }}\` branch into \`${{ env.BASE_REPO_FULL_NAME}}/${{ env.BASE_REF }}\` branch:
$(echo ; sed "s/+/-/g" ${{ env.NEW_COMMITS_FILE }})" && exit_code=0 || exit_code=1 - if [ ${exit_code} -eq 0 ] ; then - echo " - ${comment}" - else - comment="āŒ A problem occured when closing pull request and/or deleting branch." - echo " - ${comment}" - #gh pr comment "${PR_NUMBER}" --body "${comment} Please refer to ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID} logs." - #exit 1 - fi + if [[ "${{ github.event.comment.body }}" =~ "--force" ]] ; then + comment="āœ… Pull request accepted without waiting for checks and closed by \`${COMMENT_USER_LOGIN}\` with fast forward merge." + else + comment="āœ… Pull request accepted and closed by \`${COMMENT_USER_LOGIN}\` with fast forward merge." + fi + gh pr close "${PR_NUMBER}" --delete-branch --comment "${comment}.

\# List of commits merged from \`${{ env.HEAD_REPO_FULL_NAME}}/${{ env.HEAD_REF }}\` branch into \`${{ env.BASE_REPO_FULL_NAME}}/${{ env.BASE_REF }}\` branch:
$(echo ; sed "s/+/-/g" ${{ env.NEW_COMMITS_FILE }})" && exit_code=0 || exit_code=1 + if [ ${exit_code} -eq 0 ] ; then + echo " - ${comment}" + else + comment="āŒ A problem occured when closing pull request and/or deleting branch." + echo " - ${comment}" + #gh pr comment "${PR_NUMBER}" --body "${comment} Please refer to ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID} logs." + #exit 1 + fi + + - name: Release mode comment + if: contains(github.event.comment.body, '--release') + run: | + gh pr comment "${PR_NUMBER}" --body "šŸ•— As you used \`--release\` mode, a new PR will be created shortly to automatically update master branch to next ${{ steps.check-github-release.outputs.new_version_master_snapshot_version }} dev version" + + update-branch-version: + needs: + - accept-pull-request + name: update-branch-version + if: needs.accept-pull-request.outputs.is_a_github_release_pr == 'true' && contains(github.event.comment.body, '--release') + uses: Orange-OpenSource/hurl/.github/workflows/update-branch-version.yml@master + with: + new_version: ${{ needs.accept-pull-request.outputs.new_version_master_snapshot_version }} + branch: ${{ needs.accept-pull-request.outputs.base_ref }} + secrets: inherit + + release-final-comment: + if: contains(github.event.comment.body, '--release') + needs: + - accept-pull-request + - update-branch-version + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + name: release-final-comment + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + ref: ${{ env.BASE_REF }} + fetch-depth: 0 + + - name: release-final-comment + run: | + gh pr comment "${{ github.event.issue.number }}" --body "āœ… New PR [${{ needs.update-branch-version.outputs.pr_number }}](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/pull/${{ needs.update-branch-version.outputs.pr_number }}) created to update master branch to ${{ needs.accept-pull-request.outputs.new_version_master_snapshot_version }} version" + diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 101626f69..78ae27080 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -1,5 +1,14 @@ name: check -on: [pull_request] +on: + pull_request: + workflow_dispatch: + workflow_call: + inputs: + branch: + description: "ref branch for this workflow" + default: "master" + required: true + type: string env: CARGO_TERM_COLOR: always @@ -9,23 +18,36 @@ jobs: checks: runs-on: ubuntu-latest steps: + - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 + with: + ref: ${{ inputs.branch }} + - name: Install Prerequisites run: bin/check/install_prerequisites.sh + - name: Rustfmt run: bin/check/rustfmt.sh + - name: Clippy run: bin/check/clippy.sh + - name: Shellcheck run: bin/check/shellcheck.sh + - name: Black run: bin/check/black.sh + - name: Check XML/HTML files run: bin/check/xmllint.sh + - name: Run crates update run: bin/check/crates.sh + - name: Check CHANGELOG - run: bin/check/changelog.sh + run: bin/check/changelog.sh + - name: Check ad hoc run: bin/check/ad_hoc.sh + diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 894a78156..1dbbdab95 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -17,18 +17,25 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v3 + - name: Environment run: bin/environment.sh + - name: Install Prerequisites run: bin/install_prerequisites_ubuntu.sh + - name: Install Rust run: bin/install_rust_latest.sh + - name: Install Grcov run: bin/install_grcov.sh + - name: Build run: cargo build + - name: Test Prerequisites run: bin/test/test_prerequisites.sh + - name: Run Integration Tests run: | export LLVM_PROFILE_FILE="hurl-test-integration-%p-%m.profraw" @@ -37,6 +44,7 @@ jobs: - name: Build Report run: | grcov . --binary-path target/debug -s . -t html --branch --ignore-not-existing -o ./coverage/ + - name: Deploy Github Pages uses: peaceiris/actions-gh-pages@v3 with: @@ -44,6 +52,7 @@ jobs: publish_branch: github-pages publish_dir: coverage destination_dir: coverage + - name: Archive Artifacts uses: actions/upload-artifact@v3 if: ${{ always() }} @@ -52,3 +61,4 @@ jobs: path: | coverage *.profraw + diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml new file mode 100644 index 000000000..2006bef67 --- /dev/null +++ b/.github/workflows/package.yml @@ -0,0 +1,375 @@ +name: package + +on: + pull_request: + workflow_dispatch: + workflow_call: + inputs: + branch: + description: "ref branch for this workflow" + default: "master" + required: true + type: string + +env: + CARGO_TERM_COLOR: always + +jobs: + package-generic-linux-x64: + runs-on: ubuntu-18.04 + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + ref: ${{ inputs.branch }} + + - name: Install + run: | + bin/install_prerequisites_ubuntu.sh + bin/install_rust_latest.sh + - name: Build + run: | + bin/release/release.sh + echo "PATH=:${PWD}/target/release:$PATH" >> "${GITHUB_ENV}" + - name: Install Python 3.8 + uses: actions/setup-python@v4 + with: + python-version: '3.8' + + - name: Install Curl 7.68 + uses: myci-actions/add-deb-repo@10 + with: + repo: deb http://azure.archive.ubuntu.com/ubuntu/ focal main restricted + repo-name: focal + install: curl + + - name: Test integ + run: | + bin/test/test_prerequisites.sh + bin/test/test_integ.sh + - name: Get version + run: | + VERSION=$(bin/release/get_version.sh) + echo "VERSION=${VERSION}" | tee -a "${GITHUB_ENV}" + - name: Create generic linux package + run: | + bin/release/man.sh + bin/release/create_tarball.sh linux + - name: Install package + run: | + bin/release/install_generic_linux_package.sh + echo "PATH=/tmp/hurl-generic-linux:$PATH" >> "${GITHUB_ENV}" + - name: Test integ + run: | + bin/test/test_prerequisites.sh + bin/test/test_integ.sh + - name: Archive production artifacts + uses: actions/upload-artifact@v3 + with: + name: release-generic-linux-x64-artifacts + path: target/upload/* + + test-generic-linux-docker-debian-x64: + needs: package-generic-linux-x64 + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + ref: ${{ inputs.branch }} + + - name: Retrieve release-generic-linux-x64-artifacts + uses: actions/download-artifact@v3 + with: + name: release-generic-linux-x64-artifacts + path: target/upload + + - name: Install package and tests integ + uses: addnab/docker-run-action@v3 + with: + image: debian + options: --volume ${{ github.workspace }}:/work --workdir /work --privileged + run: | + echo "::group::Install system prerequisites" + bin/install_prerequisites_docker_ubuntu.sh + echo "::endgroup::" + echo "::group::Environment" + bin/environment.sh + echo "::endgroup::" + echo "::group::Install generic linux package" + bin/release/install_generic_linux_package.sh + export PATH="/tmp/hurl-generic-linux:$PATH" + echo "::endgroup::" + echo "::group::Install tests prerequisites" + bin/test/test_prerequisites.sh + echo "::endgroup::" + echo "::group::Tests" + bin/test/test_integ.sh + echo "::endgroup::" + - name: Archive production artifacts + uses: actions/upload-artifact@v3 + if: ${{ always() }} + with: + name: test-generic-linux-package-docker-debian-x64-artifacts + path: | + integration/mitmdump.log + integration/server.log + integration/server-ssl.log + test-generic-linux-docker-archlinux-x64: + needs: package-generic-linux-x64 + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + ref: ${{ inputs.branch }} + + - name: Retrieve release-generic-linux-x64-artifacts + uses: actions/download-artifact@v3 + with: + name: release-generic-linux-x64-artifacts + path: target/upload + + - name: Install package and tests integ + uses: addnab/docker-run-action@v3 + with: + image: archlinux + options: --volume ${{ github.workspace }}:/work --workdir /work --privileged + run: | + echo "::group::Install system prerequisites" + bin/install_prerequisites_docker_archlinux.sh + echo "::endgroup::" + echo "::group::Environment" + bin/environment.sh + echo "::endgroup::" + echo "::group::Install generic linux package" + bin/release/install_generic_linux_package.sh + export PATH="/tmp/hurl-generic-linux:$PATH" + echo "::endgroup::" + echo "::group::Install tests prerequisites" + bin/test/test_prerequisites.sh + echo "::endgroup::" + echo "::group::Tests" + bin/test/test_integ.sh + echo "::endgroup::" + - name: Archive production artifacts + uses: actions/upload-artifact@v3 + if: ${{ always() }} + with: + name: test-generic-linux-package-docker-archlinux-x64-artifacts + path: | + integration/mitmdump.log + integration/server.log + integration/server-ssl.log + test-generic-linux-docker-fedora-x64: + needs: package-generic-linux-x64 + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + ref: ${{ inputs.branch }} + + - name: Retrieve release-generic-linux-x64-artifacts + uses: actions/download-artifact@v3 + with: + name: release-generic-linux-x64-artifacts + path: target/upload + + - name: Install package and tests integ + uses: addnab/docker-run-action@v3 + with: + image: fedora + options: --volume ${{ github.workspace }}:/work --workdir /work --privileged + run: | + echo "::group::Install system prerequisites" + bin/install_prerequisites_docker_fedora.sh + echo "::endgroup::" + echo "::group::Environment" + bin/environment.sh + echo "::endgroup::" + echo "::group::Install generic linux package" + bin/release/install_generic_linux_package.sh + export PATH="/tmp/hurl-generic-linux:$PATH" + echo "::group::Install tests prerequisites" + echo "::endgroup::" + bin/test/test_prerequisites.sh + echo "::endgroup::" + echo "::group::Tests" + bin/test/test_integ.sh || true # to be fixed => "error in stderr actual: > "${GITHUB_ENV}" + - name: Install Python 3.8 + uses: actions/setup-python@v4 + with: + python-version: '3.8' + + - name: Install Curl 7.68 + uses: myci-actions/add-deb-repo@10 + with: + repo: deb http://azure.archive.ubuntu.com/ubuntu/ focal main restricted + repo-name: focal + install: curl + + - name: Test integ + run: | + bin/test/test_prerequisites.sh + bin/test/test_integ.sh + - name: Get version + run: | + VERSION=$(bin/release/get_version.sh) + echo "VERSION=${VERSION}" | tee -a "${GITHUB_ENV}" + - name: Create deb package + run: | + bin/release/man.sh + bin/release/create_deb_package.sh + - name: Install package + run: | + bin/release/install_deb_package.sh + echo "PATH=/tmp/hurl-deb-package/usr/bin:$PATH" >> "${GITHUB_ENV}" + - name: Test integ + run: | + bin/test/test_prerequisites.sh + bin/test/test_integ.sh + - name: Archive production artifacts + uses: actions/upload-artifact@v3 + with: + name: release-deb-x64-artifacts + path: target/upload/* + + package-macos-x64: + runs-on: macos-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + ref: ${{ inputs.branch }} + + - name: Install Rust + run: bin/install_rust_latest.sh + + - name: Install Python 3.8 + uses: actions/setup-python@v4 + with: + python-version: '3.8' + + - name: Build + run: | + bin/release/release.sh + echo "PATH=:${PWD}/target/release:$PATH" >> "${GITHUB_ENV}" + - name: Test integ + run: | + bin/test/test_prerequisites.sh + bin/test/test_integ.sh + - name: Get version + run: | + VERSION=$(bin/release/get_version.sh) + echo "VERSION=${VERSION}" | tee -a "${GITHUB_ENV}" + - name: Create generic macos package + run: | + bin/release/man.sh + bin/release/create_tarball.sh macos + - name: Install package + run: | + bin/release/install_generic_macos_package.sh + echo "PATH=/tmp/hurl-generic-macos:$PATH" >> "${GITHUB_ENV}" + - name: Test integ + run: | + bin/test/test_prerequisites.sh + bin/test/test_integ.sh + - name: Archive production artifacts + uses: actions/upload-artifact@v3 + with: + name: release-macos-x64-artifacts + path: target/upload/* + + package-windows-x64: + runs-on: windows-latest + env: + VCPKGRS_DYNAMIC: 1 + steps: + - name: Set git to use LF + run: | + git config --global core.autocrlf false + git config --global core.eol lf + - name: Checkout repository + uses: actions/checkout@v3 + with: + ref: ${{ inputs.branch }} + + - name: Cache + uses: actions/cache@v3 + with: + path: C:\vcpkg\installed + key: ${{ runner.os }}-release-windows-x64-${{ github.sha }} + restore-keys: ${{ runner.os }}-release-windows-x64- + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + profile: minimal + + - name: Environment + run: .\bin\environment.ps1 + + - name: Install prerequisites + run: .\bin\install_prerequisites_windows.ps1 + + - name: Build and test integ + run: | + .\bin\release\release.ps1 + .\bin\test\test_prerequisites.ps1 + .\bin\test\test_integ.ps1 + - name: Create windows64 Zip package + run: .\bin\release\create_windows64_zip_package.ps1 + + - name: Install win64 zip and test integ + run: | + .\bin\release\install_windows64_zip_package.ps1 + .\bin\test\test_prerequisites.ps1 + .\bin\test\test_integ.ps1 + - name: Create windows64 installer + run: .\bin\release\create_windows64_installer.ps1 + + - name: Install win64 installer and test integ + run: | + .\bin\release\install_windows64_installer.ps1 + .\bin\test\test_prerequisites.ps1 + .\bin\test\test_integ.ps1 + - name: Archive production artifacts + uses: actions/upload-artifact@v3 + with: + name: release-windows-x64-artifacts + path: | + .\target\win-package\hurl-*-installer.exe + .\target\win-package\hurl-*-win64.zip + diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 000e9e51b..ff1680269 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,331 +1,375 @@ name: release -on: [pull_request] +on: + workflow_dispatch: + inputs: + control-release-version: + description: 'Control release version' + required: true + type: string + create-release-branch: + description: 'Create release branch' + required: true + type: boolean + default: true + deliver-github-release: + description: 'Deliver github release' + required: true + type: boolean + default: true -env: - CARGO_TERM_COLOR: always +concurrency: release jobs: - release-generic-linux-x64: - runs-on: ubuntu-18.04 - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - name: Install - run: | - bin/install_prerequisites_ubuntu.sh - bin/install_rust_latest.sh - - name: Build - run: | - bin/release/release.sh - echo "PATH=:${PWD}/target/release:$PATH" >> "${GITHUB_ENV}" - - name: Install Python 3.8 - uses: actions/setup-python@v4 - with: - python-version: '3.8' - - name: Install Curl 7.68 - uses: myci-actions/add-deb-repo@10 - with: - repo: deb http://azure.archive.ubuntu.com/ubuntu/ focal main restricted - repo-name: focal - install: curl - - name: Test integ - run: | - bin/test/test_prerequisites.sh - bin/test/test_integ.sh - - name: Get version - run: | - VERSION=$(bin/release/get_version.sh) - echo "VERSION=${VERSION}" | tee -a "${GITHUB_ENV}" - - name: Create generic linux package - run: | - bin/release/man.sh - bin/release/create_tarball.sh linux - - name: Install package - run: | - bin/release/install_generic_linux_package.sh - echo "PATH=/tmp/hurl-generic-linux:$PATH" >> "${GITHUB_ENV}" - - name: Test integ - run: | - bin/test/test_prerequisites.sh - bin/test/test_integ.sh - - name: Archive production artifacts - uses: actions/upload-artifact@v3 - with: - name: release-generic-linux-x64-artifacts - path: target/upload/* - - test-generic-linux-docker-debian-x64: - needs: release-generic-linux-x64 - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - name: Retrieve release-generic-linux-x64-artifacts - uses: actions/download-artifact@v3 - with: - name: release-generic-linux-x64-artifacts - path: target/upload - - name: Install package and tests integ - uses: addnab/docker-run-action@v3 - with: - image: debian - options: --volume ${{ github.workspace }}:/work --workdir /work --privileged - run: | - echo "::group::Install system prerequisites" - bin/install_prerequisites_docker_ubuntu.sh - echo "::endgroup::" - echo "::group::Environment" - bin/environment.sh - echo "::endgroup::" - echo "::group::Install generic linux package" - bin/release/install_generic_linux_package.sh - export PATH="/tmp/hurl-generic-linux:$PATH" - echo "::endgroup::" - echo "::group::Install tests prerequisites" - bin/test/test_prerequisites.sh - echo "::endgroup::" - echo "::group::Tests" - bin/test/test_integ.sh - echo "::endgroup::" - - name: Archive production artifacts - uses: actions/upload-artifact@v3 - if: ${{ always() }} - with: - name: test-generic-linux-package-docker-debian-x64-artifacts - path: | - integration/mitmdump.log - integration/server.log - integration/server-ssl.log - - test-generic-linux-docker-archlinux-x64: - needs: release-generic-linux-x64 - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - name: Retrieve release-generic-linux-x64-artifacts - uses: actions/download-artifact@v3 - with: - name: release-generic-linux-x64-artifacts - path: target/upload - - name: Install package and tests integ - uses: addnab/docker-run-action@v3 - with: - image: archlinux - options: --volume ${{ github.workspace }}:/work --workdir /work --privileged - run: | - echo "::group::Install system prerequisites" - bin/install_prerequisites_docker_archlinux.sh - echo "::endgroup::" - echo "::group::Environment" - bin/environment.sh - echo "::endgroup::" - echo "::group::Install generic linux package" - bin/release/install_generic_linux_package.sh - export PATH="/tmp/hurl-generic-linux:$PATH" - echo "::endgroup::" - echo "::group::Install tests prerequisites" - bin/test/test_prerequisites.sh - echo "::endgroup::" - echo "::group::Tests" - bin/test/test_integ.sh - echo "::endgroup::" - - name: Archive production artifacts - uses: actions/upload-artifact@v3 - if: ${{ always() }} - with: - name: test-generic-linux-package-docker-archlinux-x64-artifacts - path: | - integration/mitmdump.log - integration/server.log - integration/server-ssl.log - - test-generic-linux-docker-fedora-x64: - needs: release-generic-linux-x64 - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - name: Retrieve release-generic-linux-x64-artifacts - uses: actions/download-artifact@v3 - with: - name: release-generic-linux-x64-artifacts - path: target/upload - - name: Install package and tests integ - uses: addnab/docker-run-action@v3 - with: - image: fedora - options: --volume ${{ github.workspace }}:/work --workdir /work --privileged - run: | - echo "::group::Install system prerequisites" - bin/install_prerequisites_docker_fedora.sh - echo "::endgroup::" - echo "::group::Environment" - bin/environment.sh - echo "::endgroup::" - echo "::group::Install generic linux package" - bin/release/install_generic_linux_package.sh - export PATH="/tmp/hurl-generic-linux:$PATH" - echo "::group::Install tests prerequisites" - echo "::endgroup::" - bin/test/test_prerequisites.sh - echo "::endgroup::" - echo "::group::Tests" - bin/test/test_integ.sh || true # to be fixed => "error in stderr actual: > "${GITHUB_ENV}" - - name: Install Python 3.8 - uses: actions/setup-python@v4 - with: - python-version: '3.8' - - name: Install Curl 7.68 - uses: myci-actions/add-deb-repo@10 - with: - repo: deb http://azure.archive.ubuntu.com/ubuntu/ focal main restricted - repo-name: focal - install: curl - - name: Test integ - run: | - bin/test/test_prerequisites.sh - bin/test/test_integ.sh - - name: Get version - run: | - VERSION=$(bin/release/get_version.sh) - echo "VERSION=${VERSION}" | tee -a "${GITHUB_ENV}" - - name: Create deb package - run: | - bin/release/man.sh - bin/release/create_deb_package.sh - - name: Install package - run: | - bin/release/install_deb_package.sh - echo "PATH=/tmp/hurl-deb-package/usr/bin:$PATH" >> "${GITHUB_ENV}" - - name: Test integ - run: | - bin/test/test_prerequisites.sh - bin/test/test_integ.sh - - name: Archive production artifacts - uses: actions/upload-artifact@v3 - with: - name: release-deb-x64-artifacts - path: target/upload/* - - release-macos-x64: - runs-on: macos-latest - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - name: Install Rust - run: bin/install_rust_latest.sh - - name: Install Python 3.8 - uses: actions/setup-python@v4 - with: - python-version: '3.8' - - name: Build - run: | - bin/release/release.sh - echo "PATH=:${PWD}/target/release:$PATH" >> "${GITHUB_ENV}" - - name: Test integ - run: | - bin/test/test_prerequisites.sh - bin/test/test_integ.sh - - name: Get version - run: | - VERSION=$(bin/release/get_version.sh) - echo "VERSION=${VERSION}" | tee -a "${GITHUB_ENV}" - - name: Create generic macos package - run: | - bin/release/man.sh - bin/release/create_tarball.sh macos - - name: Install package - run: | - bin/release/install_generic_macos_package.sh - echo "PATH=/tmp/hurl-generic-macos:$PATH" >> "${GITHUB_ENV}" - - name: Test integ - run: | - bin/test/test_prerequisites.sh - bin/test/test_integ.sh - - name: Archive production artifacts - uses: actions/upload-artifact@v3 - with: - name: release-macos-x64-artifacts - path: target/upload/* - - release-windows-x64: - runs-on: windows-latest + control-release: + if: github.event.inputs.create-release-branch == 'true' env: - VCPKGRS_DYNAMIC: 1 + GITHUB_CONTEXT: ${{ toJson(github) }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + outputs: + release_version: ${{ steps.set-release-version.outputs.release_version }} + release_branch: ${{ steps.set-release-branch.outputs.release_branch }} + name: control-release + runs-on: ubuntu-latest steps: - - name: Set git to use LF - run: | - git config --global core.autocrlf false - git config --global core.eol lf - - name: Checkout repository - uses: actions/checkout@v3 - - uses: actions/cache@v3 - with: - path: C:\vcpkg\installed - key: ${{ runner.os }}-release-windows-x64-${{ github.sha }} - restore-keys: ${{ runner.os }}-release-windows-x64- - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - profile: minimal - - name: Environment - run: .\bin\environment.ps1 - - name: Install prerequisites - run: .\bin\install_prerequisites_windows.ps1 - - name: Build and test integ - run: | - .\bin\release\release.ps1 - .\bin\test\test_prerequisites.ps1 - .\bin\test\test_integ.ps1 - - name: Create windows64 Zip package - run: .\bin\release\create_windows64_zip_package.ps1 - - name: Install win64 zip and test integ - run: | - .\bin\release\install_windows64_zip_package.ps1 - .\bin\test\test_prerequisites.ps1 - .\bin\test\test_integ.ps1 - - name: Create windows64 installer - run: .\bin\release\create_windows64_installer.ps1 - - name: Install win64 installer and test integ - run: | - .\bin\release\install_windows64_installer.ps1 - .\bin\test\test_prerequisites.ps1 - .\bin\test\test_integ.ps1 - - name: Archive production artifacts - uses: actions/upload-artifact@v3 - with: - name: release-windows-x64-artifacts - path: | - .\target\win-package\hurl-*-installer.exe - .\target\win-package\hurl-*-win64.zip + - name: Checkout repository + uses: actions/checkout@v3 + with: + ref: master + + - name: Check trigger branch + run: | + if [ "${{ github.ref_name }}" == "master" ] ; then + echo " - āœ… The branch triggering this workflow is master." + else + echo " - āŒ The branch triggering this workflow is ${{ github.ref_name }} instead of master." + exit 1 + fi + + - name: Set release version + id: set-release-version + run: | + actual_version=$(grep -E "^version" packages/hurl/Cargo.toml | cut --delimiter "=" --field 2 | tr -d '" ') + echo "actual_version=${actual_version}" | tee -a $GITHUB_OUTPUT + release_version=$(echo "${actual_version}" | cut --delimiter "-" --field 1) + echo "release_version=${release_version}" | tee -a $GITHUB_OUTPUT + + - name: Set release branch + id: set-release-branch + run: | + echo "release_branch=release/${{ steps.set-release-version.outputs.release_version }}" | tee -a $GITHUB_OUTPUT + + - name: Control release version + run: | + if [ "${{ github.event.inputs.control-release-version }}" == "${{ steps.set-release-version.outputs.release_version }}" ] ; then + echo " - āœ… Desired release version ${{ github.event.inputs.control-release-version }} equals version ${{ steps.set-release-version.outputs.release_version }} getted from package/hurl/Cargo.toml on master." + else + echo " - āŒ Desired release version ${{ github.event.inputs.control-release-version }} do not equals version ${{ steps.set-release-version.outputs.release_version }} getted from package/hurl/Cargo.toml on master." + exit 1 + fi + + clean-release: + if: github.event.inputs.create-release-branch == 'true' + needs: control-release + env: + GITHUB_CONTEXT: ${{ toJson(github) }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + name: clean-release + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + ref: master + + - name: Check release pull request existence + id: check-release-pull-request-existence + run: | + actual_pr_number=$(gh pr list --repo "${{ github.repository }}" --head "${{ needs.control-release.outputs.release_branch }}" --state "open" --json number --jq .[].number) + actual_pr_number=${actual_pr_number:-0} + echo "actual_pr_number=${actual_pr_number}" | tee -a "${GITHUB_OUTPUT}" + if [ ${actual_pr_number} -eq 0 ] ; then + echo " - āœ… There is no pull request." + echo "release_pr_exists=false" | tee -a $GITHUB_OUTPUT + else + echo " - āœ… Actual pull request number is ${actual_pr_number}." + echo "release_pr_exists=true" | tee -a $GITHUB_OUTPUT + fi + + - name: Close actual pull request + if: steps.check-release-pull-request-existence.outputs.release_pr_exists == 'true' + run: | + comment=" - āœ… Pull request nĀ°${{ steps.check-release-pull-request-existence.outputs.actual_pr_number }} closed before opening new one." + gh pr close "${{ steps.check-release-pull-request-existence.outputs.actual_pr_number }}" --comment "${comment}" --delete-branch && gh_exit_code=0 || gh_exit_code=$? + if [ ${gh_exit_code} -eq 0 ] ; then + echo " - ${comment}" + else + comment=" - āŒ A problem occurs when attempting to close PR nĀ°${{ steps.check-release-pull-request-existence.outputs.actual_pr_number }}." + gh pr comment "${{ steps.check-release-pull-request-existence.outputs.actual_pr_number }}" --body "${comment} Please refer to ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID} logs." + echo " - ${comment}" + exit 1 + fi + + - name: Check github release existence + id: check-github-release-existence + run: | + gh release list || true + escaped_version=$(echo "${{ needs.control-release.outputs.release_version }}" | sed "s#\.#\\\.#g") + github_release_exists=$(gh release list | (grep -c "${escaped_version}" || true)) + if [ ${github_release_exists} -eq 0 ] ; then + echo " - āœ… Github release ${{ needs.control-release.outputs.release_version }} does not exist." + echo "github_release_exists=false" | tee -a $GITHUB_OUTPUT + else + echo " - āœ… Github release ${{ needs.control-release.outputs.release_version }} already exists on remote." + echo "github_release_exists=true" | tee -a $GITHUB_OUTPUT + fi + + - name: Delete github release + if: steps.check-github-release-existence.outputs.github_release_exists == 'true' + run: | + gh release delete ${{ needs.control-release.outputs.release_version }} --yes && gh_exit_code=0 || gh_exit_code=$? + if [ ${gh_exit_code} -eq 0 ] ; then + echo " - āœ… ${{ needs.control-release.outputs.release_version }} github release deleted." + else + echo " - āŒ A problem occurs when attempting to delete ${{ needs.control-release.outputs.release_version }} github release." + exit 1 + fi + + - name: Check tag existence + id: check-tag-existence + run: | + escaped_version=$(echo "${{ needs.control-release.outputs.release_version }}" | sed "s#\.#\\\.#g") + tag_exists=$(git ls-remote --tags | (grep -c "${escaped_version}" || true)) + if [ ${tag_exists} -eq 0 ] ; then + echo " - āœ… The origin/${{ needs.control-release.outputs.release_version }} tag does not exists on remote." + echo "release_tag_exists=false" | tee -a $GITHUB_OUTPUT + else + echo " - āœ… The origin/${{ needs.control-release.outputs.release_version }} tag already exists on remote." + echo "release_tag_exists=true" | tee -a $GITHUB_OUTPUT + fi + + - name: Delete release tag + if: steps.check-tag-existence.outputs.release_tag_exists == 'true' + run: | + git push origin --delete ${{ needs.control-release.outputs.release_version }} && git_exit_code=0 || git_exit_code=$? + if [ ${git_exit_code} -eq 0 ] ; then + echo " - āœ… ${{ needs.control-release.outputs.release_version }} tag deleted." + else + echo " - āŒ A problem occurs when attempting to delete ${{ needs.control-release.outputs.release_version }} tag." + exit 1 + fi + + - name: Check branch existence + id: check-branch-existence + run: | + escaped_version=$(echo "${{ needs.control-release.outputs.release_version }}" | sed "s#\.#\\\.#g") + branch_exists=$(git ls-remote | (grep -c "${escaped_version}" || true)) + if [ ${branch_exists} -eq 0 ] ; then + echo " - āœ… The origin/${{ needs.control-release.outputs.release_branch }} branch does not exists on remote." + echo "release_branch_exists=false" | tee -a $GITHUB_OUTPUT + else + echo " - āœ… The origin/${{ needs.control-release.outputs.release_branch }} branch already exists on remote." + echo "release_branch_exists=true" | tee -a $GITHUB_OUTPUT + fi + + - name: Delete release branch + if: steps.check-branch-existence.outputs.release_branch_exists == 'true' + run: | + git push origin --delete ${{ needs.control-release.outputs.release_branch }} && git_exit_code=0 || git_exit_code=$? + if [ ${git_exit_code} -eq 0 ] ; then + echo " - āœ… ${{ needs.control-release.outputs.release_branch }} branch deleted." + else + echo " - āŒ A problem occurs when attempting to delete ${{ needs.control-release.outputs.release_branch }} branch." + exit 1 + fi + + create-release-branch: + if: github.event.inputs.create-release-branch == 'true' + needs: + - clean-release + - control-release + env: + GITHUB_CONTEXT: ${{ toJson(github) }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + name: create-release-branch + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + ref: master + + - name: Create release branch + id: create-release-branch + run: | + git checkout -b "${{ needs.control-release.outputs.release_branch }}" + git push origin "${{ needs.control-release.outputs.release_branch }}" && git_exit_code=0 || git_exit_code=$? + if [ ${git_exit_code} -eq 0 ] ; then + echo " - āœ… ${{ needs.control-release.outputs.release_branch }} branch created." + else + echo " - āŒ A problem occurs when attempting to create ${{ needs.control-release.outputs.release_branch }} branch." + exit 1 + fi + + - name: Checkout new release branch + uses: actions/checkout@v3 + with: + ref: ${{ needs.control-release.outputs.release_branch }} + + - name: Init git credentials + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + + - 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 = \"${{ needs.control-release.outputs.release_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 = \"${{ needs.control-release.outputs.release_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}/${{ needs.control-release.outputs.release_version }}/g" "${version_doc}" + grep "${{ needs.control-release.outputs.release_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 create release commits + run: | + git commit -am "Create ${{ needs.control-release.outputs.release_version }} release" + git push && git_exit_code=0 || git_exit_code=$? + if [ ${git_exit_code} -eq 0 ] ; then + echo " - āœ… commits pushed to ${{ needs.control-release.outputs.release_branch }}." + else + echo " - āŒ A problem occurs when attempting to push create relase commits to ${{ needs.control-release.outputs.release_branch }} branch." + exit 1 + fi + + - name: Archive artifacts + uses: actions/upload-artifact@v3 + if: ${{ always() }} + with: + name: release-changelog + path: | + release_changelog.md + + package-release: + needs: + - clean-release + - control-release + - create-release-branch + name: package-release + if: github.event.inputs.deliver-github-release == 'true' + uses: Orange-OpenSource/hurl/.github/workflows/package.yml@master + with: + branch: ${{ needs.control-release.outputs.release_branch }} + + deliver-github-release: + env: + GITHUB_CONTEXT: ${{ toJson(github) }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO: ${{ github.repository }} + needs: + - clean-release + - control-release + - create-release-branch + - package-release + name: deliver-github-release + if: github.event.inputs.deliver-github-release == 'true' + runs-on: ubuntu-latest + steps: + - name: Checkout new release branch + uses: actions/checkout@v3 + with: + ref: ${{ needs.control-release.outputs.release_branch }} + + - name: Init git credentials + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + - uses: actions/download-artifact@master + with: + path: artifacts + + - name: Push tag + run: | + git tag -a ${{ needs.control-release.outputs.release_version }} -m "Release ${{ needs.control-release.outputs.release_version }}" + git tag -n + git push --tags && git_exit_code=0 || git_exit_code=$? + if [ ${git_exit_code} -eq 0 ] ; then + echo " - āœ… ${{ needs.control-release.outputs.release_version }} tag created." + git fetch + else + echo " - āŒ A problem occurs when attempting to create ${{ needs.control-release.outputs.release_version }} tag." + exit 1 + fi + + - name: deliver release + run: | + python3 bin/release/changelog_extract.py ${{ needs.control-release.outputs.release_version }} > release_changelog.md + gh release create ${{ needs.control-release.outputs.release_version }} \ + --target ${{ needs.control-release.outputs.release_branch }} \ + --notes-file release_changelog.md \ + --draft \ + artifacts/release-deb-x64-artifacts/hurl_"${{ needs.control-release.outputs.release_version }}"_amd64.deb \ + artifacts/release-generic-linux-x64-artifacts/hurl-"${{ needs.control-release.outputs.release_version }}"-x86_64-linux.tar.gz \ + artifacts/release-macos-x64-artifacts/hurl-"${{ needs.control-release.outputs.release_version }}"-x86_64-macos.tar.gz \ + artifacts/release-windows-x64-artifacts/hurl-"${{ needs.control-release.outputs.release_version }}"-win64-installer.exe \ + artifacts/release-windows-x64-artifacts/hurl-"${{ needs.control-release.outputs.release_version }}"-win64.zip && gh_exit_code=0 || gh_exit_code=$? + if [ ${gh_exit_code} -eq 0 ] ; then + echo " - āœ… Github release ${{ needs.control-release.outputs.release_version }} created." + else + echo " - āŒ A problem occurs when attempting to create github release ${{ needs.control-release.outputs.release_version }}." + exit 1 + fi + + - name: Create new pull request + run: | + GITHUB_TOKEN=${{ secrets.LEPAPAREIL_CI_TOKEN }} + { + echo "āš  This is a github releasing PR." + echo "- Please \`/accept\` this PR only when github release ${{ needs.control-release.outputs.release_version }} is published" + echo "- Please use \`/accept --release\` if you want to automatically update master branch to next SNAPSHOT version" + } > file-body.txt + gh pr create \ + --title "Merge github published ${{ needs.control-release.outputs.release_branch }} into master" \ + --body-file file-body.txt \ + --base master \ + --label bot && gh_exit_code=0 || gh_exit_code=$? + if [ ${gh_exit_code} -eq 0 ] ; then + new_pr_number=$(gh pr list --repo "${{ github.repository }}" --head "${{ needs.control-release.outputs.release_branch }}" --state "open" --json number --jq .[].number) + echo " - āœ… Creation of pull request nĀ°${new_pr_number} succeeds." + else + echo " - āŒ A problem occurs when attempting to create new pull request." + exit 1 + fi diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3e06d9f0c..61f0753f3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,15 @@ name: test -on: [pull_request] +on: + pull_request: + workflow_dispatch: + workflow_call: + inputs: + branch: + description: "ref branch for this workflow" + default: "master" + required: true + type: string env: CARGO_TERM_COLOR: always @@ -11,18 +20,25 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v3 + with: + ref: ${{ inputs.branch }} + - name: Environment run: bin/environment.sh + - name: Install Prerequisites run: bin/install_prerequisites_ubuntu.sh + - name: Install Rust run: bin/install_rust_latest.sh + - name: Build run: | bin/release/release.sh echo "PATH=${PWD}/target/release:$PATH" >> "${GITHUB_ENV}" - name: Bench Suite run: bin/test/bench.sh + - name: Archive artifacts uses: actions/upload-artifact@v3 if: ${{ always() }} @@ -39,20 +55,28 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v3 + with: + ref: ${{ inputs.branch }} + - name: Environment run: bin/environment.sh + - name: Install Prerequisites run: bin/install_prerequisites_ubuntu.sh + - name: Install Rust run: bin/install_rust_latest.sh + - name: Test Prerequisites run: bin/test/test_prerequisites.sh + - name: Tests units run: | bin/test/test_unit.sh echo "PATH=${PWD}/target/release:$PATH" >> "${GITHUB_ENV}" - name: Integration Tests run: bin/test/test_integ.sh + - name: Archive production artifacts uses: actions/upload-artifact@v3 if: ${{ always() }} @@ -72,30 +96,40 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v3 + with: + ref: ${{ inputs.branch }} + - name: Environment run: bin/environment.sh + - name: Install Prerequisites run: bin/install_prerequisites_ubuntu.sh + - name: Install Rust run: bin/install_rust_latest.sh + - name: Install Python 3.8 uses: actions/setup-python@v4 with: python-version: '3.8' + - name: Install Curl 7.68 uses: myci-actions/add-deb-repo@10 with: repo: deb http://azure.archive.ubuntu.com/ubuntu/ focal main restricted repo-name: focal install: curl + - name: Test Prerequisites run: bin/test/test_prerequisites.sh + - name: Tests units run: | bin/test/test_unit.sh echo "PATH=${PWD}/target/release:$PATH" >> "${GITHUB_ENV}" - name: Integration Tests run: bin/test/test_integ.sh + - name: Archive production artifacts uses: actions/upload-artifact@v3 if: ${{ always() }} @@ -111,7 +145,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v3 + with: + ref: ${{ inputs.branch }} + - name: Build, Test units and Integration tests uses: addnab/docker-run-action@v3 with: @@ -130,6 +167,7 @@ jobs: echo "::group::Tests" bin/test/test.sh echo "::endgroup::" + - name: Archive production artifacts uses: actions/upload-artifact@v3 if: ${{ always() }} @@ -144,7 +182,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v3 + with: + ref: ${{ inputs.branch }} + - name: Build, Test units and Integration tests uses: addnab/docker-run-action@v3 with: @@ -163,6 +204,7 @@ jobs: echo "::group::Tests" bin/test/test.sh echo "::endgroup::" + - name: Archive production artifacts uses: actions/upload-artifact@v3 if: ${{ always() }} @@ -177,7 +219,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v3 + with: + ref: ${{ inputs.branch }} + - name: Build, Test units and Integration tests uses: addnab/docker-run-action@v3 with: @@ -196,6 +241,7 @@ jobs: echo "::group::Tests" bin/test/test.sh echo "::endgroup::" + - name: Archive production artifacts uses: actions/upload-artifact@v3 if: ${{ always() }} @@ -214,22 +260,30 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v3 + with: + ref: ${{ inputs.branch }} + - name: Environment run: bin/environment.sh + - name: Install Rust run: bin/install_rust_latest.sh + - name: Install Python 3.8 uses: actions/setup-python@v4 with: python-version: '3.8' + - name: Test Prerequisites run: bin/test/test_prerequisites.sh + - name: Tests units run: | bin/test/test_unit.sh echo "PATH=${PWD}/target/release:$PATH" >> "${GITHUB_ENV}" - name: Integration Tests run: bin/test/test_integ.sh + - name: Archive production artifacts uses: actions/upload-artifact@v3 if: ${{ always() }} @@ -250,26 +304,36 @@ jobs: - name: Set git to use LF run: | git config --global core.autocrlf false - git config --global core.eol lf + git config --global core.eol lf + - name: Checkout repository uses: actions/checkout@v3 - - uses: actions/cache@v3 + with: + ref: ${{ inputs.branch }} + + - name: Cache + uses: actions/cache@v3 with: path: C:\vcpkg\installed key: ${{ runner.os }}-test-windows-x64-${{ github.sha }} restore-keys: ${{ runner.os }}-test-windows-x64- + - name: Install Rust uses: actions-rs/toolchain@v1 with: toolchain: stable override: true profile: minimal + - name: Environment run: .\bin\environment.ps1 + - name: Install Prerequisites run: .\bin\install_prerequisites_windows.ps1 + - name: Build and test run: .\bin\test\test.ps1 + - name: Archive production artifacts uses: actions/upload-artifact@v3 if: ${{ always() }} diff --git a/.github/workflows/update-branch-version.yml b/.github/workflows/update-branch-version.yml new file mode 100644 index 000000000..23ca7de00 --- /dev/null +++ b/.github/workflows/update-branch-version.yml @@ -0,0 +1,124 @@ +name: update-branch-version + +on: + workflow_dispatch: + inputs: + new_version: + description: 'Version (G.R.C or G.R.C-SNASPHOT)' + required: true + type: string + workflow_call: + secrets: + LEPAPAREIL_CI_TOKEN: + description: 'secrets.LEPAPAREIL_CI_TOKEN from the caller workflow' + required: true + inputs: + new_version: + description: "Version (G.R.C or G.R.C-SNASPHOT)" + 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 + diff --git a/.github/workflows/update-crates.yml b/.github/workflows/update-crates.yml index 41dac3980..65b70f6ed 100644 --- a/.github/workflows/update-crates.yml +++ b/.github/workflows/update-crates.yml @@ -17,7 +17,6 @@ jobs: name: update-crates runs-on: ubuntu-latest steps: - - name: Checkout repository uses: actions/checkout@v3 with: @@ -25,102 +24,103 @@ jobs: - name: Crates update run: | - UPDATE_CRATES_OUTPUT="/tmp/update.output" - echo "UPDATE_CRATES_OUTPUT=${UPDATE_CRATES_OUTPUT}" | tee -a "${GITHUB_ENV}" - bin/update_crates.sh 2>&1 > "${UPDATE_CRATES_OUTPUT}" && crates_update_exit_code=0 || crates_update_exit_code=$? - if [ ${crates_update_exit_code} -eq 0 ] ; then - UPDATED_CRATES_COUNT=$(grep -v "crates.io index" "${UPDATE_CRATES_OUTPUT}" | (grep -cE "updated to |.*Updating.*->.*" || true) ) - echo "UPDATED_CRATES_COUNT=${UPDATED_CRATES_COUNT}" | tee -a "${GITHUB_ENV}" - echo " - āœ… Update crates succeeds with ${UPDATED_CRATES_COUNT} crates updated." - else - echo " - āŒ A problem occurs updating crates. Please refer to ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID} logs." - exit 1 - fi + UPDATE_CRATES_OUTPUT="/tmp/update.output" + echo "UPDATE_CRATES_OUTPUT=${UPDATE_CRATES_OUTPUT}" | tee -a "${GITHUB_ENV}" + bin/update_crates.sh 2>&1 > "${UPDATE_CRATES_OUTPUT}" && crates_update_exit_code=0 || crates_update_exit_code=$? + if [ ${crates_update_exit_code} -eq 0 ] ; then + UPDATED_CRATES_COUNT=$(grep -v "crates.io index" "${UPDATE_CRATES_OUTPUT}" | (grep -cE "updated to |.*Updating.*->.*" || true) ) + echo "UPDATED_CRATES_COUNT=${UPDATED_CRATES_COUNT}" | tee -a "${GITHUB_ENV}" + echo " - āœ… Update crates succeeds with ${UPDATED_CRATES_COUNT} crates updated." + else + echo " - āŒ A problem occurs updating crates. Please refer to ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID} logs." + exit 1 + fi - name: Get actual pull request id run: | - ACTUAL_PR_NUMBER=$(gh pr list --repo "${REPO}" --head "${BOT_UPDATE_BRANCHE_NAME}" --state "open" --json number --jq .[].number) - ACTUAL_PR_NUMBER=${ACTUAL_PR_NUMBER:-0} - echo "ACTUAL_PR_NUMBER=${ACTUAL_PR_NUMBER}" | tee -a "${GITHUB_ENV}" - if [ ${ACTUAL_PR_NUMBER} -eq 0 ] ; then - echo " - āœ… There is no pull request for crates update." - else - echo " - āœ… Actual pull request number is ${ACTUAL_PR_NUMBER}." - fi + ACTUAL_PR_NUMBER=$(gh pr list --repo "${REPO}" --head "${BOT_UPDATE_BRANCHE_NAME}" --state "open" --json number --jq .[].number) + ACTUAL_PR_NUMBER=${ACTUAL_PR_NUMBER:-0} + echo "ACTUAL_PR_NUMBER=${ACTUAL_PR_NUMBER}" | tee -a "${GITHUB_ENV}" + if [ ${ACTUAL_PR_NUMBER} -eq 0 ] ; then + echo " - āœ… There is no pull request for crates update." + else + echo " - āœ… Actual pull request number is ${ACTUAL_PR_NUMBER}." + fi - name: Close actual pull request if: env.ACTUAL_PR_NUMBER != 0 run: | - if [ ${UPDATED_CRATES_COUNT} -eq 0 ] ; then - comment="āœ… Pull request nĀ°${ACTUAL_PR_NUMBER} closed because crates are up to date on master branch." - else - comment="āœ… Pull request nĀ°${ACTUAL_PR_NUMBER} closed before opening new one with new updated crates list." - fi - gh pr close "${ACTUAL_PR_NUMBER}" --comment "${comment}" --delete-branch && gh_exit_code=0 || gh_exit_code=$? - if [ ${gh_exit_code} -eq 0 ] ; then - echo " - ${comment}" - else - comment="āŒ A problem occurs when bot attempts to close PR nĀ°${ACTUAL_PR_NUMBER}." - gh pr comment "${ACTUAL_PR_NUMBER}" --body "${comment} Please refer to ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID} logs." - echo " - ${comment}" - exit 1 - fi + if [ ${UPDATED_CRATES_COUNT} -eq 0 ] ; then + comment="āœ… Pull request nĀ°${ACTUAL_PR_NUMBER} closed because crates are up to date on master branch." + else + comment="āœ… Pull request nĀ°${ACTUAL_PR_NUMBER} closed before opening new one with new updated crates list." + fi + gh pr close "${ACTUAL_PR_NUMBER}" --comment "${comment}" --delete-branch && gh_exit_code=0 || gh_exit_code=$? + if [ ${gh_exit_code} -eq 0 ] ; then + echo " - ${comment}" + else + comment="āŒ A problem occurs when bot attempts to close PR nĀ°${ACTUAL_PR_NUMBER}." + gh pr comment "${ACTUAL_PR_NUMBER}" --body "${comment} Please refer to ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID} logs." + echo " - ${comment}" + exit 1 + fi - name: Push updates to branch if: env.UPDATED_CRATES_COUNT != 0 run: | - git config --local user.email "action@github.com" - git config --local user.name "GitHub Action" - git checkout -b "${BOT_UPDATE_BRANCHE_NAME}" - git commit -am "Update crates" - git push --set-upstream origin "${BOT_UPDATE_BRANCHE_NAME}" && git_exit_code=0 || git_exit_code=$? - if [ ${git_exit_code} -eq 0 ] ; then - echo " - āœ… push crates update to ${BOT_UPDATE_BRANCHE_NAME} succeeds." - else - echo " - āŒ A problem occurs when attempting to push crates update to origin/${BOT_UPDATE_BRANCHE_NAME}." - exit 1 - fi - branch_exists=$(git ls-remote | (grep -c "${BOT_UPDATE_BRANCHE_NAME}" || true)) - if [ ${branch_exists} -eq 1 ] ; then - echo " - āœ… The origin/${BOT_UPDATE_BRANCHE_NAME} now branch exists on remote." - else - echo " - āŒ Git push command succeeds but origin/${BOT_UPDATE_BRANCHE_NAME} still does not exist on remote." - exit 1 - fi + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git checkout -b "${BOT_UPDATE_BRANCHE_NAME}" + git commit -am "Update crates" + git push --set-upstream origin "${BOT_UPDATE_BRANCHE_NAME}" && git_exit_code=0 || git_exit_code=$? + if [ ${git_exit_code} -eq 0 ] ; then + echo " - āœ… push crates update to ${BOT_UPDATE_BRANCHE_NAME} succeeds." + else + echo " - āŒ A problem occurs when attempting to push crates update to origin/${BOT_UPDATE_BRANCHE_NAME}." + exit 1 + fi + branch_exists=$(git ls-remote | (grep -c "${BOT_UPDATE_BRANCHE_NAME}" || true)) + if [ ${branch_exists} -eq 1 ] ; then + echo " - āœ… The origin/${BOT_UPDATE_BRANCHE_NAME} now branch exists on remote." + else + echo " - āŒ Git push command succeeds but origin/${BOT_UPDATE_BRANCHE_NAME} still does not exist on remote." + exit 1 + fi - name: Create new pull request if: env.UPDATED_CRATES_COUNT != 0 run: | - GITHUB_TOKEN=${{ secrets.LEPAPAREIL_CI_TOKEN }} - gh pr create --fill --base master --head "${BOT_UPDATE_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_BRANCHE_NAME}" --state "open" --json number --jq .[].number) - echo " - āœ… Creation of pull request nĀ°${NEW_PR_NUMBER} succeeds." - else - echo " - āŒ A problem occurs when attempting to create new pull request." - exit 1 - fi - pr_comment_file="comment_file.md" - (grep -vE "newest|crates.io index" "${UPDATE_CRATES_OUTPUT}" || true) | \ - tr -s ' ' | \ - sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" | \ - sed "s/Updating //g" | \ - sed "s/: updated to / -> /g" | \ - sed "s/^=>/###/g" | \ - sed "s/^ /- /g" > "${pr_comment_file}" - pr_comment="$(cat "${pr_comment_file}")" - GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} - gh pr comment "${NEW_PR_NUMBER}" --body "${pr_comment}" && gh_exit_code=0 || gh_exit_code=$? - if [ ${gh_exit_code} -eq 0 ] ; then - echo " - āœ… Comment updates list to pull request nĀ° ${NEW_PR_NUMBER} succeeds." - else - echo " - āŒ A problem occurs when attempting to create updates list comment into new pull request nĀ°${NEW_PR_NUMBER}." - exit 1 - fi - gh pr edit "${NEW_PR_NUMBER}" --add-label "bot,dependencies" && gh_exit_code=0 || gh_exit_code=$? - if [ ${gh_exit_code} -eq 0 ] ; then - echo " - āœ… Adding Label to pull request nĀ° ${NEW_PR_NUMBER} succeeds." - else - echo " - āŒ A problem occurs when attempting to add labels into new pull request nĀ°${NEW_PR_NUMBER}." - exit 1 - fi + GITHUB_TOKEN=${{ secrets.LEPAPAREIL_CI_TOKEN }} + gh pr create --fill --base master --head "${BOT_UPDATE_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_BRANCHE_NAME}" --state "open" --json number --jq .[].number) + echo " - āœ… Creation of pull request nĀ°${NEW_PR_NUMBER} succeeds." + else + echo " - āŒ A problem occurs when attempting to create new pull request." + exit 1 + fi + pr_comment_file="comment_file.md" + (grep -vE "newest|crates.io index" "${UPDATE_CRATES_OUTPUT}" || true) | \ + tr -s ' ' | \ + sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" | \ + sed "s/Updating //g" | \ + sed "s/: updated to / -> /g" | \ + sed "s/^=>/###/g" | \ + sed "s/^ /- /g" > "${pr_comment_file}" + pr_comment="$(cat "${pr_comment_file}")" + GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} + gh pr comment "${NEW_PR_NUMBER}" --body "${pr_comment}" && gh_exit_code=0 || gh_exit_code=$? + if [ ${gh_exit_code} -eq 0 ] ; then + echo " - āœ… Comment updates list to pull request nĀ° ${NEW_PR_NUMBER} succeeds." + else + echo " - āŒ A problem occurs when attempting to create updates list comment into new pull request nĀ°${NEW_PR_NUMBER}." + exit 1 + fi + gh pr edit "${NEW_PR_NUMBER}" --add-label "bot,dependencies" && gh_exit_code=0 || gh_exit_code=$? + if [ ${gh_exit_code} -eq 0 ] ; then + echo " - āœ… Adding Label to pull request nĀ° ${NEW_PR_NUMBER} succeeds." + else + echo " - āŒ A problem occurs when attempting to add labels into new pull request nĀ°${NEW_PR_NUMBER}." + exit 1 + fi +