From 6288ae283bb48f51a3b1f0643806639fe4b2b663 Mon Sep 17 00:00:00 2001 From: Aram Grigoryan <132480+aram356@users.noreply.github.com> Date: Tue, 17 Feb 2026 14:56:09 -0800 Subject: [PATCH 1/2] Add staging sub-action for deploying to Fastly staging environment Implements the official Fastly staging workflow: - fastly compute build - fastly compute update --autoclone (upload as draft, no activation) - fastly service-version stage --version= --- staging/action.yml | 82 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 staging/action.yml diff --git a/staging/action.yml b/staging/action.yml new file mode 100644 index 0000000..639423a --- /dev/null +++ b/staging/action.yml @@ -0,0 +1,82 @@ +name: 'Stage a Compute package' +author: 'Fastly' +description: 'Builds and stages a Compute package to the Fastly staging environment using the Fastly CLI.' + +branding: + icon: 'upload-cloud' + color: 'red' + +inputs: + project_directory: + description: 'Directory of the project to build, relative to the repository root.' + required: false + default: './' + service_id: + description: 'The Fastly service ID to stage to.' + required: true + comment: + description: 'An optional comment to be included with the staged service version.' + required: false + default: '' + verbose: + description: 'Set to true to enable verbose logging' + required: false + default: 'false' + cli_version: + description: 'The version of the Fastly CLI to install, e.g. v0.20.0' + required: false + default: 'latest' + token: + description: 'The GitHub token to use when downloading the Fastly CLI' + required: false + +runs: + using: "composite" + steps: + - name: Set up Fastly CLI + uses: stackpop/fastly-compute-actions/setup@main + with: + token: ${{ inputs.token }} + cli_version: ${{ inputs.cli_version }} + + - name: Build Compute package + run: fastly compute build --non-interactive + shell: bash + working-directory: ${{ inputs.project_directory }} + + - name: Upload package as draft version + id: upload-draft + env: + FASTLY_API_TOKEN: ${{ env.FASTLY_API_TOKEN }} + run: | + OUTPUT=$(fastly compute update --autoclone --service-id="${{ inputs.service_id }}" --version=active 2>&1 | tee /dev/stderr) + VERSION=$(echo "$OUTPUT" | grep -oE 'version [0-9]+' | grep -oE '[0-9]+') + if [ -z "$VERSION" ]; then + echo "::error::Failed to extract version number from fastly compute update output" + exit 1 + fi + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "Uploaded draft version: $VERSION" + shell: bash + working-directory: ${{ inputs.project_directory }} + + - name: Add comment to draft version + if: ${{ inputs.comment != '' }} + env: + FASTLY_API_TOKEN: ${{ env.FASTLY_API_TOKEN }} + run: | + fastly service-version update \ + --version=${{ steps.upload-draft.outputs.version }} \ + --service-id="${{ inputs.service_id }}" \ + --comment="${{ inputs.comment }}" + shell: bash + + - name: Stage draft version + env: + FASTLY_API_TOKEN: ${{ env.FASTLY_API_TOKEN }} + run: | + fastly service-version stage \ + --version=${{ steps.upload-draft.outputs.version }} \ + --service-id="${{ inputs.service_id }}" + echo "Successfully staged version ${{ steps.upload-draft.outputs.version }}" + shell: bash From 9f79d896d521ef4df3b85c2bc8bd7fd3e0d30b7f Mon Sep 17 00:00:00 2001 From: Aram Grigoryan <132480+aram356@users.noreply.github.com> Date: Thu, 19 Feb 2026 11:54:04 -0800 Subject: [PATCH 2/2] Getting ready for PR --- README.md | 31 +++++++++++++++++++++++++++++-- staging/action.yml | 32 +++++++++++++++++++++----------- 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 479a9ba..a6533f4 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,7 @@ Alternatively, you can manually run the individual GitHub Actions for Compute if - [fastly/compute-actions/build](build/index.js) - Build a Compute project. Equivalent to `fastly compute build` - [fastly/compute-actions/deploy](deploy/index.js) - Deploy a Compute project. Equivalent to `fastly compute deploy` - [fastly/compute-actions/preview](preview/action.yml) - Deploy a Compute project to a new Fastly Service, which is deleted when the pull-request is merged or closed. +- [fastly/compute-actions/staging](staging/action.yml) - Build and stage a Compute project to the Fastly staging environment without activating it. #### Deploy to Fastly when push to `main` @@ -131,6 +132,32 @@ jobs: FASTLY_API_TOKEN: ${{ secrets.FASTLY_API_TOKEN }} ``` +#### Stage to Fastly staging environment + +```yml +name: Stage Application +on: + push: + branches: [staging] + +jobs: + stage: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install Dependencies + run: npm ci + + - name: Stage Compute Package + uses: fastly/compute-actions/staging@v12 + with: + service_id: '4tYGx...' # optional, defaults to value in fastly.toml + comment: 'Staged via GitHub Actions' # optional + env: + FASTLY_API_TOKEN: ${{ secrets.FASTLY_API_TOKEN }} +``` + #### Preview on Fastly for each pull-request ```yml @@ -160,8 +187,8 @@ The following inputs can be used as `with` keys for the actions in this reposito - `project_directory` - Directory of the project to deploy, relative to the repository root. - `cli_version` - The version of the Fastly CLI to install, e.g. v0.20.0 -- `service_id` - The Fastly service ID to deploy to. Defaults to the value in `fastly.toml`. (deploy only) -- `comment` - An optional comment to be included with the deployed service version. (deploy only) +- `service_id` - The Fastly service ID to deploy or stage to. Defaults to the value in `fastly.toml`. (deploy and staging) +- `comment` - An optional comment to be included with the deployed or staged service version. (deploy and staging) - `version` - Version to clone from when deploying. Can be "latest", "active", or the number of a specific version. (deploy only) - `verbose` - Set to true to enable verbose logging. - `token` - The GitHub token to use when interacting with the GitHub API. diff --git a/staging/action.yml b/staging/action.yml index 639423a..8b0937f 100644 --- a/staging/action.yml +++ b/staging/action.yml @@ -12,8 +12,9 @@ inputs: required: false default: './' service_id: - description: 'The Fastly service ID to stage to.' - required: true + description: 'The Fastly service ID to stage to. Defaults to the value in fastly.toml.' + required: false + default: '' comment: description: 'An optional comment to be included with the staged service version.' required: false @@ -34,7 +35,7 @@ runs: using: "composite" steps: - name: Set up Fastly CLI - uses: stackpop/fastly-compute-actions/setup@main + uses: fastly/compute-actions/setup@main with: token: ${{ inputs.token }} cli_version: ${{ inputs.cli_version }} @@ -49,7 +50,11 @@ runs: env: FASTLY_API_TOKEN: ${{ env.FASTLY_API_TOKEN }} run: | - OUTPUT=$(fastly compute update --autoclone --service-id="${{ inputs.service_id }}" --version=active 2>&1 | tee /dev/stderr) + ARGS="--autoclone --version=active" + if [ -n "${{ inputs.service_id }}" ]; then + ARGS="$ARGS --service-id=${{ inputs.service_id }}" + fi + OUTPUT=$(fastly compute update $ARGS 2>&1 | tee /dev/stderr) VERSION=$(echo "$OUTPUT" | grep -oE 'version [0-9]+' | grep -oE '[0-9]+') if [ -z "$VERSION" ]; then echo "::error::Failed to extract version number from fastly compute update output" @@ -65,18 +70,23 @@ runs: env: FASTLY_API_TOKEN: ${{ env.FASTLY_API_TOKEN }} run: | - fastly service-version update \ - --version=${{ steps.upload-draft.outputs.version }} \ - --service-id="${{ inputs.service_id }}" \ - --comment="${{ inputs.comment }}" + ARGS="--version=${{ steps.upload-draft.outputs.version }} --comment=${{ inputs.comment }}" + if [ -n "${{ inputs.service_id }}" ]; then + ARGS="$ARGS --service-id=${{ inputs.service_id }}" + fi + fastly service-version update $ARGS shell: bash + working-directory: ${{ inputs.project_directory }} - name: Stage draft version env: FASTLY_API_TOKEN: ${{ env.FASTLY_API_TOKEN }} run: | - fastly service-version stage \ - --version=${{ steps.upload-draft.outputs.version }} \ - --service-id="${{ inputs.service_id }}" + ARGS="--version=${{ steps.upload-draft.outputs.version }}" + if [ -n "${{ inputs.service_id }}" ]; then + ARGS="$ARGS --service-id=${{ inputs.service_id }}" + fi + fastly service-version stage $ARGS echo "Successfully staged version ${{ steps.upload-draft.outputs.version }}" shell: bash + working-directory: ${{ inputs.project_directory }}