mirror-cockpit-project-cockpit/.github/workflows/webpack-jumpstart.yml
Martin Pitt 15469bb469 tools: Teach webpack-make.js to get node_modules by itself
This supports the "only work on web-y bits without autotools" workflow.
It avoids having to run `node-modules checkout` as a user from a clean
tree, and also helps after pulling new commits which change
node_modules.

As `argparse`, `webpack`, and our rsync plugin all live in node_modules,
to convert these to dynamic imports.
2023-03-21 15:51:31 +01:00

90 lines
2.7 KiB
YAML

name: webpack-jumpstart
on:
pull_request_target:
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
permissions:
pull-requests: none
timeout-minutes: 20
env:
BASE_SHA: ${{ github.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
steps:
- name: Build jumpstart tarball
run: |
id="$(docker container create -u node -w /home/node node:14 /bin/sh -ec \
"git init cockpit
cd cockpit
git config user.email '<>'
git config user.name 'nobody'
git remote add origin ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}
git fetch --no-tags origin ${BASE_SHA}:base ${HEAD_SHA}:head
git checkout --detach base
git merge --no-edit head
git rev-parse HEAD^{tree} > tree
NODE_ENV=production tools/webpack-make.js
tar cf webpack-jumpstart.tar dist package-lock.json tree")"
docker container start --attach "${id}" >&2
docker container cp "${id}":/home/node/cockpit/webpack-jumpstart.tar .
docker container rm -f "${id}"
- name: Create artifact
uses: actions/upload-artifact@v3
with:
name: webpack-jumpstart
path: webpack-jumpstart.tar
retention-days: 1
publish:
needs: build
runs-on: ubuntu-latest
permissions:
pull-requests: none
environment: cockpit-dist
timeout-minutes: 5
env:
GIT_DIR: git-dir.git
BASE_SHA: ${{ github.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
steps:
- name: Set up work area
run: |
set -ux
git init -b main
git config user.name "GitHub Workflow"
git config user.email "cockpituous@cockpit-project.org"
git remote add cache "ssh://git@github.com/${GITHUB_REPOSITORY%/*}/cockpit-dist"
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: webpack-jumpstart
path: artifact
- name: Stage git commit
run: |
set -ux
mkdir worktree
tar -C worktree -x --exclude '.git*' dist package-lock.json tree < artifact/webpack-jumpstart.tar
echo "${BASE_SHA}" > worktree/merge-base
git --work-tree worktree add dist package-lock.json merge-base tree
git --work-tree worktree commit --quiet -m "Build for ${HEAD_SHA}"
rm -rf worktree
git tag "sha-${HEAD_SHA}"
- name: Push git commit
run: |
eval $(ssh-agent)
ssh-add - <<< '${{ secrets.DEPLOY_KEY }}'
git push cache tag "sha-${HEAD_SHA}"
ssh-add -D
ssh-agent -k