From cf8387848d20d82fa770538ab90aec4d3ad200b7 Mon Sep 17 00:00:00 2001 From: yahavi Date: Fri, 2 Feb 2024 19:55:15 +0200 Subject: [PATCH 1/2] Modernize GitHub Actions examples --- .../.github/workflows/main.yml | 12 +- .../simple-github-action-example/README.md | 2 +- .../simple-github-action-example/workflow.yml | 4 +- .../.github/workflows/main.yml | 105 ------------------ .../README.md | 4 - .../deletion/repositories-spec.json | 10 -- .../maths/pom.xml | 74 ------------ .../dineshvelhal/javaprojects/maths/Math.java | 28 ----- .../javaprojects/maths/MathTest.java | 68 ------------ .../templates/local-repo-template.json | 5 - .../templates/remote-repo-template.json | 6 - .../templates/virtual-repo-template.json | 8 -- 12 files changed, 9 insertions(+), 317 deletions(-) delete mode 100644 repo-management-github-actions-example/.github/workflows/main.yml delete mode 100644 repo-management-github-actions-example/README.md delete mode 100644 repo-management-github-actions-example/deletion/repositories-spec.json delete mode 100644 repo-management-github-actions-example/maths/pom.xml delete mode 100644 repo-management-github-actions-example/maths/src/main/java/com/dineshvelhal/javaprojects/maths/Math.java delete mode 100644 repo-management-github-actions-example/maths/src/test/java/com/dineshvelhal/javaprojects/maths/MathTest.java delete mode 100644 repo-management-github-actions-example/templates/local-repo-template.json delete mode 100644 repo-management-github-actions-example/templates/remote-repo-template.json delete mode 100644 repo-management-github-actions-example/templates/virtual-repo-template.json diff --git a/github-action-examples/repo-management-github-actions-example/.github/workflows/main.yml b/github-action-examples/repo-management-github-actions-example/.github/workflows/main.yml index 000b9775b..e079f964b 100644 --- a/github-action-examples/repo-management-github-actions-example/.github/workflows/main.yml +++ b/github-action-examples/repo-management-github-actions-example/.github/workflows/main.yml @@ -20,20 +20,20 @@ jobs: name: calculate-ci-job steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup JDK 1.8 - uses: actions/setup-java@v1 + uses: actions/setup-java@v4 with: - java-version: 1.8 + distribution: 'temurin' + java-version: 8 - name: Setup JFrog CLI - uses: jfrog/setup-jfrog-cli@v2 + uses: jfrog/setup-jfrog-cli@v4 env: JF_ENV_1: ${{ secrets.JF_SECRET_ENV_1 }} - M2_HOME: /usr/local/apache-maven/apache-maven-3.6.3 - - name: Ping JFrog CLI + - name: Ping Artifactory run: jf rt ping - name: Set Environment Variables diff --git a/github-action-examples/simple-github-action-example/README.md b/github-action-examples/simple-github-action-example/README.md index 332b75c61..0c5c21114 100644 --- a/github-action-examples/simple-github-action-example/README.md +++ b/github-action-examples/simple-github-action-example/README.md @@ -3,7 +3,7 @@ This is an example Github workflow, which uses the [Setup JFrog CLI Github Actio ## Running the Example 1. Create a new Github repository. -2. Make sure you have version **1.29.0** or above of [JFrog CLI](https://jfrog.com/getcli/) on your local machine, by running ```jfrog -v```. +2. Make sure you have version **1.46.4** or above of [JFrog CLI](https://jfrog.com/getcli/) on your local machine, by running ```jfrog -v```. 3. Configure the details of your Artifactory server by running ```jfrog c add```. 4. Using the server ID you configured, export the server details by running ```jfrog c export ```. 5. Copy the generated token to the clipboard. diff --git a/github-action-examples/simple-github-action-example/workflow.yml b/github-action-examples/simple-github-action-example/workflow.yml index ef8ab2f6f..c0bdc8564 100644 --- a/github-action-examples/simple-github-action-example/workflow.yml +++ b/github-action-examples/simple-github-action-example/workflow.yml @@ -6,9 +6,9 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup JFrog CLI - uses: jfrog/setup-jfrog-cli@v3 + uses: jfrog/setup-jfrog-cli@v4 env: # JFrog platform url (for example: https://acme.jfrog.io) JF_URL: ${{ secrets.JF_URL }} diff --git a/repo-management-github-actions-example/.github/workflows/main.yml b/repo-management-github-actions-example/.github/workflows/main.yml deleted file mode 100644 index 87776adf2..000000000 --- a/repo-management-github-actions-example/.github/workflows/main.yml +++ /dev/null @@ -1,105 +0,0 @@ -name: calculate-ci-job -on: - push: - branches-ignore: [ master ] - pull_request: - branches-ignore: [ master ] - schedule: - - cron: '0 1 * * *' - -jobs: - build-jdk8: - runs-on: ${{ matrix.os }} - strategy: - max-parallel: 3 - fail-fast: false - #GitHub-hosted runners, possible to add: windows-latest - matrix: - os: [ubuntu-latest] - - name: calculate-ci-job - steps: - - name: Checkout - uses: actions/checkout@v1 - - - name: Setup JDK 1.8 - uses: actions/setup-java@v1 - with: - java-version: 1.8 - - - name: Setup JFrog CLI - uses: jfrog/setup-jfrog-cli@v1 - env: - JF_ARTIFACTORY_1: ${{ secrets.JF_ARTIFACTORY_SECRET_1 }} - M2_HOME: /usr/local/apache-maven/apache-maven-3.6.3 - - - name: Ping JFrog CLI - run: jfrog rt ping - - - name: Set Environment Variables - run: | - echo "::set-env name=repository::$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//_/g')" - echo $repository - - # if pushed from a feature branch, should create a proper repository in artifactory for that - - name: Feature Branch Repository Creation - run: | - jfrog rt rc templates/local-repo-template.json --vars key1=$repository - jfrog rt rc templates/remote-repo-template.json --vars key1=$repository - jfrog rt rc templates/virtual-repo-template.json --vars key1=$repository - - - if: always() - name: Feature Branch Repository Update - env: - SERVER_ID: tal-eplus-saas - run: | - echo "::set-env name=repository::$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//_/g')" - jfrog rt mvnc --server-id-resolve=$SERVER_ID --server-id-deploy=$SERVER_ID --repo-resolve-releases=auto-cli-virtual-$repository --repo-resolve-snapshots=auto-cli-virtual-$repository --repo-deploy-releases=auto-cli-virtual-$repository --repo-deploy-snapshots=auto-cli-virtual-$repository - - - if: always() - name: Build & Deploy - run: | - cd maths && jfrog rt mvn clean install - - - if: always() - name: Publish Build Information - run: | - # Collect environment variables for the build - jfrog rt bce - # Collect VCS details from git and add them to the build - jfrog rt bag - # Publish build info - jfrog rt bp - - - if: always() - name: Xray Scan - run: | - jfrog rt bs - - - if: always() - name: Feature Branch Repository Deletion - env: - NUMBER_OF_DAYS_TO_KEEP: 90 - run: | - # Extract all the LOCAL repositories created automatically by the CI process - jfrog rt curl -XGET /api/repositories | jq '[.[] | .key | select(test("auto-cli-local"))]' > deletion/auto_created_repositories.json && cat deletion/auto_created_repositories.json - - # Calculate for which month are we going back to verify who should be deleted - jq -n 'now - 3600 * 24 * '$NUMBER_OF_DAYS_TO_KEEP' | gmtime | todate' > deletion/months_indicator && cat deletion/months_indicator - - # Iterate over all the repositories, delete those by the latest file that was modified - jq -c '.[]' deletion/auto_created_repositories.json | while read i; do - echo Iterating repository = $i - sh -c "jfrog rt s --spec deletion/repositories-spec.json --spec-vars='key1="$i"' > deletion/search_results && cat deletion/search_results" - - # If the repository is empty / latest modified file is older > NUMBER_OF_DAYS_TO_KEEP days => DELETE the repository - if [[ $(cat deletion/search_results) == "[]" ]]; then - echo "Deleting repository: $i, repository is empty" - sh -c "jfrog rt rdel $i --quiet && jfrog rt rdel ${i//local/virtual} --quiet && jfrog rt rdel ${i//local/jcenter} --quiet" - elif [[ $(cat deletion/search_results | jq --arg month_indicator $(cat deletion/months_indicator) '.[] | .modified | . <= $month_indicator') = "true" ]]; then - echo "Deleting repository: $i, too old to keep in Artifactory" - sh -c "jfrog rt rdel $i --quiet && jfrog rt rdel ${i//local/virtual} --quiet && jfrog rt rdel ${i//local/jcenter} --quiet" - else - echo "Skipping Repository deletion - repository is still relevant" - fi - done \ No newline at end of file diff --git a/repo-management-github-actions-example/README.md b/repo-management-github-actions-example/README.md deleted file mode 100644 index 52e7698e6..000000000 --- a/repo-management-github-actions-example/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# Repo Management GitHub Actions Example - -This example demonstrates how you can use GitHub Actions to automate the creation and deletion of Artifactory repositories, which correspond to feature branches that are created on GitHub. -The full description of how to set up and run this example are available on <---this blog post--->. \ No newline at end of file diff --git a/repo-management-github-actions-example/deletion/repositories-spec.json b/repo-management-github-actions-example/deletion/repositories-spec.json deleted file mode 100644 index d30197285..000000000 --- a/repo-management-github-actions-example/deletion/repositories-spec.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "files": [ - { - "pattern": ${key1}, - "sortBy": ["modified"], - "sortOrder": "desc", - "limit": 1 - } - ] -} diff --git a/repo-management-github-actions-example/maths/pom.xml b/repo-management-github-actions-example/maths/pom.xml deleted file mode 100644 index 474d614ce..000000000 --- a/repo-management-github-actions-example/maths/pom.xml +++ /dev/null @@ -1,74 +0,0 @@ - - 4.0.0 - - com.dineshvelhal.javaprojects - maths-app - 4.500 - jar - - maths - http://maven.apache.org - - - UTF-8 - project-repository-name - projecet-distribution-url - - - - - central - artifactory - ${project.distribution.url} - - - - - central - ${project.distribution.url} - - - - - junit - junit - 4.12 - test - - - - org.sonarsource.scanner.maven - sonar-maven-plugin - 3.7.0.1746 - - - - - - - - - org.sonarsource.scanner.maven - sonar-maven-plugin - 3.7.0.1746 - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.6.1 - - 1.8 - 1.8 - - - - - - - - diff --git a/repo-management-github-actions-example/maths/src/main/java/com/dineshvelhal/javaprojects/maths/Math.java b/repo-management-github-actions-example/maths/src/main/java/com/dineshvelhal/javaprojects/maths/Math.java deleted file mode 100644 index 023f5f5cd..000000000 --- a/repo-management-github-actions-example/maths/src/main/java/com/dineshvelhal/javaprojects/maths/Math.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.dineshvelhal.javaprojects.maths; - - -/** - * @author Dinesh_Velhal (dinesh.velhal at gmail) - * - * A dummy Math class used for testing the Jenkins pipeline builds. - * - * - */ -public class Math -{ - public int add(int a, int b) { - return a + b + 0 + 0 + 0; - } - - public int subtract(int a, int b) { - return a - b; - } - - public int multiply(int a, int b) { - return a * b; - } - - public int divide(int a, int b) { - return a / b; - } -} diff --git a/repo-management-github-actions-example/maths/src/test/java/com/dineshvelhal/javaprojects/maths/MathTest.java b/repo-management-github-actions-example/maths/src/test/java/com/dineshvelhal/javaprojects/maths/MathTest.java deleted file mode 100644 index 3c4e4f4d1..000000000 --- a/repo-management-github-actions-example/maths/src/test/java/com/dineshvelhal/javaprojects/maths/MathTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * - */ -package com.dineshvelhal.javaprojects.maths; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -/** - * @author Dinesh_Velhal - * - * JUnit Test Cases - created for testing the Jenkins Unit Test step - * - */ -public class MathTest { - Math math; - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - System.out.println("@Before Inside setUp"); - math = new Math(); - } - - /** - * @throws java.lang.Exception - */ - @After - public void tearDown() throws Exception { - System.out.println("@After Inside tearDown\n*********************************"); - math = null; - } - - @Test - public void addTest() { - System.out.println("@Test Inside addTest"); - - assertEquals(5 + 0 + 0, math.add(2, 3)); - } - - @Test - public void subtractTest() { - System.out.println("@Test Inside subtractTest"); - - assertEquals(5, math.subtract(7, 2)); - } - - @Test - public void multiplyTest() { - System.out.println("@Test Inside multiplyTest"); - - assertEquals(15, math.multiply(5, 3)); - } - - @Test - public void divideTest() { - System.out.println("@Test Inside divideTest"); - - assertEquals(5, math.divide(20, 4)); - assertNotEquals(5.5, math.divide(11, 2)); // to check it's integer division - } - -} diff --git a/repo-management-github-actions-example/templates/local-repo-template.json b/repo-management-github-actions-example/templates/local-repo-template.json deleted file mode 100644 index fe1b44bb3..000000000 --- a/repo-management-github-actions-example/templates/local-repo-template.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "key": "auto-cli-local-${key1}", - "packageType": "maven", - "rclass": "local" -} \ No newline at end of file diff --git a/repo-management-github-actions-example/templates/remote-repo-template.json b/repo-management-github-actions-example/templates/remote-repo-template.json deleted file mode 100644 index 6a0d13d8e..000000000 --- a/repo-management-github-actions-example/templates/remote-repo-template.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "key":"auto-cli-central-${key1}", - "packageType":"maven", - "rclass":"remote", - "url":"https://repo1.maven.org/maven2" -} \ No newline at end of file diff --git a/repo-management-github-actions-example/templates/virtual-repo-template.json b/repo-management-github-actions-example/templates/virtual-repo-template.json deleted file mode 100644 index 694587895..000000000 --- a/repo-management-github-actions-example/templates/virtual-repo-template.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "key":"auto-cli-virtual-${key1}", - "packageType":"maven", - "rclass":"virtual", - "repositories":"auto-cli-central-${key1},auto-cli-local-${key1}", - "defaultDeploymentRepo":"auto-cli-local-${key1}" -} - \ No newline at end of file From ab7909383e7716f3bd8739e227aee95a0a26c3fd Mon Sep 17 00:00:00 2001 From: yahavi Date: Sun, 4 Feb 2024 17:15:02 +0200 Subject: [PATCH 2/2] CR --- .../.github/workflows/main.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/github-action-examples/repo-management-github-actions-example/.github/workflows/main.yml b/github-action-examples/repo-management-github-actions-example/.github/workflows/main.yml index e079f964b..623ed4f8c 100644 --- a/github-action-examples/repo-management-github-actions-example/.github/workflows/main.yml +++ b/github-action-examples/repo-management-github-actions-example/.github/workflows/main.yml @@ -50,11 +50,9 @@ jobs: - if: always() name: Feature Branch Repository Update - env: - SERVER_ID: tal-eplus-saas run: | echo "::set-env name=repository::$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//_/g')" - jf mvnc --server-id-resolve=$SERVER_ID --server-id-deploy=$SERVER_ID --repo-resolve-releases=auto-cli-virtual-$repository --repo-resolve-snapshots=auto-cli-virtual-$repository --repo-deploy-releases=auto-cli-virtual-$repository --repo-deploy-snapshots=auto-cli-virtual-$repository + jf mvnc --repo-resolve-releases=auto-cli-virtual-$repository --repo-resolve-snapshots=auto-cli-virtual-$repository --repo-deploy-releases=auto-cli-virtual-$repository --repo-deploy-snapshots=auto-cli-virtual-$repository - if: always() name: Build & Deploy