Skip to content

Release

Release #70

Workflow file for this run

# Workflow name
name: Release
# This workflow is triggered manually from the GitHub Actions tab.
on:
workflow_dispatch:
inputs:
version:
description: 'The release version (e.g., v1.8.0). This will be used to create the Git tag.'
required: true
type: string
# This input specifies the branch to tag and release from.
source_branch:
description: 'The branch to create the release from (e.g., main or 1.8). This branch MUST have the final code.'
required: true
type: string
default: 'main'
jobs:
# The job for creating a release
create-release:
name: Create Release
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
# This permission is required for creating a release and uploading assets.
contents: write
steps:
# Step 1: Check out the code from the SPECIFIED BRANCH in the AWS repository.
- name: Checkout code
uses: actions/checkout@v4
with:
# This ensures we are on the correct branch to get the latest code.
ref: ${{ github.event.inputs.source_branch }}
# CRITICAL: We check out the code from the AWS repository directly.
repository: aws/sagemaker-code-editor
# Step 2: Explicitly get the commit SHA of the checked-out branch HEAD.
- name: Get commit SHA
id: get_sha
run: echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
# Step 3: Delete existing tag in the AWS repo if you want to re-run the release.
- name: Delete existing tag (if any)
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const tag = '${{ github.event.inputs.version }}';
try {
await github.rest.git.deleteRef({
owner: 'aws',
repo: 'sagemaker-code-editor',
ref: `tags/${tag}`
});
console.log(`Deleted existing tag: ${tag}`);
} catch (e) {
if (e.status !== 404 && e.status !== 422) {
// Re-throw the error if it's not a "Not Found" or "Unprocessable" error
throw e;
}
console.log(`Tag ${tag} does not exist or already deleted.`);
}
# Step 4: Download the build artifact from the UPSTREAM repository after a PUSH event.
- name: Download artifact from build workflow
uses: dawidd6/action-download-artifact@v6
with:
# CRITICAL: Explicitly specify the repository where the build artifact was created.
repo: aws/sagemaker-code-editor
# BEST PRACTICE: Look for artifacts created by a 'push' event (e.g., after a PR is merged).
event: push
workflow: build.yml
branch: ${{ github.event.inputs.source_branch }}
name: npm-package
path: ./release-assets
workflow_conclusion: success
# Step 5: Prepare the release assets by renaming the artifact.
- name: Prepare release assets
id: prepare_assets
run: |
# Find the downloaded tarball (there should only be one).
ARTIFACT_FILE=$(find ./release-assets -name "*.tar.gz")
if [ -z "$ARTIFACT_FILE" ]; then
echo "::error::Build artifact not found! Ensure a 'build.yml' workflow ran successfully on the '${{ github.event.inputs.source_branch }}' branch in 'aws/sagemaker-code-editor' after the code was pushed/merged."
exit 1
fi
# Get the version from the manual input, and remove the leading 'v' if it exists.
VERSION_TAG="${{ github.event.inputs.version }}"
VERSION_NUM="${VERSION_TAG#v}"
# Create the new, clean filename for the release.
NEW_FILENAME="code-editor${VERSION_NUM}.tar.gz"
# Rename the file.
mv "$ARTIFACT_FILE" "./release-assets/$NEW_FILENAME"
echo "Renamed artifact to $NEW_FILENAME"
# Set the new filename as an output for the next step.
echo "filename=./release-assets/$NEW_FILENAME" >> $GITHUB_OUTPUT
# Step 6: Create the GitHub Release in the AWS repo using the CORRECT commit SHA.
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
# We need a token with permissions to create releases in the AWS repo.
token: ${{ secrets.GITHUB_TOKEN }}
# CRITICAL: Explicitly specify the repository to create the release in.
repository: aws/sagemaker-code-editor
name: CodeEditor ${{ github.event.inputs.version }}
tag_name: ${{ github.event.inputs.version }}
files: ${{ steps.prepare_assets.outputs.filename }}
draft: false
generate_release_notes: false
# CRITICAL: Force the tag to be created on the commit we explicitly got in Step 2.
target_commitish: ${{ steps.get_sha.outputs.sha }}