Skip to content

Commit

Permalink
Merge pull request #41 from carvel-dev/fix-github-actions
Browse files Browse the repository at this point in the history
Fix GitHub actions
  • Loading branch information
joaopapereira authored Sep 22, 2023
2 parents 5aa0c27 + 3dd08f0 commit 3e1f2fa
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 652 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/inclusive-language-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ on:

jobs:
check-inclusive-language:
uses: vmware-tanzu/carvel-release-scripts/.github/workflows/inclusive-language-check.yml@main
uses: carvel-dev/release-scripts/.github/workflows/inclusive-language-check.yml@main
12 changes: 9 additions & 3 deletions .github/workflows/release-published.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Checks after release is published
name: Checks after any release is published
on:
release:
types: ['published']
Expand All @@ -7,19 +7,25 @@ jobs:
validate-github-action:
runs-on: ubuntu-latest
steps:
- uses: k14s/setup-k14s-action@v1
- uses: carvel-dev/setup-action@v1
with:
only: kwt
kwt: ${{ github.event.release.tag_name }}
- run: |
kwt version
version=`kwt version`
tag="${{ github.event.release.tag_name }}"
tool_version="$(echo $version | sed 's/^.*[^0-9]\([0-9]*\.[0-9]*\.[0-9]*\).*$/\1/')"
if [[ "v${tool_version}" == "${tag}" ]];
then
echo "Version match with latest"
echo "Version match with $tag"
exit 0
else
echo "Versions do not match v$tool_version != $tag"
exit 1
fi
- run: |
curl -X POST https://api.github.com/repos/carvel-dev/release-scripts/dispatches \
-H 'Accept: application/vnd.github.everest-preview+json' \
-u ${{ secrets.carvel_bot_access_token }} \
--data '{"event_type": "kwt_released", "client_payload": { "tagName": "${{ github.event.release.tag_name }}", "repo": "${{ github.repository }}", "toolName": "kwt" }}'
104 changes: 104 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: goreleaser

on:
push:
tags:
- 'v*'

jobs:
goreleaser:
runs-on: ubuntu-latest
# Set permissions of github token. See https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#permissions
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.21.1
- name: Retrieve version
run: |
echo "TAG_NAME=$(echo ${{ github.ref }} | grep -Eo 'v[0-9].*')" >> $GITHUB_OUTPUT
id: version

- name: Run GoReleaser
# GoReleaser v5.0.0
uses: goreleaser/goreleaser-action@7ec5c2b0c6cdda6e8bbb49444bc797dd33d74dd8
if: startsWith(github.ref, 'refs/tags/')
with:
version: 1.20.0
args: release --clean --debug
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GORELEASER_CURRENT_TAG: ${{ steps.version.outputs.TAG_NAME }}

- uses: actions/github-script@v4
id: get-checksums-from-draft-release
if: startsWith(github.ref, 'refs/tags/')
with:
github-token: ${{secrets.GITHUB_TOKEN}}
result-encoding: string
script: |
var crypto = require('crypto');
const { owner, repo } = context.repo;
// https://docs.github.com/en/rest/reference/repos#list-releases
// https://octokit.github.io/rest.js/v18#repos-list-releases
var releases = await github.repos.listReleases({
owner: owner,
repo: repo
});
var crypto = require('crypto')
var fs = require('fs')
const url = require('url');
const https = require('https');
checksums = {}
for (const r of releases["data"]) {
if (r.draft && `refs/tags/${r.tag_name}` == "${{ github.ref }}") {
for (const asset of r.assets) {
var release_asset = await github.repos.getReleaseAsset({ headers: {accept: `application/octet-stream`}, accept: `application/octet-stream`, owner: owner, repo: repo, asset_id: asset.id });
const hash = crypto.createHash('sha256');
let http_promise = new Promise((resolve, reject) => {
https.get(release_asset.url, (stream) => {
stream.on('data', function (data) {
hash.update(data);
});
stream.on('end', function () {
checksums[asset.name]= hash.digest('hex');
resolve(`${asset.name}`);
});
});
});
await http_promise;
}
}
}
console.log(checksums)
return `${checksums['kwt-darwin-amd64']} ./kwt-darwin-amd64
${checksums['kwt-darwin-arm64']} ./kwt-darwin-arm64
${checksums['kwt-linux-amd64']} ./kwt-linux-amd64
${checksums['kwt-linux-arm64']} ./kwt-linux-arm64`
- name: verify uploaded artifacts
if: startsWith(github.ref, 'refs/tags/')
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: |
set -e -x
VERSION=`echo ${{ github.ref }} | grep -Eo '[0-9].*'`
./hack/build-binaries.sh "$VERSION" > ./go-checksums
cat ./go-checksums
diff ./go-checksums <(cat <<EOF
${{steps.get-checksums-from-draft-release.outputs.result}}
EOF
)
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/kwt
/kwt-*-*
/tmp
.idea
dist
80 changes: 80 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# This is an example .goreleaser.yml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- amd64
- arm64
main: ./cmd/kwt
binary: kwt-{{ .Os }}-{{ .Arch }}

flags:
- -trimpath

ldflags:
- -X github.com/k14s/kwt/pkg/kwt/version.Version={{ .Version }}

# archives:
# - format: binary
# name_template: "{{ .Binary }}"
# replacements:
# darwin: Darwin
# linux: Linux
# amd64: x86_64
archives:
- id: kwt
name_template: >-
{{- .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end -}}
checksum:
name_template: 'checksums.txt'
algorithm: sha256
disable: false
snapshot:
name_template: "{{ .Tag }}-next"
release:
# Repo in which the release will be created.
github:
owner: carvel-dev
name: kwt

# If set to true, will not auto-publish the release.
draft: true

# If set to auto, will mark the release as not ready for production
# in case there is an indicator for this in the tag e.g. v1.0.0-rc1
# If set to true, will mark the release as not ready for production.
# Default is false.
prerelease: auto

# use to change the name of the release.
name_template: "{{.Tag}}"

# You can disable this pipe in order to not upload any artifacts.
# Defaults to false.
disable: false

changelog:
# Set it to true if you wish to skip the changelog generation.
# This may result in an empty release notes on GitHub/GitLab/Gitea.
skip: false

# Sorts the changelog by the commit's messages.
# Could either be asc, desc or empty
# Default is empty
sort: asc

filters:
# Commit messages matching the regexp listed here will be removed from
# the changelog
# Default is empty
exclude:
- '^docs:'
- typo
2 changes: 1 addition & 1 deletion .wokeignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
vendor/
docs/network.md

# example we can change in the future - https://github.com/vmware-tanzu/carvel-kwt/issues/32
# example we can change in the future - https://github.com/carvel-dev/kwt/issues/32
test/e2e/assets/guestbook-all-in-one.yml
Loading

0 comments on commit 3e1f2fa

Please sign in to comment.