Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(icons): Generate and deploy to the CDN the main sprite and the list of icons contained in a fixed path #3705

Closed
wants to merge 9 commits into from
65 changes: 65 additions & 0 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,47 @@ on:
- '!*'
tags:
- 'v*'

jobs:
deploy-release:
runs-on: ubuntu-latest
name: build and deploy the release

steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 20.9.0

- name: Get tag
id: tag
uses: dawidd6/action-get-tag@v1

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Build presets
run: yarn dist:presets

- name: Generate sri file
run: node scripts/sri.js ${{ steps.tag.outputs.tag }}

- name: Browserstats
run: npm run browserstats

- name: Build storybook
run: PUBLIC_URL=/component-library yarn dist:storybook

- name: Build website
run: PUBLIC_URL=/component-library yarn dist:website

- name: Set version
run: echo ${{ steps.tag.outputs.tag }} > dist/website/.version

- name: Set commit
run: echo ${{ github.sha }} > dist/website/.commit

- name: Deploy to cdn
uses: keithweaver/[email protected]
with:
Expand All @@ -44,36 +57,88 @@ jobs:
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws_region: ${{ secrets.AWS_DEFAULT_REGION }}
flags: --recursive

- name: Get Latest Release
id: get_latest
uses: joutvhu/get-release@v1
with:
latest: true
pattern: '^v*'
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Check if this release is the latest
id: check_latest
run: |
# Get the latest release tag from the get latest release step
LATEST_TAG="${{ steps.get_latest.outputs.tag_name }}"
CURRENT_TAG="${{ steps.tag.outputs.tag }}"

echo "Latest Tag: $LATEST_TAG"
echo "Current Tag: $CURRENT_TAG"

if [[ "$LATEST_TAG" == "$CURRENT_TAG" ]]; then
echo "This is the latest release. Deploying to CDN."
echo "deploy=true" >> $GITHUB_ENV
else
echo "This is not the latest release. Not uploading the sprite file."
echo "deploy=false" >> $GITHUB_ENV
fi

- name: Deploy to CDN the unversioned files
if: env.deploy == 'true'
uses: keithweaver/[email protected]
with:
command: cp
source: ./dist/unversioned
destination: s3://inno-ecl/ecl/unversioned
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws_region: ${{ secrets.AWS_DEFAULT_REGION }}
flags: --recursive

- name: Install zip
uses: montudor/action-zip@v1

- name: Create the package
run: zip -r -qq europa-component-library-${{ steps.tag.outputs.tag }}.zip .
working-directory: dist/website

- name: Create the EC preset package
run: zip -r -qq ec-preset-${{ steps.tag.outputs.tag }}.zip .
working-directory: dist/packages/ec

- name: Create the EU preset package
run: zip -r -qq eu-preset-${{ steps.tag.outputs.tag }}.zip .
working-directory: dist/packages/eu

- name: Create the list of packages
run: sh ./scripts/packagesList.sh

- name: Deploy packages to github
uses: AButler/[email protected]
with:
files: 'dist/website/europa-component-library-*.zip;dist/packages/europa-component-library-*-sri.json;dist/packages/ec/*.zip;dist/packages/eu/*.zip;ECL-npm-packages'
repo-token: ${{ secrets.GITHUB_TOKEN }}
release-tag: ${{ steps.tag.outputs.tag }}

- name: Build the archive
run: PUBLIC_URL=/component-library/${{ steps.tag.outputs.tag }} yarn dist

- name: Set version
run: echo ${{ steps.tag.outputs.tag }} > dist/website/.version

- name: Set commit
run: echo ${{ github.sha }} > dist/website/.commit

- name: Install zip
uses: montudor/action-zip@v1

- name: Create the package for the archive
run: zip -r -qq europa-component-library-${{ steps.tag.outputs.tag }}-archive.zip .
working-directory: dist/website

- name: Deploy archive to github
uses: AButler/[email protected]
with:
Expand Down
2 changes: 2 additions & 0 deletions scripts/dist-presets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ cd ..
# Copy builds
rm -rf ./dist/packages
mkdir -p ./dist/packages
mkdir -p ./dist/unversioned
mv ./src/presets/ec/dist/images/icons/unversioned/* ./dist/unversioned
cp -r ./src/presets/ec/dist ./dist/packages/ec
cp -r ./src/presets/reset/dist/styles ./dist/packages/ec
cp -r ./src/presets/rtl/dist/styles ./dist/packages/ec
Expand Down
22 changes: 4 additions & 18 deletions src/resources/icons/scripts/build-lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const glob = require('glob');

const writeList = require('./write-list');

const src = path.resolve(__dirname, '../src');
const dest = path.resolve(__dirname, '../dist/lists');
const src = path.resolve(__dirname, '../src/all');
let dest = path.resolve(__dirname, '../dist/lists');

const files = glob
.sync('**/*.svg', { cwd: src })
Expand All @@ -15,19 +15,5 @@ const files = glob

writeList({ dest, files, outputFile: 'all.json' });

/* Write lists of icons per set */

const filesBySet = {};
files.forEach((file) => {
const [set, filename] = file.split('/');
if (!filesBySet[set]) filesBySet[set] = [];
filesBySet[set].push(filename);
});

Object.keys(filesBySet).forEach((set) => {
writeList({
dest,
files: filesBySet[set],
outputFile: `${set}.json`,
});
});
dest = path.resolve(__dirname, '../dist/unversioned');
writeList({ dest, files, outputFile: 'icons-current.json' });
6 changes: 4 additions & 2 deletions src/resources/icons/scripts/build-sprites.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ const glob = require('glob');
const writeSprite = require('./write-sprite');

const src = path.resolve(__dirname, '../dist/svg');
const dest = path.resolve(__dirname, '../dist/sprites');
let dest = path.resolve(__dirname, '../dist/sprites');
const files = glob
.sync('**/*.svg', { cwd: src })
.sort((a, b) => a.localeCompare(b, 'en'));

/* Generate 1 sprite with all icons and organize icons per folder */

writeSprite({ files, cwd: src, dest, outputFile: `icons.svg` });
/* Generate 1 sprite in the unversioned folder */
dest = path.resolve(__dirname, '../dist/unversioned');
writeSprite({ files, cwd: src, dest, outputFile: `icons-current.svg` });
Loading