Installing Sitecore Content Serialization package from a NuGet package using GitHub Packages, with the power of SITECORE CLI and GITHUB ACTIONS

Fellow developers and Sitecore lovers, summer is here! I hope you are enjoying your vacation! Here in Elounda(Crete), the weather(and view) is fantastic. If you have never been to Crete, I strongly recommend you to go there! Just look at the view:

In my previous post, Use Github Packages for storing Sitecore content as a nuget package, with the power of SITECORE CLI and GITHUB ACTIONS, we created a NuGet package containing an SCS package and stored it in GitHub Packages.

In today’s post, we will install the Sitecore Content Serialization package from the “created” NuGet package using GitHub Packages, with the power of SITECORE CLI and GITHUB ACTIONS.

Github Packages is great, it allows you to store all kinds of “package” types – Including NuGet packages 😉. We will grab a NuGet package containing an SCS package(Sitecore Content Serialization package).

GitHub Packages is a platform for hosting and managing packages, including containers and other dependencies. GitHub Packages combines your source code and packages in one place to provide integrated permissions management and billing, so you can centralize your software development on GitHub.

The powerful SITECORE CLI, Sitecore Command Line Interface, is a great command tool that allows you to administer your Sitecore items. We will use it to install an SCS package – Sitecore Content Serialization package to a Sitecore instance.

Sitecore Content Serialization (SCS) packages (file extension .itempackage) contain specified modules and all their serialized items. You use packages as build artifacts in your continuous integration pipeline by creating them in your build pipeline and installing them in your delivery pipeline.

The orchestrator behind it all will be the wonderful and powerful – GitHub Actions.

GitHub Actions makes it easy to automate all your software workflows, now with world-class CI/CD. Build, test, and deploy your code right from GitHub. Make code reviews, branch management, and issue triaging work the way you want.

Ok friends, let’s begin!

First up is to set up the workflow in GitHub Actions. We will create a workflow file and put it in .github/workflows, let’s call it DeployContentPackage.yml. We want to run it manually, so we will go for the “workflow_dispatch”

name: Deploy content package to CM

on:
  workflow_dispatch:

jobs:

Instead of having one big job, we will split the workflow into smaller jobs:
– Install NuGet package
– Deploy SCS package

The first job – Install NuGet package

The job will check out the repo code and install a NuGet package from Github packages.

install-nuget:
  name: Install NuGet package  
  runs-on: self-hosted

  steps:
  - name: Checkout
	uses: actions/checkout@v2

  
  - name : Install NuGet package   
	shell: powershell
	run: |
			Invoke-Expression "./BackupContent/nuget.exe install SandboxSiteContent -Source https://nuget.pkg.github.com/VisionsInCode/Index.json -OutputDirectory BackupContent -x"

Let me break it down for you:

install-nuget:
  name: Install NuGet package  
  runs-on: self-hosted

  steps:

Here we set the job, and instruct it to use the self-hosted runner(which we created in the previous post).

  - name: Checkout
	uses: actions/checkout@v2

This step checks out the repo code

  - name : Install NuGet package
	shell: powershell
	run: |
			Invoke-Expression "./BackupContent/nuget.exe install SandboxSiteContent -Source https://nuget.pkg.github.com/VisionsInCode/Index.json -OutputDirectory BackupContent -x"


Here we install the NuGet package, it will be installed in the folder BackupContent. And the parameter -x installs the package with the name SandboxSiteContent only(no version):


No need to unpack and so on, look at the lovely SCS package – SandboxSite.itempackage. Ready to be installed to our Sitecore instance 😀

The final job – Deploy SCS package

Here we recreate the module.json file(it’s needed when installing the SCS package), login to the Sitecore site, and finally, deploy(install) the Sitecore Content Serialization package.

deploy-scs-package:
  needs: install-nuget
  name: Deploy SCS package  
  runs-on: self-hosted

  steps:

  - name : Create module.json file
	id: create-json-module
	uses: jsdaniell/create-json@1.1.2
	with:
	  name: 'Content.module.json'
	  dir: 'VisionsInCode.Sitecore/src/Project/SandboxSite/'
	  json: '{"namespace": "Project.Content", "items":{"includes":[{"name":"Images","path":"/sitecore/media library/Project/VisionsInCode/Sites/SandboxSite","database": "master"},{"name": "Content","path": "/sitecore/content/VisionsInCode/Sites/SandboxSite","database": "master"}]}}'

  - name : Deploy SCS package to CM   
	shell: powershell
	run: |
			# Add nuget source & install Sitecore CLI
			dotnet nuget add source https://sitecore.myget.org/F/sc-packages/api/v3/index.json --name "Sitecore-Public-Nuget-Feed"
			dotnet tool install --add-source=https://sitecore.myget.org/F/sc-packages/api/v3/index.json --version 2.0.0 sitecore.cli --local
			
			# Login to ID Server
			dotnet sitecore login --client-credentials true --auth https://id.visionsincode.localhost/ --cm https://cm.visionsincode.localhost/ --allow-write true --client-id "SANDBOXSITE_Automation" --client-secret "my_secret_garden"
			

			# Install package
			dotnet sitecore ser package install --package BackupContent/SandboxSiteContent/Sitecore/SandboxSite.itempackage --cm https://cm.visionsincode.localhost/ --client-id "SANDBOXSITE_Automation" --client-secret "my_secret_garden" -i Project.Content

Let me break it down for you:

deploy-scs-package:
  needs: install-nuget
  name: Deploy SCS package  
  runs-on: self-hosted
  
  steps:

Create the job and instruct it to use the self-hosted runner. For the job to work, the previous job needs to be executed. Using “needs” will tell what job it depends on(install-nuget).

  - name : Create module.json file
	id: create-json-module
	uses: jsdaniell/create-json@1.1.2
	with:
	  name: 'Content.module.json'
	  dir: 'VisionsInCode.Sitecore/src/Project/SandboxSite/'
	  json: '{"namespace": "Project.Content", "items":{"includes":[{"name":"Images","path":"/sitecore/media library/Project/VisionsInCode/Sites/SandboxSite","database": "master"},{"name": "Content","path": "/sitecore/content/VisionsInCode/Sites/SandboxSite","database": "master"}]}}'

The next step will be to re-create the module.json file. (We don’t want it to be included in the Github repo, instead, we are creating it on the fly) The file will contain the paths to the content, which is needed for the next step.

  - name : Deploy SCS package to CM   
	shell: powershell
	run: |
			# Add nuget source & install Sitecore CLI
			dotnet nuget add source https://sitecore.myget.org/F/sc-packages/api/v3/index.json --name "Sitecore-Public-Nuget-Feed"
			dotnet tool install --add-source=https://sitecore.myget.org/F/sc-packages/api/v3/index.json --version 2.0.0 sitecore.cli --local
			
			# Login to ID Server
			dotnet sitecore login --client-credentials true --auth https://id.visionsincode.localhost/ --cm https://cm.visionsincode.localhost/ --allow-write true --client-id "SANDBOXSITE_Automation" --client-secret "my_secret_garden"
			

			# Install package
			dotnet sitecore ser package install --package BackupContent/SandboxSiteContent/Sitecore/SandboxSite.itempackage --cm https://cm.visionsincode.localhost/ --client-id "SANDBOXSITE_Automation" --client-secret "my_secret_garden" -i Project.Content

The last step will install/deploy the Sitecore Content Serialization package to the Sitecore site:
1. First, we install Sitecore CLI, the command tool which allows us to administer Sitecore content(items).
2. But before the job can start deploying content, it needs to login – the non-interactive client login(we set up in the previous post).
3. The last part will be to install/deploy the Sitecore Content Serialization package – SandboxSite.itempackage , following “instructions” from the created module.json file (-i Project.Content).


Working with SCS package is great, it’s really powerful and I really recommend that you guys start using it. Here is some great documentation, read all about it:
https://doc.sitecore.com/en/developers/101/developer-tools/create-and-install-a-sitecore-content-serialization-package.html

And here is some great documentation on how to create NuGet packages:
https://doc.sitecore.com/en/developers/101/developer-tools/walkthrough–serializing-with-nuget-and-npm.html

That’s all for now folks 😀




Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.