Skip to content

Commit 3aa69ac

Browse files
author
Newton Der
committed
Update release workflow for 1.6
1 parent 204a475 commit 3aa69ac

File tree

1 file changed

+106
-165
lines changed

1 file changed

+106
-165
lines changed

.github/workflows/release.yml

Lines changed: 106 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -1,180 +1,121 @@
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.
45
on:
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
2319
jobs:
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 }}
101-
102-
# This job updates the feedstock repository
103-
update-feedstock-files:
104-
runs-on: ubuntu-latest
105-
# This job depends on the successful completion of 'check-tag' and 'release' jobs
106-
needs: [check-tag, release]
107-
steps:
108-
# Clones the feedstock repository (your fork)
109-
- name: Clone the feedstock repository
110-
uses: actions/checkout@v4
111-
with:
112-
repository: 'harvenstar/sagemaker-code-editor-feedstock'
113-
ref: 'dev'
114-
token: ${{ secrets.PERSONAL_TOKEN }}
115-
116-
- name: Create and checkout dynamic update branch
117-
id: create_branch # Assign an ID to this step to reference its outputs
118-
run: |
119-
# Generate a unique branch name using the version (e.g., "auto-update-v1.2.0")
120-
# This prevents conflicts with pre-existing branches from previous runs.
121-
NEW_BRANCH_NAME="auto-update-v${{ needs.check-tag.outputs.version }}"
122-
123-
git checkout -b ${NEW_BRANCH_NAME}
124-
echo "Created and switched to new branch: ${NEW_BRANCH_NAME}"
100+
# Rename the file.
101+
mv "$ARTIFACT_FILE" "./release-assets/$NEW_FILENAME"
125102
126-
# Output the new branch name for use in later steps (e.g., creating the PR)
127-
echo "branch_name=${NEW_BRANCH_NAME}" >> $GITHUB_OUTPUT
128-
129-
# Updates the meta.yaml file in the cloned feedstock repository
130-
# Updates the meta.yaml file in the cloned feedstock repository
131-
- name: Update meta.yaml
132-
run: |
133-
# Get the version from the 'check-tag' job's output
134-
VERSION=${{ needs.check-tag.outputs.version }}
135-
136-
sed -i "s/{% set version = \".*\" %}/{% set version = \"$VERSION\" %}/" recipe/meta.yaml
137-
138-
URL="${{ fromJSON(needs.release.outputs.assets)[0].browser_download_url }}"
139-
sed -i "s|url: .*\.tar\.gz|url: $URL|" recipe/meta.yaml
140-
141-
SHA256=${{ needs.release.outputs.sha256_hash }}
142-
sed -i "s|sha256: [0-9a-f]*|sha256: $SHA256|" recipe/meta.yaml
143-
144-
# Displays the differences in meta.yaml after modifications for verification
145-
- name: Show changes in meta.yaml
146-
run: git diff recipe/meta.yaml
147-
148-
# Commits the changes to meta.yaml and pushes them to the dynamic branch in your feedstock fork
149-
- name: Commit and push changes
150-
# This step commits the modified 'recipe/meta.yaml' file and pushes it to the remote feedstock repository.
151-
# - Git user name and email are configured for the commit.
152-
# - 'git add' stages the changes.
153-
# - 'git commit' creates a commit with a message including the new version.
154-
# ' || echo "No changes to commit." ' prevents the workflow from failing if there are no changes (e.g., if re-running on same version with no actual file change).
155-
# - The current local branch (which is the dynamic branch, e.g., 'auto-update-vX.Y.Z') is pushed to the 'origin' remote.
156-
# This creates the branch on the remote if it doesn't exist.
157-
run: |
158-
git config user.name "github-actions[bot]"
159-
git config user.email "github-actions[bot]@users.noreply.github.com"
160-
git add recipe/meta.yaml
161-
162-
# Check if there are changes to commit to avoid error if meta.yaml is already up-to-date
163-
if git diff --staged --quiet; then
164-
echo "No changes to commit."
165-
else
166-
git commit -m "Update recipe to v${{ needs.check-tag.outputs.version }}"
167-
fi
168-
169-
# Get the current branch name (should be the dynamic one created earlier)
170-
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
171-
echo "Pushing changes to origin/${CURRENT_BRANCH}"
172-
# Push the dynamic branch to your feedstock fork (origin)
173-
# The '-u' flag sets the upstream branch for future pushes/pulls from this local branch.
174-
git push -u origin ${CURRENT_BRANCH}
175-
176-
177-
# labels: automated-update, bot
178-
# assignees: harvenstar
179-
# reviewers: harvenstar
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
180106
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

Comments
 (0)