From 2cb0633b883c90681c9c0738b21ba4c81aa25bb1 Mon Sep 17 00:00:00 2001 From: Luke Walton Date: Wed, 23 Oct 2024 11:11:06 +0100 Subject: [PATCH] ci: Add comment showing lastUpdated time for icons (#48) --- .github/fetch_icons/action.yml | 3 +++ .github/fetch_icons/index.js | 4 ++++ .github/workflows/build.yml | 8 ++++---- .github/workflows/on-main.yml | 20 ++++++++++++++++++++ .github/workflows/on-pr.yml | 24 ++++++++++++++++++++++++ package.json | 3 ++- 6 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/on-main.yml diff --git a/.github/fetch_icons/action.yml b/.github/fetch_icons/action.yml index 1e4788f0..feff5b20 100644 --- a/.github/fetch_icons/action.yml +++ b/.github/fetch_icons/action.yml @@ -4,6 +4,9 @@ inputs: figma-access-token: description: "The personal access token given by Figma. Required to make API calls" required: true + date: + description: "The date and time the action was run" + required: true outputs: files_changed: description: "Boolean that gets set to true if any icons have been added or removed" diff --git a/.github/fetch_icons/index.js b/.github/fetch_icons/index.js index 1906ec90..961b8630 100644 --- a/.github/fetch_icons/index.js +++ b/.github/fetch_icons/index.js @@ -4,6 +4,7 @@ import fetchIcons from "../../dist/scripts/fetch-icons/fetchIcons.js"; import { ZDS_ASSETS_FILE_ID, ZDS_ASSETS_ICON_PAGE_NAME } from "../../figmaConfig.js"; const FIGMA_ACCESS_TOKEN = core.getInput("figma-access-token") || process.env.FIGMA_ACCESS_TOKEN; +const DATE = core.getInput("date") || 'now'; try { const hashPath = "./.github/fetch_icons/hash.txt"; @@ -26,6 +27,9 @@ try { if (newHash) { writeFileSync(hashPath, newHash); + const packageJson = JSON.parse(readFileSync("./package.json").toString()); + packageJson.lastUpdated = DATE; + writeFileSync("./package.json", JSON.stringify(packageJson, null, 2)); } console.log("Files changed", newHash); core.setOutput("files_changed", newHash != undefined); diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3613315a..fc3799bf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -39,20 +39,20 @@ jobs: if: ${{github.event_name != 'schedule'}} run: | : > ./.github/fetch_icons/hash.txt + - name: Get date / time + id: date + run: echo date=$(date +'%d %b %Y, %H:%M:%S') >> $GITHUB_OUTPUT - name: Fetch icons id: "fetch_icons" uses: ./.github/fetch_icons with: figma-access-token: ${{ secrets.FIGMA_PERSONAL_ACCESS_TOKEN }} + date: ${{ steps.date.outputs.date }} - name: Icons changed run: echo ${{ steps.fetch_icons.outputs.files_changed }} - name: Create code connect files if: ${{ steps.fetch_icons.outputs.files_changed == 'true'}} uses: ./.github/create_code_connect - - name: Get current date - if: ${{ steps.fetch_icons.outputs.files_changed == 'true'}} - id: date - run: echo date=$(date +'%d-%b-%Y') >> $GITHUB_OUTPUT - name: Create PR title id: title run: | diff --git a/.github/workflows/on-main.yml b/.github/workflows/on-main.yml new file mode 100644 index 00000000..cd64dd5b --- /dev/null +++ b/.github/workflows/on-main.yml @@ -0,0 +1,20 @@ +name: CI - On Main + +on: + push: + branches: + - main + +permissions: + contents: write + pull-requests: write + +jobs: + release-please: + runs-on: ubuntu-latest + steps: + - uses: googleapis/release-please-action@v4 + with: + token: ${{ secrets.PAT }} + config-file: release-please-config.json + manifest-file: .release-please-manifest.json diff --git a/.github/workflows/on-pr.yml b/.github/workflows/on-pr.yml index 96a5ab2b..d67002f4 100644 --- a/.github/workflows/on-pr.yml +++ b/.github/workflows/on-pr.yml @@ -2,6 +2,11 @@ name: CI - Pull Request on: pull_request +# Pull Request Runs on the same branch will be cancelled +concurrency: + group: ${{ github.head_ref }} + cancel-in-progress: true + env: FIGMA_ACCESS_TOKEN: ${{secrets.FIGMA_PERSONAL_ACCESS_TOKEN}} @@ -22,3 +27,22 @@ jobs: run: npm ci - name: Run tests run: npm run test + + release-comment: + name: Release Comment + runs-on: ubuntu-latest + if: ${{ contains(github.event.pull_request.title, 'release zeta-icons')}} + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Get lastUpdated + id: lastUpdated + run: echo "lastUpdated=$(cat package.json | jq .lastUpdated)" >> $GITHUB_OUTPUT + - name: Comment + uses: mikedloss/create-update-comment@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + unique-identifier: "lastUpdated comment" + message: | + ### PR is ready to merge. + Last updated: ${{ steps.lastUpdated.outputs.lastUpdated }} diff --git a/package.json b/package.json index b3f04073..80cf7baf 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "@zebra-fed/zeta-icons", "version": "0.8.1", "type": "module", + "lastUpdated": "18 Oct 2024, 15:25:00", "main": "index.js", "types": "dist/index.d.ts", "files": [ @@ -74,4 +75,4 @@ "url": "https://github.com/zebratechnologies/zeta-icons/issues" }, "homepage": "https://github.com/zebratechnologies/zeta-icons#readme" -} +} \ No newline at end of file