|
1 | 1 | --- |
| 2 | +name: Build assets for SimpleSAMLphp 2.1 |
2 | 3 |
|
3 | | -name: 'Update of assets' |
4 | | - |
5 | | -on: |
| 4 | +on: # yamllint disable-line rule:truthy |
| 5 | + push: |
| 6 | + branches: ['release-*'] |
| 7 | + pull_request: |
| 8 | + branches: ['*'] |
6 | 9 | workflow_dispatch: |
7 | | - schedule: |
8 | | - # Run every week on Sunday at 00:00 AM UTC |
9 | | - - cron: '0 0 * * 0' |
10 | 10 |
|
11 | 11 | jobs: |
| 12 | + quality: |
| 13 | + name: Quality checks |
| 14 | + runs-on: ['ubuntu-latest'] |
| 15 | + if: ${{ github.event.commits[0].author.name != 'dependabot[bot]' }} |
| 16 | + |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + with: |
| 20 | + token: ${{ secrets.ASSETS_COMMIT_TOKEN }} |
| 21 | + ref: ${{ github.head_ref || github.ref_name }} |
| 22 | + # Full git history is needed to get a proper list of changed files within `super-linter` |
| 23 | + fetch-depth: 0 |
| 24 | + |
| 25 | + - name: Fetch changes |
| 26 | + # Without fetching, we might miss new tags due to caching in Github Actions |
| 27 | + run: git fetch --all |
| 28 | + |
| 29 | + - name: Remove generated files |
| 30 | + # Remove generated files; we can't lint them and we want to detect removed files during build |
| 31 | + run: find css/ js/ -type f -not -name '.gitkeep' -delete |
| 32 | + |
| 33 | + - name: Lint Code Base |
| 34 | + uses: super-linter/super-linter/slim@v7 |
| 35 | + env: |
| 36 | + DEFAULT_BRANCH: ${{ github.head_ref || github.ref_name }} |
| 37 | + # CSS Linter will choke on generated assets |
| 38 | + IGNORE_GENERATED_FILES: true |
| 39 | + FILTER_REGEX_EXCLUDE: '(css|js)/.*' |
| 40 | + # To report GitHub Actions status checks |
| 41 | + SAVE_SUPER_LINTER_OUTPUT: false |
| 42 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 43 | + LINTER_RULES_PATH: 'tools/linters' |
| 44 | + VALIDATE_ALL_CODEBASE: true |
| 45 | + #VALIDATE_CSS: true |
| 46 | + #VALIDATE_JAVASCRIPT_ES: true |
| 47 | + VALIDATE_JSON: true |
| 48 | + VALIDATE_MARKDOWN: true |
| 49 | + VALIDATE_YAML: true |
| 50 | + VALIDATE_GITHUB_ACTIONS: true |
| 51 | + |
| 52 | + - name: Zip artifact for deployment |
| 53 | + run: | |
| 54 | + zip release.zip -r . |
| 55 | +
|
| 56 | + - uses: actions/upload-artifact@v4 |
| 57 | + with: |
| 58 | + name: release |
| 59 | + path: release.zip |
| 60 | + retention-days: 1 |
| 61 | + |
12 | 62 | build: |
13 | | - name: 'Build assets' |
| 63 | + name: Build assets |
| 64 | + runs-on: ['ubuntu-latest'] |
| 65 | + needs: quality |
| 66 | + |
| 67 | + outputs: |
| 68 | + files_changed: ${{ steps.changes.outputs.files_changed }} |
| 69 | + |
| 70 | + steps: |
| 71 | + - uses: actions/setup-node@v4 |
| 72 | + with: |
| 73 | + node-version: 18 |
| 74 | + |
| 75 | + - uses: actions/download-artifact@v4 |
| 76 | + with: |
| 77 | + name: release |
| 78 | + |
| 79 | + - name: unzip artifact for deployment |
| 80 | + run: | |
| 81 | + unzip release.zip |
| 82 | + rm release.zip |
| 83 | +
|
| 84 | + - name: Install & build assets |
| 85 | + run: | |
| 86 | + # Make sure the lock-file is up to date before we run clean-install |
| 87 | + npm install --package-lock-only |
| 88 | + npm clean-install |
| 89 | + npm audit fix |
| 90 | + npx browserslist@latest --update-db |
| 91 | + npm run build |
| 92 | +
|
| 93 | + - name: Fix git safe.directory in container |
| 94 | + run: | |
| 95 | + mkdir -p /home/runner/work/_temp/_github_home |
| 96 | + printf "[safe]\n\tdirectory = /github/workspace" > /home/runner/work/_temp/_github_home/.gitconfig |
| 97 | +
|
| 98 | + - name: Diff the changes after building |
| 99 | + shell: pwsh |
| 100 | + # Give an id to the step, so we can reference it later |
| 101 | + id: changes |
| 102 | + run: | |
| 103 | + git add --all |
| 104 | + $Diff = git diff --cached --name-only |
| 105 | +
|
| 106 | + # Check if a file under css/ or js/ that has changed (added, modified, deleted) |
| 107 | + $SourceDiff = $Diff | Where-Object { |
| 108 | + $_ -match '^css/' -or |
| 109 | + $_ -match '^js/' |
| 110 | + } |
| 111 | + echo "Changed files" |
| 112 | + echo $SourceDiff |
| 113 | +
|
| 114 | + $HasSourceDiff = $SourceDiff.Length -gt 0 |
| 115 | + echo "($($SourceDiff.Length) changes)" |
| 116 | + echo "files_changed=$HasSourceDiff" >> $env:GITHUB_OUTPUT |
| 117 | +
|
| 118 | + - name: Zip artifact for deployment |
| 119 | + if: steps.changes.outputs.files_changed == 'true' || steps.changes.outputs.packages_changed |
| 120 | + run: zip build.zip -r . |
| 121 | + |
| 122 | + - uses: actions/upload-artifact@v4 |
| 123 | + if: steps.changes.outputs.files_changed == 'true' || steps.changes.outputs.packages_changed |
| 124 | + with: |
| 125 | + name: build |
| 126 | + path: build.zip |
| 127 | + retention-days: 1 |
| 128 | + |
| 129 | + version: |
| 130 | + name: Determine next version |
| 131 | + runs-on: ['ubuntu-latest'] |
| 132 | + needs: build |
| 133 | + if: | |
| 134 | + always() && |
| 135 | + needs.build.outputs.files_changed == 'true' && |
| 136 | + (github.event_name == 'push' || github.event_name == 'workflow_dispatch') |
| 137 | +
|
| 138 | + outputs: |
| 139 | + version: ${{ steps.asset_version.outputs.version }} |
| 140 | + |
| 141 | + steps: |
| 142 | + - uses: actions/download-artifact@v4 |
| 143 | + with: |
| 144 | + name: build |
| 145 | + |
| 146 | + - name: unzip artifact for deployment |
| 147 | + run: | |
| 148 | + unzip build.zip |
| 149 | + rm build.zip |
| 150 | +
|
| 151 | + - uses: paulhatch/semantic-version@v5.4.0 |
| 152 | + id: asset_version |
| 153 | + with: |
| 154 | + # The prefix to use to identify tags |
| 155 | + tag_prefix: "v" |
| 156 | + |
| 157 | + # A string which, if present in a git commit, indicates that a change represents a |
| 158 | + # major (breaking) change, supports regular expressions wrapped with '/' |
| 159 | + major_pattern: "(MAJOR)" |
| 160 | + |
| 161 | + # Same as above except indicating a minor change, supports regular expressions wrapped with '/' |
| 162 | + minor_pattern: "(MINOR)" |
| 163 | + |
| 164 | + # A string to determine the format of the version output |
| 165 | + version_format: "${major}.${minor}.${patch}" |
| 166 | + |
| 167 | + # Optional path to check for changes. If any changes are detected in the path the |
| 168 | + # 'changed' output will true. Enter multiple paths separated by spaces. |
| 169 | + change_path: "css/** js/** package.json package-lock.json" |
| 170 | + |
| 171 | + commit: |
| 172 | + name: Commit changes to assets |
| 173 | + needs: version |
14 | 174 | runs-on: [ubuntu-latest] |
15 | 175 |
|
16 | 176 | steps: |
17 | | - - name: 'Run assets build (2.1)' |
18 | | - uses: actions/github-script@v7 |
19 | | - with: |
20 | | - # Token has to be generated on a user account that controls the remote repository. |
21 | | - # The _only_ scope to select is "Access public repositories", nothing more. |
22 | | - github-token: "${{ secrets.PAT_TOKEN }}" |
23 | | - debug: true |
24 | | - script: | |
25 | | - await github.rest.actions.createWorkflowDispatch({ |
26 | | - owner: 'simplesamlphp', |
27 | | - repo: 'simplesamlphp-assets-jquery', |
28 | | - workflow_id: 'build-release.yml', |
29 | | - ref: 'release-2.1' |
30 | | - }) |
31 | | -
|
32 | | - - name: 'Run assets build (2.2)' |
33 | | - uses: actions/github-script@v7 |
34 | | - with: |
35 | | - # Token has to be generated on a user account that controls the remote repository. |
36 | | - # The _only_ scope to select is "Access public repositories", nothing more. |
37 | | - github-token: "${{ secrets.PAT_TOKEN }}" |
38 | | - debug: true |
39 | | - script: | |
40 | | - await github.rest.actions.createWorkflowDispatch({ |
41 | | - owner: 'simplesamlphp', |
42 | | - repo: 'simplesamlphp-assets-jquery', |
43 | | - workflow_id: 'build-release.yml', |
44 | | - ref: 'release-2.2' |
45 | | - }) |
46 | | -
|
47 | | - - name: 'Run assets build (2.3)' |
48 | | - uses: actions/github-script@v7 |
49 | | - with: |
50 | | - # Token has to be generated on a user account that controls the remote repository. |
51 | | - # The _only_ scope to select is "Access public repositories", nothing more. |
52 | | - github-token: "${{ secrets.PAT_TOKEN }}" |
53 | | - debug: true |
54 | | - script: | |
55 | | - await github.rest.actions.createWorkflowDispatch({ |
56 | | - owner: 'simplesamlphp', |
57 | | - repo: 'simplesamlphp-assets-jquery', |
58 | | - workflow_id: 'build-release.yml', |
59 | | - ref: 'release-2.3' |
60 | | - }) |
| 177 | + - uses: actions/download-artifact@v4 |
| 178 | + with: |
| 179 | + name: build |
| 180 | + |
| 181 | + - name: unzip artifact for deployment |
| 182 | + run: | |
| 183 | + unzip build.zip |
| 184 | + rm build.zip |
| 185 | +
|
| 186 | + - name: Add & Commit |
| 187 | + uses: EndBug/add-and-commit@v9 |
| 188 | + with: |
| 189 | + # The arguments for the `git add` command (see the paragraph below for more info) |
| 190 | + # Default: '.' |
| 191 | + add: "['css/*', 'js/*']" |
| 192 | + |
| 193 | + # Determines the way the action fills missing author name and email. Three options are available: |
| 194 | + # - github_actor -> UserName <UserName@users.noreply.github.com> |
| 195 | + # - user_info -> Your Display Name <your-actual@email.com> |
| 196 | + # - github_actions -> github-actions <email associated with the github logo> |
| 197 | + # Default: github_actor |
| 198 | + default_author: github_actions |
| 199 | + |
| 200 | + # The message for the commit. |
| 201 | + # Default: 'Commit from GitHub Actions (name of the workflow)' |
| 202 | + message: "[skip ci] Auto-rebuild assets" |
| 203 | + |
| 204 | + # The way the action should handle pathspec errors from the add and remove commands. |
| 205 | + # Three options are available: |
| 206 | + # - ignore -> errors will be logged but the step won't fail |
| 207 | + # - exitImmediately -> the action will stop right away, and the step will fail |
| 208 | + # - exitAtEnd -> the action will go on, every pathspec error will be logged at the end, the step will fail. |
| 209 | + # Default: ignore |
| 210 | + pathspec_error_handling: exitImmediately |
| 211 | + |
| 212 | + # Arguments for the git tag command (the tag name always needs to be the first word not preceded by an hyphen) |
| 213 | + # Default: '' |
| 214 | + tag: "v${{ needs.version.outputs.version }}" |
| 215 | + |
| 216 | + cleanup: |
| 217 | + name: Cleanup artifacts |
| 218 | + needs: [build, commit] |
| 219 | + runs-on: [ubuntu-latest] |
| 220 | + if: | |
| 221 | + always() && |
| 222 | + needs.commit.result == 'success' || |
| 223 | + (needs.build.result == 'success' && needs.commit.result == 'skipped') |
| 224 | +
|
| 225 | + steps: |
| 226 | + - uses: geekyeggo/delete-artifact@v5 |
| 227 | + with: |
| 228 | + name: | |
| 229 | + release |
| 230 | + build |
0 commit comments