From ec35bf1db7522358bb3d0bc82a1080d41c1498ff Mon Sep 17 00:00:00 2001 From: F-WRunTime Date: Thu, 28 Sep 2023 17:00:27 -0600 Subject: [PATCH] New action, new workflow test-pr using new action. New update-version workflow --- .github/actions/with-docker/action.yml | 33 +++++++++++++ .github/workflows/test-pr.yml | 67 ++++++++++++-------------- .github/workflows/update-version.yml | 33 +++++++++++++ 3 files changed, 96 insertions(+), 37 deletions(-) create mode 100644 .github/actions/with-docker/action.yml create mode 100644 .github/workflows/update-version.yml diff --git a/.github/actions/with-docker/action.yml b/.github/actions/with-docker/action.yml new file mode 100644 index 00000000..ac9e2534 --- /dev/null +++ b/.github/actions/with-docker/action.yml @@ -0,0 +1,33 @@ +name: 'With Docker' +description: 'Run a given stage with Docker Image' +inputs: + container-version: + description: 'Docker Image Version' + required: true + container-name: + description: 'Docker Container Name' + required: true +runs: + using: 'composite' + steps: + - name: 'Set up Docker' + shell: bash {0} + run: | + set -euxo pipefail + + CONTAINER_NAME=${{inputs.container-name}} + CONTAINER_VERSION=${{inputs.container-version}} + + docker run \ + --name ${CONTAINER_NAME} \ + --rm \ + --interactive \ + --tty \ + --detach \ + --user root \ + --workdir /home/user/workspace \ + runtimeverificationinc/kontrol:ubuntu-jammy-${CONTAINER_VERSION} + + # Copy the current Checkout direcotry into the container + docker cp . ${CONTAINER_NAME}:/home/user/workspace + docker exec ${CONTAINER_NAME} chown -R user:user /home/user diff --git a/.github/workflows/test-pr.yml b/.github/workflows/test-pr.yml index d9508d13..3d28c35a 100644 --- a/.github/workflows/test-pr.yml +++ b/.github/workflows/test-pr.yml @@ -1,5 +1,5 @@ --- -name: 'Update Version' +name: 'Test PR' on: pull_request: branches: @@ -11,52 +11,45 @@ concurrency: cancel-in-progress: true jobs: - set-image-version: - name: 'Set Image Version' - runs-on: [self-hosted, linux, flyweight] - outputs: - image-version: ${{ steps.image-version.outputs.kontrol_version }} - steps: - - name: 'Check out code' - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: 'Set Image Version' - id: image-version - run: | - kontrol_version=$(cat deps/kontrol_release) - echo "kontrol_version=${kontrol_version}" >> $GITHUB_ENV - new-version-test: name: 'Test Tool Update' runs-on: [self-hosted, linux, normal] - needs: [set-image-version] - container: - image: runtimeverificationinc/kontrol:ubuntu-jammy-${{ needs.set-image-version.outputs.image-version }} steps: - name: 'Check out code' uses: actions/checkout@v3 with: + token: ${{ secrets.JENKINS_GITHUB_PAT }} fetch-depth: 0 - - name: 'Configure GitHub user' + - name: 'Get Kontrol Version' run: | - git config user.name devops - git config user.email devops@runtimeverification.com + set -euo pipefail + # Get the version of the tool from the Dockerfile + echo "kontrol-version=$(cat deps/kontrol_release)" >> $GITHUB_ENV + # Get Repository Base name + echo "repository_basename=$(basename ${{ github.repository }})" >> $GITHUB_ENV + + - name: "Start Docker Container" + uses: ./.github/actions/with-docker + with: + container-name: '${{ env.repository_basename }}-ci' + container-version: '${{ env.kontrol-version }}' - name: 'Test New Tool Versions' run: | - set -euo pipefail - new-version=$(cat deps/kontrol_release) - kup install --version ${new-version} - # If all scripts in test.sh pass then the test is successful, else fail - # and print the name of the script that failed - for script in ./tests/*.sh; do - if ! bash "$script"; then - echo "Test failed: $script" - exit 1 - else - echo "Test passed: $script" - fi - done + # Run the following in the running docker container + docker exec -u user ${{ env.repository_basename }}-ci bash -c ' + set -euo pipefail + # If all scripts in test.sh pass then the test is successful, else fail + # and print the name of the script that failed + # Print the tests folder + ls -lR + for script in ./tests/*.sh; do + if ! bash "$script"; then + echo "Test failed: $script" + exit 1 + else + echo "Test passed: $script" + fi + done + ' diff --git a/.github/workflows/update-version.yml b/.github/workflows/update-version.yml new file mode 100644 index 00000000..dfd7ca90 --- /dev/null +++ b/.github/workflows/update-version.yml @@ -0,0 +1,33 @@ +name: 'Update Version' +on: + push: + branches: + - '_update-deps/runtimeverification/kontrol' +# Stop in progress workflows on the same branch and same workflow to use latest committed code +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + set-image-version: + runs-on: [self-hosted, linux, flyweight] + steps: + - uses: actions/checkout@v3 + with: + token: ${{ secrets.JENKINS_DEVOPS_TOKEN }} + - name: Set image version + run: | + # Search replace previous version in .github/workflows/test-pr.yml with new version in deps/kontrol_release + version=$(cat deps/kontrol_release) + sed -i "s/kontrol:ubuntu-jammy-.*$/kontrol:ubuntu-jammy-${version}/g" .github/workflows/test-pr.yml + git config --global user.name "DevOps" + git config --global user.email "devops@runtimeverification.com" + if [[ -z $(git status -s) ]]; then + echo "No changes to commit" + exit 0 + fi + else + git add . + git commit -m "Update kontrol image version to ${version}" + git push origin HEAD:${{ github.ref }} + fi \ No newline at end of file