Skip to content

Commit

Permalink
chore: use composite action to resolve exact npm package version (#251)
Browse files Browse the repository at this point in the history
* chore: use composite action to resolve exact npm package version

* fix: run schema workflows when actions change
  • Loading branch information
byCedric authored Mar 8, 2024
1 parent 5a4bf25 commit 2d0efa6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 22 deletions.
29 changes: 29 additions & 0 deletions .github/actions/package-version/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Package version
description: Resolve the exact npm package version, using a semver

inputs:
name:
description: Package name to resolve
required: true

semver:
description: Semver version to resolve the exact version of (e.g. "latest" or "^1.0.0")
default: 'latest'

outputs:
exact:
description: The exact version of the package, resolved from semver
value: ${{ steps.resolve.outputs.exact }}

runs:
using: composite
steps:
- name: 🌐 Resolve version
id: resolve
uses: actions/github-script@v7
with:
script: |
const packageRequest = '${{ inputs.name }}@${{ inputs.semver }}'
const { stdout: exactVersion } = await exec.getExecOutput('npm', ['show', packageRequest, 'version']);
core.setOutput('exact', exactVersion.trim());
console.log('✅ Resolved version for ${{ inputs.name }}', { packageRequest, exactVersion: exactVersion.trim() });
17 changes: 6 additions & 11 deletions .github/workflows/schema-eas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
pull_request:
types: [opened, synchronize]
paths:
- '.github/actions/**'
- .github/workflows/schema-eas.yml
- 'scripts/**'
- package.json
workflow_dispatch:
Expand Down Expand Up @@ -35,23 +37,16 @@ jobs:

- name: 🌐 Resolve version
id: version
uses: actions/github-script@v7
uses: ./.github/actions/package-version
with:
script: |
const inputVersion = "${{ github.event.inputs.version || 'latest' }}";
const { stdout: latestVersion } = await exec.getExecOutput('npm', ['view', 'eas-cli', 'dist-tags.latest']);
const resolvedVersion = inputVersion === 'latest'
? latestVersion.trim()
: inputVersion.trim();
core.setOutput('resolved', resolvedVersion);
console.log('✅ Resolved versions for eas-cli', { inputVersion, latestVersion, resolvedVersion });
name: eas-cli
semver: ${{ github.event.inputs.version || 'latest' }}

- name: 👷 Download schema
run: |
mkdir -p ./schema
rm -f ./schema/eas.json
curl https://raw.githubusercontent.com/expo/eas-cli/v${{ steps.version.outputs.resolved }}/packages/eas-json/schema/eas.schema.json -o ./schema/eas.json
curl https://raw.githubusercontent.com/expo/eas-cli/v${{ steps.version.outputs.exact }}/packages/eas-json/schema/eas.schema.json -o ./schema/eas.json
- name: 📋 Upload schema
uses: actions/upload-artifact@v4
Expand Down
17 changes: 6 additions & 11 deletions .github/workflows/schema-metadata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
pull_request:
types: [opened, synchronize]
paths:
- '.github/actions/**'
- .github/workflows/schema-metadata.yml
- 'scripts/**'
- package.json
workflow_dispatch:
Expand Down Expand Up @@ -35,23 +37,16 @@ jobs:

- name: 🌐 Resolve version
id: version
uses: actions/github-script@v7
uses: ./.github/actions/package-version
with:
script: |
const inputVersion = "${{ github.event.inputs.version || 'latest' }}";
const { stdout: latestVersion } = await exec.getExecOutput('npm', ['view', 'eas-cli', 'dist-tags.latest']);
const resolvedVersion = inputVersion === 'latest'
? latestVersion.trim()
: inputVersion.trim();
core.setOutput('resolved', resolvedVersion);
console.log('✅ Resolved versions for eas-cli', { inputVersion, latestVersion, resolvedVersion });
name: eas-cli
semver: ${{ github.event.inputs.version || 'latest' }}

- name: 👷 Download schema
run: |
mkdir -p ./schema
rm -f ./schema/eas-metadata.json
curl https://raw.githubusercontent.com/expo/eas-cli/v${{ steps.version.outputs.resolved }}/packages/eas-cli/schema/metadata-0.json -o ./schema/eas-metadata.json
curl https://raw.githubusercontent.com/expo/eas-cli/v${{ steps.version.outputs.exact }}/packages/eas-cli/schema/metadata-0.json -o ./schema/eas-metadata.json
- name: 📋 Upload schema
uses: actions/upload-artifact@v4
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/schema-xdl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
pull_request:
types: [opened, synchronize]
paths:
- '.github/actions/**'
- .github/workflows/schema-xdl.yml
- 'scripts/**'
- package.json
workflow_dispatch:
Expand Down

0 comments on commit 2d0efa6

Please sign in to comment.