.github/workflows/legacy-release_sbom-generator.yaml #17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Generate SBOM for latest version of dotCMS and put into core-test-repo | |
on: | |
release: | |
types: [published] | |
workflow_dispatch: | |
inputs: | |
dotcms_version: | |
description: 'Enter the dotCMS version (vYY.MM.DD)' | |
required: true | |
default: '' | |
jobs: | |
scan: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write # Ensure write access to contents | |
steps: | |
- name: Checkout core repository | |
uses: actions/checkout@v3 | |
with: | |
repository: dotCMS/core | |
token: ${{ secrets.GITHUB_TOKEN }} | |
path: core | |
- name: Get dotCMS release version | |
id: get_version | |
run: | | |
if [ "${{ github.event_name }}" == "release" ]; then | |
# Extract the tag name from the release event context | |
latest_tag=${{ github.event.release.tag_name }} | |
else | |
# Use the input provided in manual run | |
latest_tag=${{ github.event.inputs.dotcms_version }} | |
fi | |
# Format the tag name if necessary | |
formatted_tag=$(echo "$latest_tag" | sed -e 's/^dotcms-cli-//' -e 's/^v//') | |
# Construct the branch name based on the version | |
branch_name="release-v${formatted_tag}_lts" | |
echo "DOTCMS_VERSION=${latest_tag}" >> $GITHUB_ENV | |
echo "BRANCH_NAME=${branch_name}" >> $GITHUB_ENV | |
- name: Print environment variables | |
run: | | |
echo "DOTCMS_VERSION=${{ env.DOTCMS_VERSION }}" | |
echo "BRANCH_NAME=${{ env.BRANCH_NAME }}" | |
- name: Pull and run dotCMS Docker image | |
run: | | |
if [ -z "${{ env.DOTCMS_VERSION }}" ]; then | |
echo "Error: DOTCMS_VERSION is not set" | |
exit 1 | |
fi | |
docker pull dotcms/dotcms:${{ env.DOTCMS_VERSION }} | |
docker run -d -p 8082:8082 dotcms/dotcms:${{ env.DOTCMS_VERSION }} | |
- name: Install pipx | |
run: | | |
pip install pipx | |
- name: Create SBOM folder | |
run: | | |
mkdir -p core/sbom | |
- name: Scan Docker Image with Syft | |
run: | | |
pipx run anchore_syft dotcms/dotcms:${{ env.DOTCMS_VERSION }} -o cyclonedx-xml > core/sbom/cyclonedx.json | |
- name: Rename SBOM file with dotCMS version | |
run: | | |
mv core/sbom/cyclonedx.json core/sbom/dotcms-${{ env.DOTCMS_VERSION }}.json | |
- name: Configure Git | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "Github Actions" | |
- name: Check out the target branch | |
run: | | |
cd core | |
# Fetch and check out the branch | |
git fetch origin | |
git checkout ${{ env.BRANCH_NAME }} | |
- name: Commit and push results to target branch | |
run: | | |
cd core | |
git add sbom/dotcms-${{ env.DOTCMS_VERSION }}.json | |
git commit -m "Add SBOM for dotCMS version ${{ env.DOTCMS_VERSION }}" || echo "No changes to commit" | |
git push origin ${{ env.BRANCH_NAME }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |