Skip to content

Commit

Permalink
Cache build step for use in publish step
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanformio committed Mar 21, 2024
1 parent 7e07c26 commit 836a406
Showing 1 changed file with 33 additions and 9 deletions.
42 changes: 33 additions & 9 deletions .github/workflows/repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ jobs:
with:
cmd: build

- name: Cache build directory
uses: actions/cache@v3
with:
path: .
key: ${{ runner.os }}-build-${{ hashFiles('build.tgz') }}
restore-keys: |
${{ runner.os }}-build-
test:
needs: setup
runs-on: ubuntu-latest
Expand Down Expand Up @@ -100,28 +108,44 @@ jobs:
cache: 'npm'
registry-url: 'https://registry.npmjs.org/'

- name: Restore node modules from cache
# Restore Build cache
- name: Restore build cache
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
path: .
key: ${{ runner.os }}-build-${{ hashFiles('build.tgz') }}
restore-keys: |
${{ runner.os }}-node-
${{ runner.os }}-build-
- name: Show workspace contents
run: |
ls -R .
- name: Prepare version for publish
id: prep
run: |
# Extract the pull request number and the short SHA of the commit
PR_NUMBER=$(echo ${{ github.event.number }})
COMMIT_SHORT_SHA=$(echo "${{ github.event.pull_request.head.sha }}" | cut -c1-7)
# Extract the current version from package.json
CURRENT_VERSION=$(node -p "require('./package.json').version")
NEW_VERSION="${CURRENT_VERSION}-dev.${PR_NUMBER}.${COMMIT_SHORT_SHA}"
# If the current version includes '-rc.', remove it and everything after
# This step ensures that we start with a base version like '3.0.0' even if it was a release candidate
BASE_VERSION=$(echo "$CURRENT_VERSION" | sed 's/-rc.*//')
# Construct the new version string
NEW_VERSION="${BASE_VERSION}-dev.${PR_NUMBER}.${COMMIT_SHORT_SHA}"
# Output the new version for use in subsequent GitHub Actions steps
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
- name: Echo version for testing
run: |
echo "Version to publish: $NEW_VERSION"
- name: Publish to npm
run: |
npm version $NEW_VERSION
npm publish --tag dev
# - name: Publish to npm
# run: |
# npm version $NEW_VERSION
# npm publish --tag dev

0 comments on commit 836a406

Please sign in to comment.