Skip to content

Commit

Permalink
Merge pull request #200 from Shopify/cleanup-gh-actions
Browse files Browse the repository at this point in the history
Tidying up our Actions
  • Loading branch information
elsom25 authored May 30, 2024
2 parents fa50260 + 84b20f0 commit 3686a83
Show file tree
Hide file tree
Showing 16 changed files with 263 additions and 376 deletions.
47 changes: 13 additions & 34 deletions .github/workflows/deploy_github_pages.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Deploy GitHub page
name: Deploy docs site

on:
workflow_dispatch:
push:
branches:
- main
workflow_dispatch:

permissions:
contents: read
Expand All @@ -19,25 +19,15 @@ jobs:
generate_docs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1

- name: Install Cue
uses: cue-lang/[email protected]
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- uses: cue-lang/[email protected]
with:
version: 'v0.7.0'

- name: Install bundler and gems
run: |
gem install bundler
bundle install --jobs 4 --retry 3
- name: Generate dist & docs
run: make VERBOSE=1

- name: Upload data
uses: actions/upload-artifact@v4
with:
Expand All @@ -48,29 +38,19 @@ jobs:
runs-on: ubuntu-latest
needs: generate_docs
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download data
uses: actions/download-artifact@v4
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: data
path: docs/_data

- name: Setup Pages
uses: actions/configure-pages@v4

- name: Build with Jekyll
uses: actions/jekyll-build-pages@v1
- uses: actions/configure-pages@v4
- uses: actions/jekyll-build-pages@v1
with:
source: docs
destination: _site

- name: Copy search indexes
run: sudo bin/copy_docs_search_indexes

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
- uses: actions/upload-pages-artifact@v3

deploy:
environment:
Expand All @@ -79,6 +59,5 @@ jobs:
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
- uses: actions/deploy-pages@v4
id: deployment
uses: actions/deploy-pages@v4
23 changes: 6 additions & 17 deletions .github/workflows/ensure_dist_committed.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Ensure distribution files committed are up-to-date

on:
workflow_dispatch:
pull_request:
branches:
- main
workflow_dispatch:

permissions:
issues: write
Expand All @@ -13,30 +13,19 @@ jobs:
ensure_dist_committed:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1

- name: Install Cue
uses: cue-lang/[email protected]
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- uses: cue-lang/[email protected]
with:
version: 'v0.7.0'

- name: Install bundler and gems
run: |
gem install bundler
bundle install --jobs 4 --retry 3
- name: Generate distribution files
run: make VERBOSE=1

- name: Ensure there are no uncommitted distrubtion file changes
id: ensure-dist-committed
run: |
git diff --exit-code || (echo "Please commit the changes made by the build process" && exit 1)
- name: Inform PR author of failure and path to fix
if: ${{ failure() && steps.ensure-dist-committed.outcome == 'failure' }}
run: |
Expand Down
25 changes: 7 additions & 18 deletions .github/workflows/generate_dist.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Generate and commit distribution files
name: Generate and commit distribution files to requested PR

on:
workflow_dispatch:
issue_comment:
types: [created, edited]
workflow_dispatch:

concurrency:
group: "dist"
Expand All @@ -17,31 +17,20 @@ jobs:
runs-on: ubuntu-latest
if: ${{ github.event.issue.pull_request && github.event.comment.body == '/generate_dist' }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- uses: actions/checkout@v4
- name: Checkout PR
run: gh pr checkout $ISSUE
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE: ${{ github.event.issue.html_url }}

- name: Set up Ruby
uses: ruby/setup-ruby@v1

- name: Install Cue
uses: cue-lang/[email protected]
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- uses: cue-lang/[email protected]
with:
version: 'v0.7.0'

- name: Install bundler and gems
run: |
gem install bundler
bundle install --jobs 4 --retry 3
- name: Generate distribution files
run: make VERBOSE=1

- name: Commit distribution files
run: |
git config --local user.name "GitHub Action"
Expand Down
82 changes: 82 additions & 0 deletions .github/workflows/generate_dist_locales.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Generate distribution files for all locales

on:
workflow_dispatch:
push:
branches:
- main

concurrency:
group: "full_dist"
cancel-in-progress: true

permissions:
contents: write
pull-requests: write

jobs:
generate_locales:
runs-on: ubuntu-latest
outputs:
LOCALES: ${{ steps.retrieve_locales.outputs.locales }}
steps:
- uses: actions/checkout@v4
- name: Retrieve Locales
id: retrieve_locales
run: |
locales=$(ls data/localizations/categories/ | grep -Eo '^[a-z]{2,3}(-[A-Z]{2})?' | uniq | xargs)
locales_json=$(echo -n "["; for locale in $locales; do echo -n "\"$locale\","; done | sed 's/,$//'; echo -n "]")
echo "locales=$locales_json" >> $GITHUB_OUTPUT
generate_distribution_files:
needs: generate_locales
runs-on: ubuntu-latest
strategy:
matrix:
locale: ${{ fromJson(needs.generate_locales.outputs.LOCALES) }}
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- uses: cue-lang/[email protected]
with:
version: 'v0.7.0'
- name: Generate local-specific distribution files
run: make VERBOSE=1 LOCALES=${{ matrix.locale }}
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.locale }}
path: dist/${{ matrix.locale }}

create_pull_request:
needs: generate_distribution_files
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
path: dist
- name: Set up short SHA
id: short_sha
run: echo "sha=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_OUTPUT
- name: Get last commit author username
id: last_committer
run: |
LAST_COMMIT_SHA=$(git log -1 --pretty=format:'%H')
API_URL="https://api.github.com/repos/${{ github.repository }}/commits/${LAST_COMMIT_SHA}"
AUTHOR_LOGIN=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" $API_URL | jq -r '.author.login')
echo "username=$AUTHOR_LOGIN" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Commit changes and create PR
uses: peter-evans/create-pull-request@v6
with:
commit-message: "🤖 Update localization files for ${{ github.sha }}"
branch: "localization-dist"
title: "🤖 Update localization files"
body: |
Update `dist/` localization files. Triggered by ${{ steps.short_sha.outputs.sha }}.
cc @${{ steps.last_committer.outputs.username }}
labels: automated-pr, localization
reviewers: ${{ steps.last_committer.outputs.username }}
106 changes: 0 additions & 106 deletions .github/workflows/generate_full_dist.yml

This file was deleted.

Loading

0 comments on commit 3686a83

Please sign in to comment.