|
| 1 | +name: Release Extension |
| 2 | +description: Release an extension as a GitHub Release |
| 3 | + |
| 4 | +inputs: |
| 5 | + extension-name: |
| 6 | + description: The name of the extension |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + |
| 10 | +runs: |
| 11 | + using: "composite" |
| 12 | + |
| 13 | + steps: |
| 14 | + - uses: actions/setup-node@v4 |
| 15 | + |
| 16 | + - run: npm install -g semver |
| 17 | + shell: bash |
| 18 | + |
| 19 | + - name: Get manifest extension version |
| 20 | + run: | |
| 21 | + MANIFEST_VERSION=$(semver -c $(jq -c -r '.extension.version' < ./extensions/${{ inputs.extension-name }}/manifest.json)) |
| 22 | + echo "MANIFEST_VERSION=$MANIFEST_VERSION" >> "$GITHUB_ENV" |
| 23 | + shell: bash |
| 24 | + |
| 25 | + # Grabs the latest version from the extensions.json file |
| 26 | + # If an extension hasn't been released yet we default to `0.0.0` so any |
| 27 | + # version in the manifest will be higher |
| 28 | + - name: Get lastest version from extension list |
| 29 | + continue-on-error: true |
| 30 | + run: | |
| 31 | + LATEST_VERSION=$(jq -c '.extensions[] | select(.name=="${{ inputs.extension-name }}").latestVersion.version' < extensions.json) |
| 32 | + LATEST_VERSION=$(semver -c "${LATEST_VERSION:-0.0.0}") |
| 33 | + echo "LATEST_VERSION=$LATEST_VERSION" >> "$GITHUB_ENV" |
| 34 | + shell: bash |
| 35 | + |
| 36 | + # We only want to release if the manifest.json contains a newer semver |
| 37 | + # version than the latest version in the extensions.json |
| 38 | + # We compare that here, and echo if a release will occur |
| 39 | + # This can be helpful when looking at Pull Request action outputs |
| 40 | + # so it is clear what will happen on a merge to `main` |
| 41 | + - name: Check if manifest has newer version |
| 42 | + id: should_release |
| 43 | + run: | |
| 44 | + echo "The manifest version is '$MANIFEST_VERSION' and the released version is '$LATEST_VERSION'" |
| 45 | + HIGHER_VERSION=$(semver "$MANIFEST_VERSION" "$LATEST_VERSION" | tail -n 1) |
| 46 | + if [ "$MANIFEST_VERSION" = "$HIGHER_VERSION" ] && [ "$MANIFEST_VERSION" != "$LATEST_VERSION" ]; then |
| 47 | + echo "🚀 Will release! The manifest version is greater than the released version." |
| 48 | + echo "should_release=true" >> "$GITHUB_OUTPUT" |
| 49 | + else |
| 50 | + echo "😴 Holding back from release: The manifest version is not greater than the released version." |
| 51 | + echo "should_release=false" >> "$GITHUB_OUTPUT" |
| 52 | + fi |
| 53 | + shell: bash |
| 54 | + |
| 55 | + # Here we download the packaged extension artifact to release |
| 56 | + - uses: actions/download-artifact@v4 |
| 57 | + if: github.ref_name == 'main' && steps.should_release.outputs.should_release == 'true' |
| 58 | + with: |
| 59 | + name: ${{ inputs.extension-name }}.tar.gz |
| 60 | + |
| 61 | + # The release tag utilizes both the extension name and semver version |
| 62 | + # to create a unique tag for the repository |
| 63 | + - name: Release tag |
| 64 | + if: github.ref_name == 'main' && steps.should_release.outputs.should_release == 'true' |
| 65 | + id: release_tag |
| 66 | + run: | |
| 67 | + RELEASE_TAG="${{ inputs.extension-name }}@v$MANIFEST_VERSION" |
| 68 | + echo "RELEASE_TAG=$RELEASE_TAG" >> "$GITHUB_ENV" |
| 69 | + shell: bash |
| 70 | + |
| 71 | + - name: Release |
| 72 | + if: github.ref_name == 'main' && steps.should_release.outputs.should_release == 'true' |
| 73 | + run: | |
| 74 | + gh release create $RELEASE_TAG \ |
| 75 | + --title "${{ inputs.extension-name }} v$MANIFEST_VERSION" \ |
| 76 | + ${{ inputs.extension-name }}.tar.gz |
| 77 | + shell: bash |
| 78 | + |
| 79 | + # We fetch the GitHub release using the GitHub API, storing the data |
| 80 | + # for use in the extension list update. |
| 81 | + - name: Get release data |
| 82 | + if: github.ref_name == 'main' && steps.should_release.outputs.should_release == 'true' |
| 83 | + run: gh api /repos/${{ github.repository }}/releases/tags/$RELEASE_TAG > release-${{ inputs.extension-name }}.json |
| 84 | + shell: bash |
| 85 | + |
| 86 | + # Each release data file is uploaded as an artifact for the extension list update |
| 87 | + # The naming convention is `release-<extension-name>.json` to easily |
| 88 | + # download each artifact matching the pattern |
| 89 | + - name: Upload release data |
| 90 | + if: github.ref_name == 'main' && steps.should_release.outputs.should_release == 'true' |
| 91 | + uses: actions/upload-artifact@v4 |
| 92 | + with: |
| 93 | + name: release-${{ inputs.extension-name }}.json |
| 94 | + path: release-${{ inputs.extension-name }}.json |
0 commit comments