Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 5 additions & 37 deletions .github/workflows/agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,6 @@ jobs:
with:
go-version: '1.24.0'
check-latest: true
- uses: actions/checkout@v2
with:
# You should create a personal access token and store it in your repository
token: ${{ secrets.CI_USER_TOKEN }}
repository: 'optimizely/travisci-tools'
path: 'home/runner/travisci-tools'
ref: 'master'
persist-credentials: false
- name: Get the version
id: get_version
run: echo "VERSION=${GITHUB_REF_NAME}" >> $GITHUB_OUTPUT
Expand All @@ -190,31 +182,22 @@ jobs:
echo "APP_VERSION=${TAG#v}" >> $GITHUB_ENV
echo "RELEASE_TAG=${TAG}" >> $GITHUB_ENV
echo "TRAVIS_BUILD_DIR=${{ steps.get_workspace.outputs.WORKSPACE }}" >> $GITHUB_ENV
- name: Upload and publish draft
env:
HOME: 'home/runner'
run: |
# installs hub to ~/bin
$HOME/travisci-tools/release_github/install_hub.sh
echo "$HOME/bin:$HOME/travisci-tools/release_github" >> $GITHUB_PATH
- name: run make
env:
TRAVIS_OS_NAME: 'linux'
run: |
make -e setup build
- name: create and upload packages
env:
HOME: 'home/runner'
env:
GITHUB_TOKEN: ${{ secrets.CI_USER_TOKEN }}
TRAVIS_OS_NAME: 'linux'
DOCKERHUB_PASS: ${{ secrets.DOCKERHUB_PASS }}
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
run: |
# now we're going to create packages & upload packages
./scripts/ci_create_packages.sh && ./scripts/ci_upload_packages.sh
# create the github release (draft)
cp $HOME/travisci-tools/release_github/release_github_v2.sh .
./release_github_v2.sh "$APP_VERSION"
# create the github release (draft) if it doesn't already exist
./scripts/ci_create_github_release.sh "$RELEASE_TAG"
# attach generate_secret to the github release
./scripts/ci_build_generate_secret.sh && ./scripts/ci_attach_generate_secret.sh

Expand Down Expand Up @@ -244,29 +227,13 @@ jobs:
with:
go-version: '1.24.0'
check-latest: true
- uses: actions/checkout@v2
with:
# You should create a personal access token and store it in your repository
token: ${{ secrets.CI_USER_TOKEN }}
repository: 'optimizely/travisci-tools'
path: 'home/runner/travisci-tools'
ref: 'master'
persist-credentials: false
- name: Get the version
id: get_version
run: echo "VERSION=${GITHUB_REF_NAME}" >> $GITHUB_OUTPUT
- name: set the env
run: |
TAG=${{ steps.get_version.outputs.VERSION }}
echo "APP_VERSION=${TAG#v}" >> $GITHUB_ENV
- name: Upload and publish draft
shell: bash
env:
HOME: 'home/runner'
run: |
# installs hub to ~/bin
$HOME/travisci-tools/release_github/install_hub.sh
# echo "$HOME/bin:$HOME/travisci-tools/slack" >> $GITHUB_PATH
- name: run script
env:
GITHUB_TOKEN: ${{ secrets.CI_USER_TOKEN }}
Expand All @@ -276,7 +243,8 @@ jobs:
id: script
shell: bash
run: |
hub release download $(git describe --abbrev=0 --tags) -i '*-${{ matrix.TARGET }}-*'
# gh is preinstalled on GitHub-hosted runners; replaces the deprecated hub CLI
gh release download $(git describe --abbrev=0 --tags) -p '*-${{ matrix.TARGET }}-*'
tar xvfz generate_secret-${{ matrix.TARGET }}-${APP_VERSION}.tar.gz -C /tmp
/tmp/generate_secret
# TODO: add step to publish outcome on teams.
Expand Down
11 changes: 7 additions & 4 deletions scripts/ci_attach_generate_secret.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/env bash
set -e

hub release edit "$RELEASE_TAG" -m "" \
-a "/tmp/output_packages/generate_secret-linux-amd64-$APP_VERSION.tar.gz#generate_secret $APP_VERSION for Linux 64-bit" \
-a "/tmp/output_packages/generate_secret-darwin-amd64-$APP_VERSION.tar.gz#generate_secret $APP_VERSION for MacOS 64-bit" \
-a "/tmp/output_packages/generate_secret-windows-amd64-$APP_VERSION.tar.gz#generate_secret $APP_VERSION for Windows 64-bit"
# Attaches the generate_secret binaries to the GitHub release for $RELEASE_TAG.
# Uses `gh` (preinstalled on GitHub-hosted runners) instead of the deprecated `hub` CLI.
# `gh release upload` supports per-asset display labels via the "path#label" syntax.
gh release upload "$RELEASE_TAG" --clobber \
"/tmp/output_packages/generate_secret-linux-amd64-$APP_VERSION.tar.gz#generate_secret $APP_VERSION for Linux 64-bit" \
"/tmp/output_packages/generate_secret-darwin-amd64-$APP_VERSION.tar.gz#generate_secret $APP_VERSION for MacOS 64-bit" \
"/tmp/output_packages/generate_secret-windows-amd64-$APP_VERSION.tar.gz#generate_secret $APP_VERSION for Windows 64-bit"
70 changes: 70 additions & 0 deletions scripts/ci_create_github_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env bash
set -eo pipefail

# Creates a draft GitHub release for the given tag, using the latest
# CHANGELOG.md entry as the release description.
#
# This is a `gh`-based replacement for travisci-tools/release_github/release_github_v2.sh,
# which relied on the deprecated `hub` CLI. `gh` is preinstalled on GitHub-hosted runners.
#
# Run this in the same directory where CHANGELOG.md lives.
# grep -P below is GNU grep specific, so this is meant to run on Linux.

CHANGELOG="CHANGELOG.md"

# set to true for debugging
debug=false

if [ $# -ne 1 ]; then
echo "example: $0 v3.1.1"
exit 1
fi

# the tag being released, e.g. v4.6.0
GIT_TAG="$1"

# VERSION is the git tag with the "v" prefix removed
VERSION=${GIT_TAG#v}

# The release is often already created (the tag push that triggers CI usually
# comes from a GitHub release created in the UI). In that case there is nothing
# to create -- just let the caller move on to uploading assets.
if gh release view "${GIT_TAG}" >/dev/null 2>&1; then
echo "Release ${GIT_TAG} already exists; skipping creation."
exit 0
fi

if [[ ! -f "${CHANGELOG}" ]]; then
echo "ERROR: ${CHANGELOG} not found in $(pwd)."
exit 1
fi

# check that CHANGELOG.md has been updated
# (first version entry in the changelog should match our VERSION argument)
NEW_VERSION_CHECK=$(grep -P '^## \[\d+\.\d+\.\d+\]' "${CHANGELOG}" | cut -d[ -f2 | cut -d] -f1 | awk 'NR==1')

$debug && echo "NEW_VERSION_CHECK $NEW_VERSION_CHECK"
$debug && echo "VERSION $VERSION"

if [[ "${NEW_VERSION_CHECK}" != "${VERSION}" ]]; then
echo "ERROR: ${CHANGELOG} has not been updated yet."
exit 1
fi

NEW_VERSION=$(grep -P '^## \[\d+\.\d+\.\d+\]' "${CHANGELOG}" | awk 'NR==1' | sed -e 's/\[/\\\[/' | sed -e 's/\]/\\\]/')
LAST_VERSION=$(grep -P '^## \[\d+\.\d+\.\d+\]' "${CHANGELOG}" | awk 'NR==2' | sed -e 's/\[/\\\[/' | sed -e 's/\]/\\\]/')

DESCRIPTION=$(awk "/^${NEW_VERSION}$/,/^${LAST_VERSION:-nothingmatched}$/" "${CHANGELOG}" | grep -v "^${LAST_VERSION:-nothingmatched}$")

$debug && echo "NEW_VERSION $NEW_VERSION"
$debug && echo "LAST_VERSION $LAST_VERSION"
$debug && echo "DESCRIPTION $DESCRIPTION"

# Write the notes to a temp file and pass via --notes-file. This avoids the shell
# re-parsing backticks / $ that can appear in changelog bodies (which --notes would).
NOTES_FILE=$(mktemp)
trap 'rm -f "${NOTES_FILE}"' EXIT
printf '%s\n' "${DESCRIPTION}" > "${NOTES_FILE}"

# --draft creates a draft release; the tag already exists (release is triggered by the tag push)
gh release create "${GIT_TAG}" --draft --title "Release ${VERSION}" --notes-file "${NOTES_FILE}"
Loading