Skip to content

Commit

Permalink
Adding CI (#6)
Browse files Browse the repository at this point in the history
* Adding CI

* Fix typo

* Fix targets

* Removing registry part
  • Loading branch information
TonioGela authored Nov 23, 2022
1 parent dec9f51 commit 737876b
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 28 deletions.
145 changes: 145 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# This file was automatically generated by sbt-github-actions using the
# githubWorkflowGenerate task. You should add and commit this file to
# your git repository. It goes without saying that you shouldn't edit
# this file by hand! Instead, if you wish to make changes, you should
# change your sbt build configuration to revise the workflow description
# to meet your needs, then regenerate this file.

name: Continuous Integration

on:
push:
branches: ['**']
tags: ['**']

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
build:
name: Build and Test
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.10]
java: [temurin@11]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup Java (temurin@11)
if: matrix.java == 'temurin@11'
uses: actions/setup-java@v2
with:
distribution: temurin
java-version: 11

- name: Cache sbt
uses: actions/cache@v2
with:
path: |
~/.sbt
~/.ivy2/cache
~/.coursier/cache/v1
~/.cache/coursier/v1
~/AppData/Local/Coursier/Cache/v1
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Install node 16
uses: actions/setup-node@v3
with:
node-version: 16

- name: Installing openapi-generator-cli
run: npm install -g @openapitools/openapi-generator-cli

- name: Build project
run: sbt ++${{ matrix.scala }} test

- name: Compress target directories
run: tar cf targets.tar party-process-client/target party-management-client/target user-registry-client/target project/target

- name: Upload target directories
uses: actions/upload-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.scala }}-${{ matrix.java }}
path: targets.tar

publish:
name: Publish Artifacts
needs: [build]
permissions:
contents: read
packages: write
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/1.0.x' || startsWith(github.ref, 'refs/tags/'))
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.10]
java: [temurin@11]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup Java (temurin@11)
if: matrix.java == 'temurin@11'
uses: actions/setup-java@v2
with:
distribution: temurin
java-version: 11

- name: Cache sbt
uses: actions/cache@v2
with:
path: |
~/.sbt
~/.ivy2/cache
~/.coursier/cache/v1
~/.cache/coursier/v1
~/AppData/Local/Coursier/Cache/v1
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Download target directories (2.13.10)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-2.13.10-${{ matrix.java }}

- name: Inflate target directories (2.13.10)
run: |
tar xf targets.tar
rm targets.tar
- name: Install node 16
uses: actions/setup-node@v3
with:
node-version: 16

- name: Installing openapi-generator-cli
run: npm install -g @openapitools/openapi-generator-cli

- name: Get 1.0.x-SNAPSHOTS versionIds
id: version
if: github.ref == 'refs/heads/1.0.x'
uses: castlabs/[email protected]
with:
version: 1.0.x-SNAPSHOT

- name: Deleting 1.0.x-SNAPSHOTS versions
if: ${{ github.ref == 'refs/heads/1.0.x' && steps.version.outputs.ids != '' }}
uses: actions/delete-package-versions@v2
with:
package-version-ids: ${{ steps.version.outputs.ids }}

- name: Regenerating code
run: sbt ++${{ matrix.scala }} generateCode

- name: Publish project
run: sbt ++${{ matrix.scala }} +publish
59 changes: 59 additions & 0 deletions .github/workflows/clean.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# This file was automatically generated by sbt-github-actions using the
# githubWorkflowGenerate task. You should add and commit this file to
# your git repository. It goes without saying that you shouldn't edit
# this file by hand! Instead, if you wish to make changes, you should
# change your sbt build configuration to revise the workflow description
# to meet your needs, then regenerate this file.

name: Clean

on: push

jobs:
delete-artifacts:
name: Delete Artifacts
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Delete artifacts
run: |
# Customize those three lines with your repository and credentials:
REPO=${GITHUB_API_URL}/repos/${{ github.repository }}
# A shortcut to call GitHub API.
ghapi() { curl --silent --location --user _:$GITHUB_TOKEN "$@"; }
# A temporary file which receives HTTP response headers.
TMPFILE=/tmp/tmp.$$
# An associative array, key: artifact name, value: number of artifacts of that name.
declare -A ARTCOUNT
# Process all artifacts on this repository, loop on returned "pages".
URL=$REPO/actions/artifacts
while [[ -n "$URL" ]]; do
# Get current page, get response headers in a temporary file.
JSON=$(ghapi --dump-header $TMPFILE "$URL")
# Get URL of next page. Will be empty if we are at the last page.
URL=$(grep '^Link:' "$TMPFILE" | tr ',' '\n' | grep 'rel="next"' | head -1 | sed -e 's/.*<//' -e 's/>.*//')
rm -f $TMPFILE
# Number of artifacts on this page:
COUNT=$(( $(jq <<<$JSON -r '.artifacts | length') ))
# Loop on all artifacts on this page.
for ((i=0; $i < $COUNT; i++)); do
# Get name of artifact and count instances of this name.
name=$(jq <<<$JSON -r ".artifacts[$i].name?")
ARTCOUNT[$name]=$(( $(( ${ARTCOUNT[$name]} )) + 1))
id=$(jq <<<$JSON -r ".artifacts[$i].id?")
size=$(( $(jq <<<$JSON -r ".artifacts[$i].size_in_bytes?") ))
printf "Deleting '%s' #%d, %'d bytes\n" $name ${ARTCOUNT[$name]} $size
ghapi -X DELETE $REPO/actions/artifacts/$id
done
done
34 changes: 6 additions & 28 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ ThisBuild / scalaVersion := "2.13.10"
ThisBuild / organization := "it.pagopa"
ThisBuild / organizationName := "Pagopa S.p.A."
ThisBuild / version := ComputeVersion.version

ThisBuild / resolvers += "Pagopa Nexus Snapshots" at s"https://${System.getenv("MAVEN_REPO")}/nexus/repository/maven-snapshots/"
ThisBuild / resolvers += "Pagopa Nexus Releases" at s"https://${System.getenv("MAVEN_REPO")}/nexus/repository/maven-releases/"
ThisBuild / credentials += Credentials(Path.userHome / ".sbt" / ".credentials")
ThisBuild / githubOwner := "pagopa"
ThisBuild / githubRepository := "interop-selfcare-proxy-clients"
ThisBuild / resolvers += Resolver.githubPackages("pagopa")

val generateCode = taskKey[Unit]("A task for generating the code starting from the swagger definition")
val packagePrefix = settingKey[String]("The package prefix derived from the uservice name")
Expand Down Expand Up @@ -48,14 +47,7 @@ lazy val partyProcessClient = project
},
scalacOptions := Seq(),
libraryDependencies := Dependencies.Jars.client,
updateOptions := updateOptions.value.withGigahorse(false),
publishTo := {
val nexus = s"https://${System.getenv("MAVEN_REPO")}/nexus/repository/"
if (isSnapshot.value)
Some("snapshots" at nexus + "maven-snapshots/")
else
Some("releases" at nexus + "maven-releases/")
}
updateOptions := updateOptions.value.withGigahorse(false)
)

cleanFiles += baseDirectory.value / "party-management-client" / "src"
Expand Down Expand Up @@ -87,14 +79,7 @@ lazy val partyManagementClient = project
},
scalacOptions := Seq(),
libraryDependencies := Dependencies.Jars.client,
updateOptions := updateOptions.value.withGigahorse(false),
publishTo := {
val nexus = s"https://${System.getenv("MAVEN_REPO")}/nexus/repository/"
if (isSnapshot.value)
Some("snapshots" at nexus + "maven-snapshots/")
else
Some("releases" at nexus + "maven-releases/")
}
updateOptions := updateOptions.value.withGigahorse(false)
)

cleanFiles += baseDirectory.value / "user-registry-client" / "src"
Expand Down Expand Up @@ -126,14 +111,7 @@ lazy val userRegistryClient = project
},
scalacOptions := Seq(),
libraryDependencies := Dependencies.Jars.client,
updateOptions := updateOptions.value.withGigahorse(false),
publishTo := {
val nexus = s"https://${System.getenv("MAVEN_REPO")}/nexus/repository/"
if (isSnapshot.value)
Some("snapshots" at nexus + "maven-snapshots/")
else
Some("releases" at nexus + "maven-releases/")
}
updateOptions := updateOptions.value.withGigahorse(false)
)

(Compile / compile) := ((Compile / compile) dependsOn partyProcessClient / generateCode).value
Expand Down
4 changes: 4 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.2.2")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")

addSbtPlugin("com.lightbend.sbt" % "sbt-javaagent" % "0.1.6")

addSbtPlugin("com.codecommit" % "sbt-github-packages" % "0.5.3")

ThisBuild / libraryDependencySchemes ++= Seq("org.scala-lang.modules" %% "scala-xml" % VersionScheme.Always)

0 comments on commit 737876b

Please sign in to comment.