1- name : Automated Release
1+ # Workflow name
2+ name : Release
23
3- # Controls when the workflow will run
4+ # This workflow is triggered manually from the GitHub Actions tab.
45on :
5- # Triggers the workflow on updates to the "main" branch which include a version tag
6- push :
7- tags :
8- - ' **' # Push events to every tag including hierarchical tags like v1.0/beta
9-
10- # Allows you to run this workflow manually from the Actions tab
116 workflow_dispatch :
7+ inputs :
8+ version :
9+ description : ' The release version (e.g., v1.8.0). This will be used to create the Git tag.'
10+ required : true
11+ type : string
12+ # This input specifies the branch to tag and release from.
13+ source_branch :
14+ description : ' The branch to create the release from (e.g., main or 1.8). This branch MUST have the final code.'
15+ required : true
16+ type : string
17+ default : ' main'
1218
13-
14- # Defines permissions granted to the GITHUB_TOKEN for this workflow run.
15- # 'contents: write' is needed for actions like softprops/action-gh-release to create GitHub releases
16- # and for peter-evans/create-pull-request if it were to commit to the same repo
17-
18- permissions :
19- contents : write
20-
21-
22- # A workflow run is made up of one or more jobs that can run sequentially or in parallel
2319jobs :
24- # This job checks if the pushed tag is a valid version tag (starts with 'v')
25- check-tag :
20+ # The job for creating a release
21+ create-release :
22+ name : Create Release
2623 runs-on : ubuntu-latest
24+ timeout-minutes : 30
25+ permissions :
26+ # This permission is required for creating a release and uploading assets.
27+ contents : write
28+
2729 steps :
28- # This step performs the tag check
29- - name : Check tag is version tag
30- id : check # Assign an ID to this step to reference its outputs
30+ # Step 1: Check out the code from the SPECIFIED BRANCH in the AWS repository.
31+ - name : Checkout code
32+ uses : actions/checkout@v4
33+ with :
34+ # This ensures we are on the correct branch to get the latest code.
35+ ref : ${{ github.event.inputs.source_branch }}
36+ # CRITICAL: We check out the code from the AWS repository directly.
37+ repository : aws/sagemaker-code-editor
38+
39+ # Step 2: Explicitly get the commit SHA of the checked-out branch HEAD.
40+ - name : Get commit SHA
41+ id : get_sha
42+ run : echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
43+
44+ # Step 3: Delete existing tag in the AWS repo if you want to re-run the release.
45+ - name : Delete existing tag (if any)
46+ uses : actions/github-script@v7
47+ with :
48+ github-token : ${{ secrets.GITHUB_TOKEN }}
49+ script : |
50+ const tag = '${{ github.event.inputs.version }}';
51+ try {
52+ await github.rest.git.deleteRef({
53+ owner: 'aws',
54+ repo: 'sagemaker-code-editor',
55+ ref: `tags/${tag}`
56+ });
57+ console.log(`Deleted existing tag: ${tag}`);
58+ } catch (e) {
59+ if (e.status !== 404 && e.status !== 422) {
60+ // Re-throw the error if it's not a "Not Found" or "Unprocessable" error
61+ throw e;
62+ }
63+ console.log(`Tag ${tag} does not exist or already deleted.`);
64+ }
65+
66+
67+ # Step 4: Download the build artifact from the UPSTREAM repository after a PUSH event.
68+ - name : Download artifact from build workflow
69+ uses : dawidd6/action-download-artifact@v6
70+ with :
71+ # CRITICAL: Explicitly specify the repository where the build artifact was created.
72+ repo : aws/sagemaker-code-editor
73+ # BEST PRACTICE: Look for artifacts created by a 'push' event (e.g., after a PR is merged).
74+ event : push
75+ workflow : build.yml
76+ branch : ${{ github.event.inputs.source_branch }}
77+ name : npm-package
78+ path : ./release-assets
79+ workflow_conclusion : success
80+
81+ # Step 5: Prepare the release assets by renaming the artifact.
82+ - name : Prepare release assets
83+ id : prepare_assets
3184 run : |
32- # Check if the GitHub reference (github.ref) starts with 'refs/tags/v'
33- if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
34- REF="${{ github.ref }}"
35- VERSION="${REF##refs/tags/v}"
36- echo "Tag starts with 'v'."
37- echo "Version: ${VERSION}"
38- echo "Continuing..."
39- # Set the version as an output variable for other jobs/steps
40- echo "version=${VERSION}" >> $GITHUB_OUTPUT
41- exit 0
42- else
43- echo "The tag doesn't start with 'v'. To release a new version, the tag must start with 'v'"
85+ # Find the downloaded tarball (there should only be one).
86+ ARTIFACT_FILE=$(find ./release-assets -name "*.tar.gz")
87+
88+ if [ -z "$ARTIFACT_FILE" ]; then
89+ 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."
4490 exit 1
4591 fi
46- outputs :
47- version : ${{ steps.check.outputs.version }}
48-
49- # This job builds the release tarball and publishes it to GitHub Releases
50- release :
51- # Specifies the environment for this job (if you have environments configured)
52- environment : release
53- # This job runs on the latest Ubuntu environment
54- runs-on : ubuntu-latest
55- needs : [check-tag]
56- container :
57- image : node:20
58- steps :
59- # Checks out the repository code at the specific tag that triggered the workflow
60- - name : Checkout the main branch
61- uses : actions/checkout@v4
62- - name : Install Dependencies
63- run : |
64- apt-get update
65- apt-get install -y build-essential g++ libx11-dev libxkbfile-dev libsecret-1-dev libkrb5-dev python-is-python3 quilt
66- # Builds the tarball
67- - name : Build Tarball
68- id : build
69- run : |
70- # Configure git safe directory for operations within the workspace
71- git config --global --add safe.directory /__w/sagemaker-code-editor/sagemaker-code-editor
7292
73- # Run the install script to build the tarball, passing the version
74- sh ./scripts/install.sh -t ${{ needs.check-tag.outputs.version }}
93+ # Get the version from the manual input, and remove the leading 'v' if it exists.
94+ VERSION_TAG="${{ github.event.inputs.version }}"
95+ VERSION_NUM="${VERSION_TAG#v}"
7596
76- # Define the tarball name based on the version
77- TARBALL_NAME="code-editor${{ needs.check-tag.outputs.version }}.tar.gz"
78- # Set the tarball name as an output variable
79- echo "tarball_name=${TARBALL_NAME}" >> $GITHUB_OUTPUT
97+ # Create the new, clean filename for the release.
98+ NEW_FILENAME="code-editor${VERSION_NUM}.tar.gz"
8099
81- # Calculate the SHA256 hash of the tarball
82- SHA256_HASH=$(sha256sum ${TARBALL_NAME} | awk '{ print $1 }')
83- # Set the SHA256 hash as an output variable
84- echo "sha256_hash=${SHA256_HASH}" >> $GITHUB_OUTPUT
85- # Publishes the release to GitHub Releases
86- - name : Publish Release
87- id : publish # Assign an ID to this step to reference its outputs
88- uses : softprops/action-gh-release@v2.2.2 # Caution: Due to recent update of action-gh-release, it now requires node24. So here we still used the previous version v2.2.2
89- with :
90- # Name of the release (e.g., "Code Editor x.y.z")
91- name : Code Editor ${{ needs.check-tag.outputs.version }}
92- # Tag name for the release (e.g., "vx.y.z")
93- tag_name : v${{ needs.check-tag.outputs.version }}
94- # Files to upload as release assets
95- files : |
96- ${{ steps.build.outputs.tarball_name }}
97- # Define outputs for this job
98- outputs :
99- sha256_hash : ${{ steps.build.outputs.sha256_hash }}
100- assets : ${{ steps.publish.outputs.assets }}
100+ # Rename the file.
101+ mv "$ARTIFACT_FILE" "./release-assets/$NEW_FILENAME"
102+
103+ echo "Renamed artifact to $NEW_FILENAME"
104+ # Set the new filename as an output for the next step.
105+ echo "filename=./release-assets/$NEW_FILENAME" >> $GITHUB_OUTPUT
101106
102-
107+ # Step 6: Create the GitHub Release in the AWS repo using the CORRECT commit SHA.
108+ - name : Create GitHub Release
109+ uses : softprops/action-gh-release@v2
110+ with :
111+ # We need a token with permissions to create releases in the AWS repo.
112+ token : ${{ secrets.GITHUB_TOKEN }}
113+ # CRITICAL: Explicitly specify the repository to create the release in.
114+ repository : aws/sagemaker-code-editor
115+ name : CodeEditor ${{ github.event.inputs.version }}
116+ tag_name : ${{ github.event.inputs.version }}
117+ files : ${{ steps.prepare_assets.outputs.filename }}
118+ draft : false
119+ generate_release_notes : false
120+ # CRITICAL: Force the tag to be created on the commit we explicitly got in Step 2.
121+ target_commitish : ${{ steps.get_sha.outputs.sha }}
0 commit comments