Skip to content

chore(deps): update github artifact actions to v4 (major) #318

chore(deps): update github artifact actions to v4 (major)

chore(deps): update github artifact actions to v4 (major) #318

Workflow file for this run

---
# Based on https://github.com/nicolas-van/rust-cross-compile-example - Thanks!
name: Publish
on:
release:
types:
- published
workflow_dispatch:
pull_request: # for testing, when we change the workflow
branches:
- main
paths:
- .github/workflows/publish.yml
env:
CARGO_TERM_COLOR: always
defaults:
run:
# necessary for windows
shell: bash
jobs:
build:
strategy:
fail-fast: false
matrix:
include:
# 64-bit version of the x86 architecture for Linux-based systems with the GNU C Library (glibc)
- TARGET: x86_64-unknown-linux-gnu
OS: ubuntu-latest
# disabled, because ring package does not support musl
#- TARGET: x86_64-unknown-linux-musl # test in an alpine container on a mac
# OS: ubuntu-latest
# 64-bit version of the ARM architecture for Linux-based systems with the GNU C Library (glibc)
- TARGET: aarch64-unknown-linux-gnu # tested on aws t4g.nano
OS: ubuntu-latest
# disabled, because ring package does not support musl
#- TARGET: aarch64-unknown-linux-musl # tested on aws t4g.nano in alpine container
# OS: ubuntu-latest
# 32-bit version of the ARM architecture for Linux-based systems with the GNU C Library (glibc) and hardware floating-point support
- TARGET: armv7-unknown-linux-gnueabihf
OS: ubuntu-latest
# disabled, because ring package does not support musl
#- TARGET: armv7-unknown-linux-musleabihf # raspberry pi 2-3-4, not tested
# OS: ubuntu-latest
# 32-bit version of the ARM architecture for Linux-based systems with the GNU C Library (glibc) and hardware floating-point support
- TARGET: arm-unknown-linux-gnueabihf
OS: ubuntu-latest
# disabled, because ring package does not support musl
#- TARGET: arm-unknown-linux-musleabihf # raspberry pi 0-1, not tested
# OS: ubuntu-latest
# 64-bit version of the x86 architecture for macOS
- TARGET: x86_64-apple-darwin
OS: macos-latest
# 64-bit version of the ARM architecture for macOS
- target: aarch64-apple-darwin
OS: macos-latest
# 64-bit version of the x86 architecture for Windows-based systems with the Microsoft Visual C++ (MSVC) runtime
- TARGET: x86_64-pc-windows-msvc
OS: windows-latest
# 64-bit version of the x86 architecture for Windows-based systems with the GNU C Library (glibc) and GNU Compiler Collection (GCC)
- TARGET: x86_64-pc-windows-gnu
OS: windows-latest
# 32-bit version of the x86 architecture for Windows-based systems with the Microsoft Visual C++ (MSVC) runtime
- TARGET: i686-pc-windows-msvc
OS: windows-latest
# 32-bit version of the x86 architecture for Linux-based systems with the GNU C Library (glibc)
- TARGET: i686-unknown-linux-gnu
OS: ubuntu-latest
runs-on: ${{ matrix.OS }}
env:
NAME: cfn-teleport
TARGET: ${{ matrix.TARGET }}
OS: ${{ matrix.OS }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 0
- name: Dependency cache
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
./target
key: ${{ runner.os }}-${{ matrix.TARGET }}-target-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.TARGET }}-target-
- name: Install and configure dependencies
run: |
# dependencies are only needed on ubuntu as that's the only place where
# we make cross-compilation
if [[ "${OS}" =~ ^ubuntu.*$ ]]; then
sudo apt-get install -qq crossbuild-essential-arm64 crossbuild-essential-armhf
fi
if [[ "${TARGET}" =~ ^.*-musl(eabihf?)$ ]]; then
sudo apt-get install musl-tools
fi
if [[ "${TARGET}" == "i686-unknown-linux-gnu" ]]; then
sudo apt-get install gcc-multilib
fi
- name: Install rust target
run: rustup target add "${TARGET}"
- name: Run build
run: cargo build --release --verbose --target "${TARGET}"
- name: List target
run: find ./target
- name: Compress
id: compress
run: |
mkdir -p ./artifacts
VERSION="${GITHUB_REF_NAME}"
if ! [[ "${VERSION}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
VERSION="v9.9.9"
fi
if [[ $OS =~ ^windows.*$ ]]; then
SRC=$NAME.exe
ARTIFACT="./artifacts/${NAME}-${TARGET}-${VERSION}.exe"
elif [[ $OS =~ ^macos.*$ ]]; then
SRC=$NAME
ARTIFACT="./artifacts/${NAME}-${TARGET}-${VERSION}.dmg"
else
SRC=$NAME
ARTIFACT="./artifacts/${NAME}-${TARGET}-${VERSION}.tar.gz"
fi
mv "./target/$TARGET/release/${SRC}" "./${SRC}"
if [[ $OS =~ ^windows.*$ ]]; then
# there is no reduction in size for the exe
# tar.exe -a -c -f "${ARTIFACT}" "${SRC}"
mv "./${SRC}" "${ARTIFACT}"
elif [[ $OS =~ ^macos.*$ ]]; then
mkdir -p dmg
cp "./${SRC}" dmg
hdiutil create cfn-teleport.dmg -ov -volname "cfn-teleport" -fs HFS+ -srcfolder "dmg"
hdiutil convert cfn-teleport.dmg -format UDZO -o "${ARTIFACT}"
else
tar -czf "${ARTIFACT}" "${SRC}"
fi
if [[ ! $OS =~ ^windows.*$ ]]; then
ls -lh "${SRC}" "${ARTIFACT}"
fi
echo "ARTIFACT=${ARTIFACT}" >> $GITHUB_OUTPUT
- name: Archive artifact
uses: actions/upload-artifact@v4
with:
name: artifacts
path: |
./artifacts
- name: Attach artifact to release
run: |
if [[ "${{ github.event_name }}" != "pull_request" ]]; then
gh release upload "${GITHUB_REF_NAME}" "${ARTIFACT}"
else
echo "Not uploading artifact to release because this is a pull request"
ls -l "${ARTIFACT}"
fi
env:
GH_TOKEN: ${{ secrets.OVERRIDE_TOKEN }}
ARTIFACT: ${{ steps.compress.outputs.ARTIFACT }}
cargo-publish:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 0
- name: Dependency cache
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
./target
key: ubuntu-latest-x86_64-unknown-linux-gnu-target-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
ubuntu-latest-x86_64-unknown-linux-gnu-target-
- name: Publish to crates.io
run: |
if [[ "${{ github.event_name }}" != "pull_request" ]]; then
cargo publish
else
cargo publish --dry-run
fi
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
homebrew-publish:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
repository: udondan/homebrew-software
token: ${{ secrets.OVERRIDE_TOKEN }}
- uses: actions/download-artifact@v4
with:
name: artifacts
path: artifacts
- name: Update homebrew formula
run: |
VERSION="${GITHUB_REF_NAME}"
if ! [[ "${VERSION}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
VERSION="v9.9.9"
fi
AARM=($(shasum -a 256 artifacts/cfn-teleport-aarch64-apple-darwin-${VERSION}.dmg))
AINTEL=($(shasum -a 256 artifacts/cfn-teleport-x86_64-apple-darwin-${VERSION}.dmg))
LARM32=($(shasum -a 256 artifacts/cfn-teleport-arm-unknown-linux-gnueabihf-${VERSION}.tar.gz))
LARM64=($(shasum -a 256 artifacts/cfn-teleport-aarch64-unknown-linux-gnu-${VERSION}.tar.gz))
LINTEL32=($(shasum -a 256 artifacts/cfn-teleport-i686-unknown-linux-gnu-${VERSION}.tar.gz))
LINTEL64=($(shasum -a 256 artifacts/cfn-teleport-x86_64-unknown-linux-gnu-${VERSION}.tar.gz))
echo "${TEMPLATE}" | sed \
-e "s!{{ version }}!${VERSION:1}!g" \
-e "s!{{ a_intel_file }}!$(basename ${AINTEL[1]})!g" \
-e "s!{{ a_intel_sha }}!${AINTEL[0]}!g" \
-e "s!{{ a_arm_file }}!$(basename ${AARM[1]})!g" \
-e "s!{{ a_arm_sha }}!${AARM[0]}!g" \
-e "s!{{ l_intel32_file }}!$(basename ${LINTEL32[1]})!g" \
-e "s!{{ l_intel32_sha }}!${LINTEL32[0]}!g" \
-e "s!{{ l_intel64_file }}!$(basename ${LINTEL64[1]})!g" \
-e "s!{{ l_intel64_sha }}!${LINTEL64[0]}!g" \
-e "s!{{ l_arm32_file }}!$(basename ${LARM32[1]})!g" \
-e "s!{{ l_arm32_sha }}!${LARM32[0]}!g" \
-e "s!{{ l_arm64_file }}!$(basename ${LARM64[1]})!g" \
-e "s!{{ l_arm64_sha }}!${LARM64[0]}!g" \
> cfn-teleport.rb
cat cfn-teleport.rb
rm -rf artifacts
git diff
git add cfn-teleport.rb
git status
git config --global user.email "${EMAIL}"
git config --global user.name "udondan"
git commit -m "Release ${VERSION:1}"
if [[ "${{ github.event_name }}" != "pull_request" ]]; then
git push
fi
env:
EMAIL: ${{ secrets.EMAIL }}
NAME: ${{ secrets.NAME }}
TEMPLATE: |
# typed: false
# frozen_string_literal: true
class CfnTeleport < Formula
desc "A command line-tool which can move CloudFormation resources between stacks"
homepage "${{ github.server_url }}/${{ github.repository }}"
version "{{ version }}"
license "Apache-2.0"
if OS.mac?
if Hardware::CPU.intel?
url "${{ github.server_url }}/${{ github.repository }}/releases/download/v{{ version }}/{{ a_intel_file }}"
sha256 "{{ a_intel_sha }}"
elsif Hardware::CPU.arm?
url "${{ github.server_url }}/${{ github.repository }}/releases/download/v{{ version }}/{{ a_arm_file }}"
sha256 "{{ a_arm_sha }}"
end
elsif OS.linux?
if Hardware::CPU.arm?
if Hardware::CPU.is_64_bit?
url "${{ github.server_url }}/${{ github.repository }}/releases/download/v{{ version }}/{{ l_arm64_file }}"
sha256 "{{ l_arm64_sha }}"
elsif Hardware::CPU.is_32_bit?
url "${{ github.server_url }}/${{ github.repository }}/releases/download/v{{ version }}/{{ l_arm32_file }}"
sha256 "{{ l_arm32_sha }}"
end
elsif Hardware::CPU.intel?
if Hardware::CPU.is_64_bit?
url "${{ github.server_url }}/${{ github.repository }}/releases/download/v{{ version }}/{{ l_intel64_file }}"
sha256 "{{ l_intel64_sha }}"
elsif Hardware::CPU.is_32_bit?
url "${{ github.server_url }}/${{ github.repository }}/releases/download/v{{ version }}/{{ l_intel32_file }}"
sha256 "{{ l_intel32_sha }}"
end
end
end
def install
bin.install "cfn-teleport"
end
end
aur-publish:
needs: build
runs-on: ubuntu-latest
container: archlinux:latest
steps:
- uses: actions/download-artifact@v4
with:
name: artifacts
path: artifacts
- name: Install and configure requirements
run: |
pacman -Sy --noconfirm --needed base-devel git openssh
mkdir /home/foo
useradd foo -d /home/foo
chown foo:foo /home/foo
echo "foo ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/foo
mkdir -p ~/.ssh/tmp
echo "${SSH_CONF}" > /etc/ssh/ssh_config
echo "${{ secrets.AUR_SSH_KEY }}" > /etc/ssh/id_ed25519
chmod 600 /etc/ssh/id_ed25519
ssh-keyscan aur.archlinux.org >> /etc/ssh/ssh_known_hosts
env:
SSH_CONF: |
Host aur.archlinux.org
User aur
IdentityFile /etc/ssh/id_ed25519
PreferredAuthentications publickey
StrictHostKeyChecking yes
- name: Update PKGBUILD
run: |
git clone "ssh://aur.archlinux.org/cfn-teleport.git" --depth=1
cd cfn-teleport
VERSION="${GITHUB_REF_NAME}"
if ! [[ "${VERSION}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
VERSION="v9.9.9"
fi
ARM=($(sha256sum ../artifacts/cfn-teleport-arm-unknown-linux-gnueabihf-${VERSION}.tar.gz))
X86_64=($(sha256sum ../artifacts/cfn-teleport-x86_64-unknown-linux-gnu-${VERSION}.tar.gz))
AARCH64=($(sha256sum ../artifacts/cfn-teleport-aarch64-unknown-linux-gnu-${VERSION}.tar.gz))
ARMV7H=($(sha256sum ../artifacts/cfn-teleport-armv7-unknown-linux-gnueabihf-${VERSION}.tar.gz))
I686=($(sha256sum ../artifacts/cfn-teleport-i686-unknown-linux-gnu-${VERSION}.tar.gz))
echo "${TEMPLATE}" | sed \
-e "s!{{ version }}!${VERSION:1}!g" \
-e "s!{{ arm_file }}!$(basename ${ARM[1]})!g" \
-e "s!{{ arm_sha }}!${ARM[0]}!g" \
-e "s!{{ x86_64_file }}!$(basename ${X86_64[1]})!g" \
-e "s!{{ x86_64_sha }}!${X86_64[0]}!g" \
-e "s!{{ aarch64_file }}!$(basename ${AARCH64[1]})!g" \
-e "s!{{ aarch64_sha }}!${AARCH64[0]}!g" \
-e "s!{{ armv7h_file }}!$(basename ${ARMV7H[1]})!g" \
-e "s!{{ armv7h_sha }}!${ARMV7H[0]}!g" \
-e "s!{{ i686_file }}!$(basename ${I686[1]})!g" \
-e "s!{{ i686_sha }}!${I686[0]}!g" \
> PKGBUILD
echo "##### PKGBUILD #####"
cat PKGBUILD
chown -R foo:foo .
runuser -l foo -c "cd $PWD;makepkg --printsrcinfo > .SRCINFO"
chown -R root:root .
echo "##### .SRCINFO #####"
cat .SRCINFO
echo "####################"
git status
git diff
git config --global user.email "${EMAIL}"
git config --global user.name "udondan"
git commit -am "Release ${VERSION:1}"
if [[ "${{ github.event_name }}" != "pull_request" ]]; then
git push
fi
env:
EMAIL: ${{ secrets.EMAIL }}
NAME: ${{ secrets.NAME }}
TEMPLATE: |
# Maintainer: ${{ secrets.NAME }} <${{ secrets.EMAIL }}>
# Maintainer: ${{ secrets.NAME2 }} <${{ secrets.EMAIL2 }}>
pkgname=cfn-teleport
pkgver={{ version }}
pkgrel=1
pkgdesc="A command-line tool which can move CloudFormation resources between stacks"
arch=("aarch64" "arm" "armv7h" "i686" "x86_64")
url="${{ github.server_url }}/${{ github.repository }}"
license=("APACHE")
# Source files
source_aarch64=("${url}/releases/download/v${pkgver}/cfn-teleport-aarch64-unknown-linux-gnu-v${pkgver}.tar.gz")
source_arm=("${url}/releases/download/v${pkgver}/cfn-teleport-arm-unknown-linux-gnueabihf-v${pkgver}.tar.gz")
source_armv7h=("${url}/releases/download/v${pkgver}/cfn-teleport-armv7-unknown-linux-gnueabihf-v${pkgver}.tar.gz")
source_i686=("${url}/releases/download/v${pkgver}/cfn-teleport-i686-unknown-linux-gnu-v${pkgver}.tar.gz")
source_x86_64=("${url}/releases/download/v${pkgver}/cfn-teleport-x86_64-unknown-linux-gnu-v${pkgver}.tar.gz")
# Checksums
sha256sums_aarch64=("{{ aarch64_sha }}")
sha256sums_arm=("{{ arm_sha }}")
sha256sums_armv7h=("{{ armv7h_sha }}")
sha256sums_i686=("{{ i686_sha }}")
sha256sums_x86_64=("{{ x86_64_sha }}")
# Build function
build() {
return 0
}
# Package functions
package() {
# Extract the package based on the current architecture
case "$CARCH" in
'aarch64') tar -xzf "${srcdir}/cfn-teleport-aarch64-unknown-linux-gnu-v${pkgver}.tar.gz" -C "${srcdir}/" ;;
'arm') tar -xzf "${srcdir}/cfn-teleport-arm-unknown-linux-gnueabihf-v${pkgver}.tar.gz" -C "${srcdir}/" ;;
'armv7h') tar -xzf "${srcdir}/cfn-teleport-armv7-unknown-linux-gnueabihf-v${pkgver}.tar.gz" -C "${srcdir}/" ;;
'i686') tar -xzf "${srcdir}/cfn-teleport-i686-unknown-linux-gnu-v${pkgver}.tar.gz" -C "${srcdir}/" ;;
'x86_64') tar -xzf "${srcdir}/cfn-teleport-x86_64-unknown-linux-gnu-v${pkgver}.tar.gz" -C "${srcdir}/" ;;
esac
# Move the binary to /usr/bin
install -Dm755 "${srcdir}/cfn-teleport" "${pkgdir}/usr/bin/cfn-teleport"
}
# chocolatey-publish:
# needs: build
# runs-on: windows-latest
# defaults:
# run:
# shell: powershell
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# with:
# persist-credentials: false
# fetch-depth: 0
#
# - uses: actions/download-artifact@v3
# with:
# name: artifacts
# path: artifacts
#
# - name: Generate chocolatey package
# run: |
# if (-not $Env:NUSPEC) {
# Write-Error "NUSPEC variable not set"
# exit 1
# }
#
# $markdown = Get-Content -Path "CHANGELOG.md" -Raw
# $startIndex = $markdown.IndexOf("## [", 0)
# $endIndex = $markdown.IndexOf("## [", $startIndex + 1)
# $releaseNotes = $markdown.Substring($startIndex, $endIndex - $startIndex)
#
# $nuspec = $Env:NUSPEC
# $installScript = $Env:INSTALL_SCRIPT
#
# $version = $Env:GITHUB_REF_NAME -replace '^v', ''
# if ($version -notmatch '^\d+\.\d+\.\d+$') {
# $version = '9.9.9'
# }
#
# # Get the file paths
# $url32File = "${{ github.workspace }}/artifacts/cfn-teleport-i686-pc-windows-msvc-v{0}.exe" -f $version
# $url64File = "${{ github.workspace }}/artifacts/cfn-teleport-x86_64-pc-windows-msvc-v{0}.exe" -f $version
#
# # Get the SHA256 hashes
# $sha32 = Get-FileHash $url32File -Algorithm SHA256 | Select-Object -ExpandProperty Hash
# $sha64 = Get-FileHash $url64File -Algorithm SHA256 | Select-Object -ExpandProperty Hash
#
# # Build the URLs
# $url32 = "https://github.com/udondan/cfn-teleport/releases/download/v{0}/cfn-teleport-i686-pc-windows-msvc-v{0}.exe" -f $version
# $url64 = "https://github.com/udondan/cfn-teleport/releases/download/v{0}/cfn-teleport-x86_64-pc-windows-msvc-v{0}.exe" -f $version
#
# # Replace the placeholders in the nuspec and script files
# $nuspecContent = $nuspec.Replace('{{ url32 }}', $url32).Replace('{{ sha32 }}', $sha32).Replace('{{ url64 }}', $url64).Replace('{{ sha64 }}', $sha64).Replace('{{ version }}', $version).Replace('{{ release_notes }}', $releaseNotes)
# $installScriptContent = $installScript.Replace('{{ url32 }}', $url32).Replace('{{ sha32 }}', $sha32).Replace('{{ url64 }}', $url64).Replace('{{ sha64 }}', $sha64).Replace('{{ version }}', $version)
#
# # Write nuspec and script files
# $nuspecPath = "${{ github.workspace }}/cfn-teleport.nuspec"
# Set-Content -Path $nuspecPath -Value $nuspecContent
#
# $toolsDir = "${{ github.workspace }}/tools"
# New-Item -ItemType Directory -Force -Path $toolsDir
# $installScriptPath = "${{ github.workspace }}/tools/chocolateyInstall.ps1"
# Set-Content -Path $installScriptPath -Value $installScriptContent
#
# # Output file content
# echo "#### cfn-teleport.nuspec ####"
# echo "$nuspecContent"
# echo "#### chocolateyInstall.ps1 ####"
# echo "$installScriptContent"
#
# # Create package
# echo "Creating package..."
# choco pack $nuspecPath
#
# if ("${{ github.event_name }}" -ne "pull_request") {
# # Test installation
# echo "Installing package..."
# $nupgkFile = "${{ github.workspace }}/cfn-teleport.{0}.nupkg" -f $version
# choco install cfn-teleport --source $nupgkFile --yes
#
# # Check if installation was successful
# echo "Checking if package was installed..."
# Get-Command cfn-teleport
# cfn-teleport.exe --version
#
# # Uninstall package
# echo "Uninstalling package..."
# choco uninstall cfn-teleport --yes
#
# # Ensure package is uninstalled
# echo "Checking if package was uninstalled..."
# if (Get-Command cfn-teleport -ErrorAction SilentlyContinue) {
# Write-Error "Package was not uninstalled"
# exit 1
# }
#
# # Push package
# echo "Pushing package..."
# choco push $nupgkFile --source https://push.chocolatey.org/ --api-key ${{ secrets.CHOCOLATEY_API_KEY }}
# }
# env:
# NUSPEC: |
# <?xml version="1.0"?>
# <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
# <metadata>
# <id>cfn-teleport</id>
# <title>cfn-teleport</title>
# <version>{{ version }}</version>
# <authors>udondan</authors>
# <description>A command-line tool which can move CloudFormation resources between stacks</description>
# <summary>A command-line tool which can move CloudFormation resources between stacks</summary>
# <tags>aws cloudformation migration</tags>
# <licenseUrl>https://github.com/udondan/cfn-teleport/blob/master/LICENSE</licenseUrl>
# <projectUrl>https://github.com/udondan/cfn-teleport</projectUrl>
# <packageSourceUrl>https://github.com/udondan/cfn-teleport/blob/main/.github/workflows/publish.yml</packageSourceUrl>
# <releaseNotes>{{ release_notes }}</releaseNotes>
# </metadata>
# <files>
# <file src="tools\**" target="tools" />
# </files>
# </package>
# INSTALL_SCRIPT: |
# $packageName = 'cfn-teleport'
# $version = '{{ version }}'
# $installDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
#
# $fileArgs = @{
# packageName = $packageName
# fileFullPath = Join-Path $installDir 'cfn-teleport.exe'
# url = '{{ url32 }}'
# checksum = '{{ sha32 }}'
# url64bit = '{{ url64 }}'
# checksum64 = '{{ sha64 }}'
# checksumType = 'sha256'
# ChecksumType64 = 'sha256'
# }
# Get-ChocolateyWebFile @fileArgs