Skip to content

Commit

Permalink
Merge pull request #3 from orange-cloudavenue/2-add-tools-to-release
Browse files Browse the repository at this point in the history
chore: Add github workflows
  • Loading branch information
dmicheneau authored Nov 21, 2023
2 parents 42a41f2 + e05e5f5 commit cdd7c08
Show file tree
Hide file tree
Showing 7 changed files with 237 additions and 4 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/dapendabot_changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Add CHANGELOG for dependabot changes
on: pull_request_target
permissions:
pull-requests: write
issues: write
repository-projects: write
contents: write
jobs:
dependabot:
runs-on: ubuntu-latest
if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }}
steps:
- name: Fetch dependabot metadata
id: dependabot-metadata
uses: dependabot/fetch-metadata@v1.6.0
- uses: actions/checkout@v4
- run: |
gh pr checkout $PR_URL
cat << EOF > .changelog/$PR_NUMBER.txt
\`\`\`release-note:dependency
deps: bumps $DEP_NAME from $DEP_PREV_VERSION to $DEP_NEXT_VERSION
\`\`\`
EOF
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
git add .changelog/$PR_NUMBER.txt
git commit -m "add CHANGELOG for #$PR_NUMBER"
git push
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_URL: ${{ github.event.pull_request.html_url }}
PR_NUMBER: ${{ github.event.pull_request.number }}
DEP_NAME: ${{ steps.dependabot-metadata.outputs.dependency-names }}
DEP_PREV_VERSION: ${{ steps.dependabot-metadata.outputs.previous-version }}
DEP_NEXT_VERSION: ${{ steps.dependabot-metadata.outputs.new-version }}
33 changes: 33 additions & 0 deletions .github/workflows/generate_changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Generate CHANGELOG
on:
pull_request:
types: [closed]
workflow_dispatch:
jobs:
GenerateChangelog:
if: github.event.pull_request.merged || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4 # v3.5.3
with:
token: ${{ secrets.CHANGELOG_PAT }}
fetch-depth: 0
submodules: true
- uses: actions/setup-go@v4.0.1
with:
go-version-file: '.ci/tools/go.mod'
- run: go generate -tags tools .ci/tools/tools.go
- run: ./.ci/scripts/generate-changelog.sh
- run: |
if [[ `git status --porcelain` ]]; then
if ${{github.event_name == 'workflow_dispatch'}}; then
MSG="chore: update CHANGELOG.md (Manual Trigger)"
else
MSG="chore: update CHANGELOG.md for #${{ github.event.pull_request.number }}"
fi
git config --local user.email changelogbot@frangipane.io
git config --local user.name changelogbot
git add CHANGELOG.md
git commit -m "$MSG"
git push
fi
31 changes: 31 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Terraform Provider testing workflow.
name: Lint

# This GitHub action runs your tests for each pull request and push.
# Optionally, you can turn it on using a schedule for regular testing.
on:
pull_request:
paths:
- '**.go'

# Testing only needs permissions to read the repository contents.
permissions:
contents: read

jobs:
# Ensure project builds before running testing matrix
golangci-lint:
name: Lint
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4 # v3.5.0
- uses: actions/setup-go@v4.0.1 # v4.0.0
with:
go-version-file: 'go.mod'
- run: go mod download
- run: go build -v .
- name: Run linters
uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0
with:
version: latest
134 changes: 134 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Terraform Provider release workflow.
name: Release

# This GitHub action creates a release when a tag that matches the pattern
# "v*" (e.g. v0.1.0) is created.
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'

# Releases need permissions to read and write the repository contents.
# GitHub considers creating releases and uploading assets as writing contents.
permissions:
contents: write

jobs:
# testsunit:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-go@v4.0.1
# with:
# go-version-file: 'go.mod'
# - run: go mod download
# - name: Run Go unit tests
# run: |
# go test $(go list ./... | grep -v /internal/testsacc/)
release-notes:
runs-on: ubuntu-latest
needs: [testsunit]
steps:
- uses: actions/checkout@v4 # v3.5.3
with:
fetch-depth: 0
- name: Generate Release Notes
run: |
export PREV_TAG=$(git tag --list 'v*' --sort=-version:refname | head -n 2 | tail -n 1)
export PREV_VERSION=${PREV_TAG//v}
sed -n -e "1{/# /d;}" -e "2{/^$/d;}" -e "/# $PREV_VERSION/q;p" CHANGELOG.md > release-notes.txt
- uses: actions/upload-artifact@v3
with:
name: release-notes
path: release-notes.txt
retention-days: 1
goreleaser:
runs-on: ubuntu-latest
needs: [release-notes]
steps:
- uses: actions/checkout@v4 # v3.5.3
with:
# Allow goreleaser to access older tag information.
fetch-depth: 0
- uses: actions/setup-go@v4.0.1 # v4.0.0
with:
go-version-file: 'go.mod'
go-version: '>=1.20.0'
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@82a020f1f7f605c65dd2449b392a52c3fcfef7ef # v6.0.0
id: import_gpg
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
- id: release-notes-download
name: Release Notes Download
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: release-notes
path: /tmp
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@7ec5c2b0c6cdda6e8bbb49444bc797dd33d74dd8 # v5.0.0
with:
args: release --clean --release-notes=${{ steps.release-notes-download.outputs.download-path }}/release-notes.txt
env:
# GitHub sets the GITHUB_TOKEN secret automatically.
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
METRICS_TARGET: ${{ secrets.METRICS_TARGET }}
METRICS_TOKEN: ${{ secrets.METRICS_TOKEN }}
highest-version-tag:
needs: [goreleaser]
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.highest-version-tag.outputs.tag }}
steps:
- uses: actions/checkout@v4 # v3.5.3
with:
# Allow tag to be fetched when ref is a commit
fetch-depth: 0
- name: Output highest version tag
id: highest-version-tag
run: |
HIGHEST=$(git tag | sort -V | tail -1)
echo "tag=$HIGHEST" >> "$GITHUB_OUTPUT"
changelog-newversion:
needs: [goreleaser, highest-version-tag]
# write new changelog header only if release tag is the $HIGHEST i.e. exists on main
# and not a backport release branch (e.g. release/3.x). This results in
# manually updating the CHANGELOG header if releasing from the non-default branch.
# TODO: find a more deterministic way to determine release branch from tag commit
if: github.ref_name == needs.highest-version-tag.outputs.tag
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4 # v3.5.3
with:
token: ${{ secrets.CHANGELOG_PAT }}
fetch-depth: 0
ref: main
- name: Update Changelog Header
run: |
CHANGELOG_FILE_NAME="CHANGELOG.md"
PREVIOUS_RELEASE_TAG=${{ github.ref_name }}
# Add Release Date
RELEASE_DATE=`date +%B' '%e', '%Y`
sed -i -e "1 s/.*Unreleased.*/## ${PREVIOUS_RELEASE_TAG#v} ($RELEASE_DATE)/" $CHANGELOG_FILE_NAME
# Prepend next release line
echo Previous release is: $PREVIOUS_RELEASE_TAG
NEW_RELEASE_LINE=$(echo $PREVIOUS_RELEASE_TAG | awk -F. '{
$1 = substr($1,2)
$2 += 1
printf("%s.%01d.0\n\n", $1, $2);
}')
echo New minor version is: v$NEW_RELEASE_LINE
echo -e "## $NEW_RELEASE_LINE (Unreleased)\n$(cat $CHANGELOG_FILE_NAME)" > $CHANGELOG_FILE_NAME
- run: |
git config --local user.email changelogbot@frangipane.io
git config --local user.name changelogbot
git add CHANGELOG.md
git commit -m "Update CHANGELOG.md after ${{ github.ref_name }}"
git push
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21.3
require (
github.com/aws/aws-sdk-go v1.47.9
github.com/fbiville/markdown-table-formatter v0.3.0
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.5.4-0.20231120154256-3c8c8c214b94
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.5.5
github.com/spf13/cobra v1.8.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9Y
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.5.4-0.20231120154256-3c8c8c214b94 h1:6eVvqWBkrAT+7cPQImyACBdNPrEkYkm0A5FuUCQsTfw=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.5.4-0.20231120154256-3c8c8c214b94/go.mod h1:cWQdAHu+UlpulY0Vv4i+yPG17PUp8ZhK06VOR5Oq8iM=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.5.5 h1:/GzeWP+RPyiRBNsvnswq1HfMDWu12Ta1l5fnrRG/AMU=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.5.5/go.mod h1:cWQdAHu+UlpulY0Vv4i+yPG17PUp8ZhK06VOR5Oq8iM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
2 changes: 1 addition & 1 deletion release-ci

0 comments on commit cdd7c08

Please sign in to comment.